refactor: fire topic tools load event once instead of checking for empty container

This allows for themes to put things inside the container (e.g. skeleton placeholders)
This commit is contained in:
Julian Lam
2022-12-02 17:04:06 -05:00
parent 60853bc20f
commit db1d04931d

View File

@@ -187,23 +187,31 @@ define('forum/topic/threadTools', [
};
function renderMenu(container) {
container.on('show.bs.dropdown', '.thread-tools', function () {
const $this = $(this);
const dropdownMenu = $this.find('.dropdown-menu');
if (dropdownMenu.html()) {
return;
}
container = container.get(0);
if (!container) {
return;
}
socket.emit('topics.loadTopicTools', { tid: ajaxify.data.tid, cid: ajaxify.data.cid }, function (err, data) {
if (err) {
return alerts.error(err);
container.querySelectorAll('.thread-tools').forEach((toolsEl) => {
toolsEl.addEventListener('show.bs.dropdown', (e) => {
const dropdownMenu = e.target.nextElementSibling;
if (!dropdownMenu) {
return;
}
app.parseAndTranslate('partials/topic/topic-menu-list', data, function (html) {
dropdownMenu.html(html);
hooks.fire('action:topic.tools.load', {
element: dropdownMenu,
socket.emit('topics.loadTopicTools', { tid: ajaxify.data.tid, cid: ajaxify.data.cid }, function (err, data) {
if (err) {
return alerts.error(err);
}
app.parseAndTranslate('partials/topic/topic-menu-list', data, function (html) {
$(dropdownMenu).html(html);
hooks.fire('action:topic.tools.load', {
element: $(dropdownMenu),
});
});
});
}, {
once: true,
});
});
}