DEV: removes jQuery usage from extend-for-poll (#15289)
This commit is contained in:
parent
ce7c821aa9
commit
27fda37a8f
|
@ -68,9 +68,9 @@ function initializePolls(api) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
function attachPolls($elem, helper) {
|
function attachPolls(elem, helper) {
|
||||||
const $polls = $(".poll", $elem);
|
const pollNodes = elem.querySelectorAll(".poll");
|
||||||
if (!$polls.length || !helper) {
|
if (!pollNodes.length || !helper) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,26 +83,23 @@ function initializePolls(api) {
|
||||||
|
|
||||||
_interval = _interval || setInterval(rerender, 30000);
|
_interval = _interval || setInterval(rerender, 30000);
|
||||||
|
|
||||||
$polls.each((idx, pollElem) => {
|
pollNodes.forEach((pollNode) => {
|
||||||
const $poll = $(pollElem);
|
const pollName = pollNode.dataset.pollName;
|
||||||
const pollName = $poll.data("poll-name");
|
|
||||||
let poll = polls[pollName];
|
let poll = polls[pollName];
|
||||||
let pollPost = post;
|
let pollPost = post;
|
||||||
let vote = votes[pollName] || [];
|
let vote = votes[pollName] || [];
|
||||||
|
|
||||||
const quotedId = $poll.parent(".expanded-quote").data("post-id");
|
const quotedId = pollNode.closest(".expanded-quote")?.dataset.postId;
|
||||||
if (quotedId && post.quoted[quotedId]) {
|
if (quotedId && post.quoted[quotedId]) {
|
||||||
pollPost = post.quoted[quotedId];
|
pollPost = post.quoted[quotedId];
|
||||||
pollPost = EmberObject.create(pollPost);
|
pollPost = EmberObject.create(pollPost);
|
||||||
poll = EmberObject.create(
|
poll = EmberObject.create(pollPost.polls.findBy("name", pollName));
|
||||||
pollPost.polls.find((p) => p.name === pollName)
|
|
||||||
);
|
|
||||||
vote = pollPost.polls_votes || {};
|
vote = pollPost.polls_votes || {};
|
||||||
vote = vote[pollName] || [];
|
vote = vote[pollName] || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (poll) {
|
if (poll) {
|
||||||
const titleElement = pollElem.querySelector(".poll-title");
|
const titleElement = pollNode.querySelector(".poll-title");
|
||||||
|
|
||||||
const attrs = {
|
const attrs = {
|
||||||
id: `${pollName}-${pollPost.id}`,
|
id: `${pollName}-${pollPost.id}`,
|
||||||
|
@ -110,7 +107,7 @@ function initializePolls(api) {
|
||||||
poll,
|
poll,
|
||||||
vote,
|
vote,
|
||||||
hasSavedVote: vote.length > 0,
|
hasSavedVote: vote.length > 0,
|
||||||
titleHTML: titleElement && titleElement.outerHTML,
|
titleHTML: titleElement?.outerHTML,
|
||||||
groupableUserFields: (
|
groupableUserFields: (
|
||||||
api.container.lookup("site-settings:main")
|
api.container.lookup("site-settings:main")
|
||||||
.poll_groupable_user_fields || ""
|
.poll_groupable_user_fields || ""
|
||||||
|
@ -119,14 +116,17 @@ function initializePolls(api) {
|
||||||
.filter(Boolean),
|
.filter(Boolean),
|
||||||
};
|
};
|
||||||
const glue = new WidgetGlue("discourse-poll", register, attrs);
|
const glue = new WidgetGlue("discourse-poll", register, attrs);
|
||||||
glue.appendTo(pollElem);
|
glue.appendTo(pollNode);
|
||||||
_glued.push(glue);
|
_glued.push(glue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
api.includePostAttributes("polls", "polls_votes");
|
api.includePostAttributes("polls", "polls_votes");
|
||||||
api.decorateCooked(attachPolls, { onlyStream: true, id: "discourse-poll" });
|
api.decorateCookedElement(attachPolls, {
|
||||||
|
onlyStream: true,
|
||||||
|
id: "discourse-poll",
|
||||||
|
});
|
||||||
api.cleanupStream(cleanUpPolls);
|
api.cleanupStream(cleanUpPolls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue