Skip to content

Node.js based forum software built for the modern web

closes #6957

Barış Soner Uşaklıac549f8bc7e7
diff --git a/public/src/client/topic/delete-posts.js b/public/src/client/topic/delete-posts.js
index 803d957d18..deee764ba6 100644
--- a/public/src/client/topic/delete-posts.js
+++ b/public/src/client/topic/delete-posts.js
@@ -6,15 +6,19 @@ define('forum/topic/delete-posts', ['components', 'postSelect'], function (compo
var modal;
var deleteBtn;
var purgeBtn;
+ var tid;
DeletePosts.init = function () {
+ tid = ajaxify.data.tid;
$('.topic').on('click', '[component="topic/delete/posts"]', onDeletePostsClicked);
- $(window).on('action:ajaxify.start', onAjaxifyStart);
+ $(window).off('action:ajaxify.end', onAjaxifyEnd).on('action:ajaxify.end', onAjaxifyEnd);
};
- function onAjaxifyStart() {
- closeModal();
- $(window).off('action:ajaxify.start', onAjaxifyStart);
+ function onAjaxifyEnd() {
+ if (ajaxify.data.template.name !== 'topic' || ajaxify.data.tid !== tid) {
+ closeModal();
+ $(window).off('action:ajaxify.end', onAjaxifyEnd);
+ }
}
function onDeletePostsClicked() {
@@ -84,8 +88,8 @@ define('forum/topic/delete-posts', ['components', 'postSelect'], function (compo
if (modal) {
modal.remove();
modal = null;
+ postSelect.disable();
}
- postSelect.disable();
}
return DeletePosts;
diff --git a/public/src/client/topic/fork.js b/public/src/client/topic/fork.js
index 134a41a1ac..12f873bc1f 100644
--- a/public/src/client/topic/fork.js
+++ b/public/src/client/topic/fork.js
@@ -5,15 +5,18 @@ define('forum/topic/fork', ['components', 'postSelect'], function (components, p
var Fork = {};
var forkModal;
var forkCommit;
-
+ var fromTid;
Fork.init = function () {
+ fromTid = ajaxify.data.tid;
$('.topic').on('click', '[component="topic/fork"]', onForkThreadClicked);
- $(window).on('action:ajaxify.start', onAjaxifyStart);
+ $(window).off('action:ajaxify.end', onAjaxifyEnd).on('action:ajaxify.end', onAjaxifyEnd);
};
- function onAjaxifyStart() {
- closeForkModal();
- $(window).off('action:ajaxify.start', onAjaxifyStart);
+ function onAjaxifyEnd() {
+ if (ajaxify.data.template.name !== 'topic' || ajaxify.data.tid !== fromTid) {
+ closeForkModal();
+ $(window).off('action:ajaxify.end', onAjaxifyEnd);
+ }
}
function onForkThreadClicked() {
@@ -46,7 +49,7 @@ define('forum/topic/fork', ['components', 'postSelect'], function (components, p
socket.emit('topics.createTopicFromPosts', {
title: forkModal.find('#fork-title').val(),
pids: postSelect.pids,
- fromTid: ajaxify.data.tid,
+ fromTid: fromTid,
}, function (err, newTopic) {
function fadeOutAndRemove(pid) {
components.get('post', 'pid', pid).fadeOut(500, function () {
@@ -96,9 +99,8 @@ define('forum/topic/fork', ['components', 'postSelect'], function (components, p
if (forkModal) {
forkModal.remove();
forkModal = null;
+ postSelect.disable();
}
-
- postSelect.disable();
}
return Fork;
diff --git a/public/src/client/topic/move-post.js b/public/src/client/topic/move-post.js
index c14361aa67..b3eb2a1436 100644
--- a/public/src/client/topic/move-post.js
+++ b/public/src/client/topic/move-post.js
@@ -9,14 +9,8 @@ define('forum/topic/move-post', ['components', 'postSelect'], function (componen
MovePost.init = function () {
$('.topic').on('click', '[component="topic/move-posts"]', onMovePostsClicked);
- $(window).on('action:ajaxify.start', onAjaxifyStart);
};
- function onAjaxifyStart() {
- closeMoveModal();
- $(window).off('action:ajaxify.start', onAjaxifyStart);
- }
-
function onMovePostsClicked() {
MovePost.openMovePostModal();
}
@@ -38,6 +32,9 @@ define('forum/topic/move-post', ['components', 'postSelect'], function (componen
}
MovePost.openMovePostModal = function (postEl) {
+ if (moveModal) {
+ return;
+ }
app.parseAndTranslate('partials/move_post_modal', {}, function (html) {
moveModal = html;
@@ -85,9 +82,8 @@ define('forum/topic/move-post', ['components', 'postSelect'], function (componen
if (moveModal) {
moveModal.remove();
moveModal = null;
+ postSelect.disable();
}
-
- postSelect.disable();
}
diff --git a/public/src/modules/postSelect.js b/public/src/modules/postSelect.js
index cab894c5bb..8b70689f7c 100644
--- a/public/src/modules/postSelect.js
+++ b/public/src/modules/postSelect.js
@@ -3,26 +3,31 @@
define('postSelect', ['components'], function (components) {
var PostSelect = {};
+ var onSelect;
PostSelect.pids = [];
- PostSelect.init = function (onSelect) {
+ PostSelect.init = function (_onSelect) {
PostSelect.pids.length = 0;
- components.get('topic').on('click', '[data-pid]', function () {
- PostSelect.togglePostSelection($(this), onSelect);
- });
+ onSelect = _onSelect;
+ $('#content').on('click', '[component="topic"] [component="post"]', onPostClicked);
disableClicksOnPosts();
};
+ function onPostClicked() {
+ PostSelect.togglePostSelection($(this));
+ }
+
PostSelect.disable = function () {
PostSelect.pids.forEach(function (pid) {
components.get('post', 'pid', pid).toggleClass('bg-success', false);
});
- components.get('topic').off('click', '[data-pid]');
+
+ $('#content').off('click', '[component="topic"] [component="post"]', onPostClicked);
enableClicksOnPosts();
};
- PostSelect.togglePostSelection = function (post, callback) {
+ PostSelect.togglePostSelection = function (post) {
var newPid = post.attr('data-pid');
if (parseInt(post.attr('data-index'), 10) === 0) {
@@ -42,7 +47,9 @@ define('postSelect', ['components'], function (components) {
if (PostSelect.pids.length) {
PostSelect.pids.sort(function (a, b) { return a - b; });
}
- callback();
+ if (typeof onSelect === 'function') {
+ onSelect();
+ }
}
};
@@ -52,11 +59,11 @@ define('postSelect', ['components'], function (components) {
}
function disableClicksOnPosts() {
- components.get('post').on('click', 'button,a', disableClicks);
+ $('#content').on('click', '[component="post"] button, [component="post"] a', disableClicks);
}
function enableClicksOnPosts() {
- components.get('post').off('click', 'button,a', disableClicks);
+ $('#content').off('click', '[component="post"] button, [component="post"] a', disableClicks);
}
return PostSelect;