|
|
|
@ -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;
|
|
|
|
|