2014-10-08 15:36:47 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
2016-12-23 16:35:48 +03:00
|
|
|
define('forum/topic/postTools', [
|
|
|
|
|
'share',
|
|
|
|
|
'navigator',
|
|
|
|
|
'components',
|
|
|
|
|
'translator',
|
|
|
|
|
'forum/topic/votes',
|
2020-10-06 14:12:02 -04:00
|
|
|
'api',
|
|
|
|
|
], function (share, navigator, components, translator, votes, api) {
|
2016-02-18 18:32:08 +02:00
|
|
|
var PostTools = {};
|
2014-10-08 15:36:47 -04:00
|
|
|
|
2016-06-30 11:38:33 +03:00
|
|
|
var staleReplyAnyway = false;
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
PostTools.init = function (tid) {
|
2016-06-30 11:38:33 +03:00
|
|
|
staleReplyAnyway = false;
|
|
|
|
|
|
2015-10-24 20:50:43 -04:00
|
|
|
renderMenu();
|
|
|
|
|
|
2015-04-02 22:34:23 -04:00
|
|
|
addPostHandlers(tid);
|
2014-10-08 15:36:47 -04:00
|
|
|
|
2016-12-06 15:49:34 -05:00
|
|
|
share.addShareHandlers(ajaxify.data.titleRaw);
|
2014-10-08 15:36:47 -04:00
|
|
|
|
2016-12-23 16:35:48 +03:00
|
|
|
votes.addVoteHandler();
|
2015-10-20 18:08:59 -04:00
|
|
|
|
|
|
|
|
PostTools.updatePostCount(ajaxify.data.postcount);
|
2014-10-08 15:36:47 -04:00
|
|
|
};
|
|
|
|
|
|
2015-10-24 20:50:43 -04:00
|
|
|
function renderMenu() {
|
2016-10-13 11:43:39 +02:00
|
|
|
$('[component="topic"]').on('show.bs.dropdown', '.moderator-tools', function () {
|
2015-10-24 20:50:43 -04:00
|
|
|
var $this = $(this);
|
|
|
|
|
var dropdownMenu = $this.find('.dropdown-menu');
|
|
|
|
|
if (dropdownMenu.html()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var postEl = $this.parents('[data-pid]');
|
|
|
|
|
var pid = postEl.attr('data-pid');
|
|
|
|
|
var index = parseInt(postEl.attr('data-index'), 10);
|
2016-03-01 18:16:51 -05:00
|
|
|
|
2017-02-18 12:30:49 -07:00
|
|
|
socket.emit('posts.loadPostTools', { pid: pid, cid: ajaxify.data.cid }, function (err, data) {
|
2015-10-24 20:50:43 -04:00
|
|
|
if (err) {
|
2016-08-10 22:53:30 +03:00
|
|
|
return app.alertError(err.message);
|
2015-10-24 20:50:43 -04:00
|
|
|
}
|
|
|
|
|
data.posts.display_move_tools = data.posts.display_move_tools && index !== 0;
|
2016-03-08 14:38:44 +02:00
|
|
|
|
2018-02-15 14:52:49 -05:00
|
|
|
app.parseAndTranslate('partials/topic/post-menu-list', data, function (html) {
|
|
|
|
|
dropdownMenu.html(html);
|
|
|
|
|
require(['clipboard'], function (clipboard) {
|
|
|
|
|
new clipboard('[data-clipboard-text]');
|
2015-10-24 20:50:43 -04:00
|
|
|
});
|
2018-02-15 14:52:49 -05:00
|
|
|
$(window).trigger('action:post.tools.load');
|
2015-10-24 20:50:43 -04:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
PostTools.toggle = function (pid, isDeleted) {
|
2015-03-17 13:38:18 -04:00
|
|
|
var postEl = components.get('post', 'pid', pid);
|
2014-10-08 15:36:47 -04:00
|
|
|
|
2016-10-08 19:09:48 +03:00
|
|
|
postEl.find('[component="post/quote"], [component="post/bookmark"], [component="post/reply"], [component="post/flag"], [component="user/chat"]')
|
2015-03-17 16:15:12 -04:00
|
|
|
.toggleClass('hidden', isDeleted);
|
|
|
|
|
|
2018-12-19 12:09:36 -05:00
|
|
|
postEl.find('[component="post/delete"]').toggleClass('hidden', isDeleted).parent().attr('hidden', isDeleted ? '' : null);
|
|
|
|
|
postEl.find('[component="post/restore"]').toggleClass('hidden', !isDeleted).parent().attr('hidden', !isDeleted ? '' : null);
|
|
|
|
|
postEl.find('[component="post/purge"]').toggleClass('hidden', !isDeleted).parent().attr('hidden', !isDeleted ? '' : null);
|
2016-07-06 15:15:51 +03:00
|
|
|
|
2018-07-17 21:14:53 -04:00
|
|
|
PostTools.removeMenu(postEl);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PostTools.removeMenu = function (postEl) {
|
2016-08-29 15:51:46 +03:00
|
|
|
postEl.find('[component="post/tools"] .dropdown-menu').html('');
|
2014-10-08 15:36:47 -04:00
|
|
|
};
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
PostTools.updatePostCount = function (postCount) {
|
2015-10-20 18:08:59 -04:00
|
|
|
var postCountEl = components.get('topic/post-count');
|
|
|
|
|
postCountEl.html(postCount).attr('title', postCount);
|
|
|
|
|
utils.makeNumbersHumanReadable(postCountEl);
|
|
|
|
|
navigator.setCount(postCount);
|
2014-10-08 15:36:47 -04:00
|
|
|
};
|
|
|
|
|
|
2015-04-02 22:34:23 -04:00
|
|
|
function addPostHandlers(tid) {
|
2015-03-17 14:09:08 -04:00
|
|
|
var postContainer = components.get('topic');
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
postContainer.on('click', '[component="post/quote"]', function () {
|
2016-02-18 18:32:08 +02:00
|
|
|
onQuoteClicked($(this), tid);
|
2014-10-08 15:36:47 -04:00
|
|
|
});
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
postContainer.on('click', '[component="post/reply"]', function () {
|
2016-02-18 18:32:08 +02:00
|
|
|
onReplyClicked($(this), tid);
|
2015-03-20 16:13:34 -04:00
|
|
|
});
|
|
|
|
|
|
2017-07-20 08:51:04 -04:00
|
|
|
$('.topic').on('click', '[component="topic/reply"]', function (e) {
|
|
|
|
|
e.preventDefault();
|
2016-02-18 18:32:08 +02:00
|
|
|
onReplyClicked($(this), tid);
|
2014-10-08 15:36:47 -04:00
|
|
|
});
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
$('.topic').on('click', '[component="topic/reply-as-topic"]', function () {
|
|
|
|
|
translator.translate('[[topic:link_back, ' + ajaxify.data.titleRaw + ', ' + config.relative_path + '/topic/' + ajaxify.data.slug + ']]', function (body) {
|
2016-02-23 12:55:46 -05:00
|
|
|
$(window).trigger('action:composer.topic.new', {
|
|
|
|
|
cid: ajaxify.data.cid,
|
2017-02-17 19:31:21 -07:00
|
|
|
body: body,
|
2016-02-23 12:55:46 -05:00
|
|
|
});
|
2015-12-21 12:51:49 +02:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
postContainer.on('click', '[component="post/bookmark"]', function () {
|
2016-12-23 16:35:48 +03:00
|
|
|
return bookmarkPost($(this), getData($(this), 'data-pid'));
|
2014-10-08 15:36:47 -04:00
|
|
|
});
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
postContainer.on('click', '[component="post/upvote"]', function () {
|
2020-10-06 14:47:03 -04:00
|
|
|
return votes.toggleVote($(this), '.upvoted', 1);
|
2014-10-08 15:36:47 -04:00
|
|
|
});
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
postContainer.on('click', '[component="post/downvote"]', function () {
|
2020-10-06 14:47:03 -04:00
|
|
|
return votes.toggleVote($(this), '.downvoted', -1);
|
2014-10-08 15:36:47 -04:00
|
|
|
});
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
postContainer.on('click', '[component="post/vote-count"]', function () {
|
2016-12-23 16:35:48 +03:00
|
|
|
votes.showVotes(getData($(this), 'data-pid'));
|
2014-11-15 12:37:22 -05:00
|
|
|
});
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
postContainer.on('click', '[component="post/flag"]', function () {
|
2015-10-13 16:36:43 -04:00
|
|
|
var pid = getData($(this), 'data-pid');
|
2016-12-07 12:07:22 -05:00
|
|
|
require(['flags'], function (flags) {
|
|
|
|
|
flags.showFlagModal({
|
|
|
|
|
type: 'post',
|
2017-02-24 12:47:46 -05:00
|
|
|
id: pid,
|
2016-12-07 12:07:22 -05:00
|
|
|
});
|
2015-10-13 16:36:43 -04:00
|
|
|
});
|
2014-10-08 15:36:47 -04:00
|
|
|
});
|
|
|
|
|
|
2020-06-29 19:49:48 -04:00
|
|
|
postContainer.on('click', '[component="post/flagUser"]', function () {
|
|
|
|
|
var uid = getData($(this), 'data-uid');
|
|
|
|
|
require(['flags'], function (flags) {
|
|
|
|
|
flags.showFlagModal({
|
|
|
|
|
type: 'user',
|
|
|
|
|
id: uid,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
postContainer.on('click', '[component="post/edit"]', function () {
|
2015-04-01 23:28:21 -04:00
|
|
|
var btn = $(this);
|
2016-05-25 15:48:53 +03:00
|
|
|
|
2016-05-21 19:26:06 +03:00
|
|
|
var timestamp = parseInt(getData(btn, 'data-timestamp'), 10);
|
|
|
|
|
var postEditDuration = parseInt(ajaxify.data.postEditDuration, 10);
|
2016-06-28 12:34:09 +03:00
|
|
|
|
|
|
|
|
if (checkDuration(postEditDuration, timestamp, 'post-edit-duration-expired')) {
|
|
|
|
|
$(window).trigger('action:composer.post.edit', {
|
2017-02-17 19:31:21 -07:00
|
|
|
pid: getData(btn, 'data-pid'),
|
2016-06-28 12:34:09 +03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2018-06-07 12:23:08 -04:00
|
|
|
if (config.enablePostHistory && ajaxify.data.privileges['posts:history']) {
|
2018-04-09 15:59:51 -04:00
|
|
|
postContainer.on('click', '[component="post/view-history"], [component="post/edit-indicator"]', function () {
|
|
|
|
|
var btn = $(this);
|
2018-11-17 20:50:07 -05:00
|
|
|
require(['forum/topic/diffs'], function (diffs) {
|
|
|
|
|
diffs.open(getData(btn, 'data-pid'));
|
|
|
|
|
});
|
2018-04-09 15:59:51 -04:00
|
|
|
});
|
|
|
|
|
}
|
2018-02-16 21:22:26 -05:00
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
postContainer.on('click', '[component="post/delete"]', function () {
|
2016-06-28 12:34:09 +03:00
|
|
|
var btn = $(this);
|
|
|
|
|
var timestamp = parseInt(getData(btn, 'data-timestamp'), 10);
|
|
|
|
|
var postDeleteDuration = parseInt(ajaxify.data.postDeleteDuration, 10);
|
|
|
|
|
if (checkDuration(postDeleteDuration, timestamp, 'post-delete-duration-expired')) {
|
2020-09-02 21:51:35 -04:00
|
|
|
togglePostDelete($(this));
|
2016-06-28 12:34:09 +03:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function checkDuration(duration, postTimestamp, languageKey) {
|
|
|
|
|
if (!ajaxify.data.privileges.isAdminOrMod && duration && Date.now() - postTimestamp > duration * 1000) {
|
|
|
|
|
var numDays = Math.floor(duration / 86400);
|
|
|
|
|
var numHours = Math.floor((duration % 86400) / 3600);
|
|
|
|
|
var numMinutes = Math.floor(((duration % 86400) % 3600) / 60);
|
|
|
|
|
var numSeconds = ((duration % 86400) % 3600) % 60;
|
|
|
|
|
var msg = '[[error:' + languageKey + ', ' + duration + ']]';
|
2016-05-21 19:26:06 +03:00
|
|
|
if (numDays) {
|
|
|
|
|
if (numHours) {
|
2016-06-28 12:34:09 +03:00
|
|
|
msg = '[[error:' + languageKey + '-days-hours, ' + numDays + ', ' + numHours + ']]';
|
2016-05-21 19:26:06 +03:00
|
|
|
} else {
|
2016-06-28 12:34:09 +03:00
|
|
|
msg = '[[error:' + languageKey + '-days, ' + numDays + ']]';
|
2016-05-25 15:48:53 +03:00
|
|
|
}
|
2016-05-21 19:26:06 +03:00
|
|
|
} else if (numHours) {
|
|
|
|
|
if (numMinutes) {
|
2016-06-28 12:34:09 +03:00
|
|
|
msg = '[[error:' + languageKey + '-hours-minutes, ' + numHours + ', ' + numMinutes + ']]';
|
2016-05-21 19:26:06 +03:00
|
|
|
} else {
|
2016-06-28 12:34:09 +03:00
|
|
|
msg = '[[error:' + languageKey + '-hours, ' + numHours + ']]';
|
2016-05-25 15:48:53 +03:00
|
|
|
}
|
2016-05-21 19:26:06 +03:00
|
|
|
} else if (numMinutes) {
|
|
|
|
|
if (numSeconds) {
|
2016-06-28 12:34:09 +03:00
|
|
|
msg = '[[error:' + languageKey + '-minutes-seconds, ' + numMinutes + ', ' + numSeconds + ']]';
|
2016-05-21 19:26:06 +03:00
|
|
|
} else {
|
2016-06-28 12:34:09 +03:00
|
|
|
msg = '[[error:' + languageKey + '-minutes, ' + numMinutes + ']]';
|
2016-05-25 15:48:53 +03:00
|
|
|
}
|
2016-05-21 19:26:06 +03:00
|
|
|
}
|
2016-06-28 12:34:09 +03:00
|
|
|
app.alertError(msg);
|
|
|
|
|
return false;
|
2016-05-21 19:26:06 +03:00
|
|
|
}
|
2016-06-28 12:34:09 +03:00
|
|
|
return true;
|
|
|
|
|
}
|
2015-04-02 22:54:09 -04:00
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
postContainer.on('click', '[component="post/restore"]', function () {
|
2020-09-02 21:51:35 -04:00
|
|
|
togglePostDelete($(this));
|
2014-10-08 15:36:47 -04:00
|
|
|
});
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
postContainer.on('click', '[component="post/purge"]', function () {
|
2020-09-02 21:51:35 -04:00
|
|
|
purgePost($(this));
|
2014-10-08 15:36:47 -04:00
|
|
|
});
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
postContainer.on('click', '[component="post/move"]', function () {
|
2018-11-17 20:50:07 -05:00
|
|
|
var btn = $(this);
|
|
|
|
|
require(['forum/topic/move-post'], function (movePost) {
|
|
|
|
|
movePost.init(btn.parents('[data-pid]'));
|
|
|
|
|
});
|
2014-10-08 15:36:47 -04:00
|
|
|
});
|
|
|
|
|
|
2019-07-12 14:06:09 -04:00
|
|
|
postContainer.on('click', '[component="post/change-owner"]', function () {
|
|
|
|
|
var btn = $(this);
|
|
|
|
|
require(['forum/topic/change-owner'], function (changeOwner) {
|
|
|
|
|
changeOwner.init(btn.parents('[data-pid]'));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2018-02-15 14:52:49 -05:00
|
|
|
postContainer.on('click', '[component="post/ban-ip"]', function () {
|
|
|
|
|
var ip = $(this).attr('data-ip');
|
|
|
|
|
socket.emit('blacklist.addRule', ip, function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return app.alertError(err.message);
|
|
|
|
|
}
|
|
|
|
|
app.alertSuccess('[[admin/manage/blacklist:ban-ip]]');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
postContainer.on('click', '[component="post/chat"]', function () {
|
2014-10-08 15:36:47 -04:00
|
|
|
openChat($(this));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-18 18:32:08 +02:00
|
|
|
function onReplyClicked(button, tid) {
|
2017-02-16 15:01:06 +03:00
|
|
|
var selectedNode = getSelectedNode();
|
2014-10-08 15:36:47 -04:00
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
showStaleWarning(function () {
|
2017-06-21 12:57:33 -04:00
|
|
|
var username = getUserSlug(button);
|
2016-06-21 13:37:17 +03:00
|
|
|
if (getData(button, 'data-uid') === '0' || !getData(button, 'data-userslug')) {
|
|
|
|
|
username = '';
|
|
|
|
|
}
|
2015-10-05 15:37:16 -04:00
|
|
|
|
2016-06-21 13:37:17 +03:00
|
|
|
var toPid = button.is('[component="post/reply"]') ? getData(button, 'data-pid') : null;
|
|
|
|
|
|
2017-02-16 15:01:06 +03:00
|
|
|
if (selectedNode.text && (!toPid || !selectedNode.pid || toPid === selectedNode.pid)) {
|
|
|
|
|
username = username || selectedNode.username;
|
2016-06-21 13:37:17 +03:00
|
|
|
$(window).trigger('action:composer.addQuote', {
|
|
|
|
|
tid: tid,
|
|
|
|
|
pid: toPid,
|
|
|
|
|
topicName: ajaxify.data.titleRaw,
|
|
|
|
|
username: username,
|
2017-02-16 15:01:06 +03:00
|
|
|
text: selectedNode.text,
|
2017-02-17 19:31:21 -07:00
|
|
|
selectedPid: selectedNode.pid,
|
2016-06-21 13:37:17 +03:00
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
$(window).trigger('action:composer.post.new', {
|
|
|
|
|
tid: tid,
|
|
|
|
|
pid: toPid,
|
|
|
|
|
topicName: ajaxify.data.titleRaw,
|
2019-02-06 18:36:58 -05:00
|
|
|
text: username ? username + ' ' : ($('[component="topic/quickreply/text"]').val() || ''),
|
2016-06-21 13:37:17 +03:00
|
|
|
});
|
2015-10-07 01:38:27 -04:00
|
|
|
}
|
|
|
|
|
});
|
2014-10-08 15:36:47 -04:00
|
|
|
}
|
|
|
|
|
|
2016-02-18 18:32:08 +02:00
|
|
|
function onQuoteClicked(button, tid) {
|
2017-02-16 15:01:06 +03:00
|
|
|
var selectedNode = getSelectedNode();
|
2016-06-30 11:38:33 +03:00
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
showStaleWarning(function () {
|
2017-06-21 12:57:33 -04:00
|
|
|
var username = getUserSlug(button);
|
2017-02-18 18:55:33 -07:00
|
|
|
var toPid = getData(button, 'data-pid');
|
2015-10-06 05:28:05 -04:00
|
|
|
|
2016-06-20 13:06:08 +03:00
|
|
|
function quote(text) {
|
|
|
|
|
$(window).trigger('action:composer.addQuote', {
|
|
|
|
|
tid: tid,
|
2017-02-16 15:01:06 +03:00
|
|
|
pid: toPid,
|
2016-06-20 13:06:08 +03:00
|
|
|
username: username,
|
|
|
|
|
topicName: ajaxify.data.titleRaw,
|
2017-02-17 19:31:21 -07:00
|
|
|
text: text,
|
2016-06-20 13:06:08 +03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-16 15:01:06 +03:00
|
|
|
if (selectedNode.text && toPid && toPid === selectedNode.pid) {
|
|
|
|
|
return quote(selectedNode.text);
|
2016-06-21 13:37:17 +03:00
|
|
|
}
|
2017-02-16 15:01:06 +03:00
|
|
|
socket.emit('posts.getRawPost', toPid, function (err, post) {
|
2016-06-21 13:37:17 +03:00
|
|
|
if (err) {
|
|
|
|
|
return app.alertError(err.message);
|
2016-06-20 13:06:08 +03:00
|
|
|
}
|
2015-07-03 16:41:21 -04:00
|
|
|
|
2016-06-21 13:37:17 +03:00
|
|
|
quote(post);
|
|
|
|
|
});
|
2014-10-08 15:36:47 -04:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-16 15:01:06 +03:00
|
|
|
function getSelectedNode() {
|
|
|
|
|
var selectedText = '';
|
|
|
|
|
var selectedPid;
|
|
|
|
|
var username = '';
|
2016-06-20 13:06:08 +03:00
|
|
|
var selection = window.getSelection ? window.getSelection() : document.selection.createRange();
|
2017-02-16 15:01:06 +03:00
|
|
|
var postContents = $('[component="post"] [component="post/content"]');
|
|
|
|
|
var content;
|
2017-02-16 15:11:31 +03:00
|
|
|
postContents.each(function (index, el) {
|
2017-02-16 15:01:06 +03:00
|
|
|
if (selection && selection.containsNode && el && selection.containsNode(el, true)) {
|
|
|
|
|
content = el;
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-06-20 13:06:08 +03:00
|
|
|
|
2017-02-16 15:01:06 +03:00
|
|
|
if (content) {
|
2016-06-20 13:06:08 +03:00
|
|
|
var bounds = document.createRange();
|
|
|
|
|
bounds.selectNodeContents(content);
|
|
|
|
|
var range = selection.getRangeAt(0).cloneRange();
|
|
|
|
|
if (range.compareBoundaryPoints(Range.START_TO_START, bounds) < 0) {
|
|
|
|
|
range.setStart(bounds.startContainer, bounds.startOffset);
|
|
|
|
|
}
|
|
|
|
|
if (range.compareBoundaryPoints(Range.END_TO_END, bounds) > 0) {
|
|
|
|
|
range.setEnd(bounds.endContainer, bounds.endOffset);
|
|
|
|
|
}
|
|
|
|
|
bounds.detach();
|
2017-02-16 15:01:06 +03:00
|
|
|
selectedText = range.toString();
|
|
|
|
|
var postEl = $(content).parents('[component="post"]');
|
|
|
|
|
selectedPid = postEl.attr('data-pid');
|
2017-06-21 12:57:33 -04:00
|
|
|
username = getUserSlug($(content));
|
2016-06-20 13:06:08 +03:00
|
|
|
range.detach();
|
|
|
|
|
}
|
2017-02-18 12:30:49 -07:00
|
|
|
return { text: selectedText, pid: selectedPid, username: username };
|
2016-06-20 13:06:08 +03:00
|
|
|
}
|
|
|
|
|
|
2016-10-08 19:09:48 +03:00
|
|
|
function bookmarkPost(button, pid) {
|
|
|
|
|
var method = button.attr('data-bookmarked') === 'false' ? 'posts.bookmark' : 'posts.unbookmark';
|
2014-10-08 15:36:47 -04:00
|
|
|
|
|
|
|
|
socket.emit(method, {
|
|
|
|
|
pid: pid,
|
2017-05-01 21:38:03 -04:00
|
|
|
room_id: 'topic_' + ajaxify.data.tid,
|
2016-10-13 11:43:39 +02:00
|
|
|
}, function (err) {
|
2014-10-08 15:36:47 -04:00
|
|
|
if (err) {
|
|
|
|
|
app.alertError(err.message);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getData(button, data) {
|
2015-03-17 13:59:25 -04:00
|
|
|
return button.parents('[data-pid]').attr(data);
|
2014-10-08 15:36:47 -04:00
|
|
|
}
|
|
|
|
|
|
2017-06-21 12:57:33 -04:00
|
|
|
function getUserSlug(button) {
|
|
|
|
|
var slug = '';
|
2016-03-08 14:38:44 +02:00
|
|
|
var post = button.parents('[data-pid]');
|
|
|
|
|
|
2015-09-26 18:29:27 -04:00
|
|
|
if (button.attr('component') === 'topic/reply') {
|
2017-06-21 12:57:33 -04:00
|
|
|
return slug;
|
2015-09-26 18:29:27 -04:00
|
|
|
}
|
2016-03-08 14:38:44 +02:00
|
|
|
|
2014-10-08 15:36:47 -04:00
|
|
|
if (post.length) {
|
2018-07-16 20:35:36 -04:00
|
|
|
slug = utils.slugify(post.attr('data-username'), true);
|
2014-10-08 15:36:47 -04:00
|
|
|
}
|
|
|
|
|
if (post.length && post.attr('data-uid') !== '0') {
|
2017-06-21 12:57:33 -04:00
|
|
|
slug = '@' + slug;
|
2014-10-08 15:36:47 -04:00
|
|
|
}
|
|
|
|
|
|
2017-06-21 12:57:33 -04:00
|
|
|
return slug;
|
2014-10-08 15:36:47 -04:00
|
|
|
}
|
|
|
|
|
|
2020-09-02 21:51:35 -04:00
|
|
|
function togglePostDelete(button) {
|
2016-06-28 12:34:09 +03:00
|
|
|
var pid = getData(button, 'data-pid');
|
|
|
|
|
var postEl = components.get('post', 'pid', pid);
|
|
|
|
|
var action = !postEl.hasClass('deleted') ? 'delete' : 'restore';
|
2014-10-08 15:36:47 -04:00
|
|
|
|
2020-09-02 21:51:35 -04:00
|
|
|
postAction(action, pid);
|
2014-10-08 15:36:47 -04:00
|
|
|
}
|
|
|
|
|
|
2020-09-02 21:51:35 -04:00
|
|
|
function purgePost(button) {
|
|
|
|
|
postAction('purge', getData(button, 'data-pid'));
|
2014-10-08 15:36:47 -04:00
|
|
|
}
|
|
|
|
|
|
2020-09-02 21:51:35 -04:00
|
|
|
function postAction(action, pid) {
|
2016-10-13 11:43:39 +02:00
|
|
|
translator.translate('[[topic:post_' + action + '_confirm]]', function (msg) {
|
|
|
|
|
bootbox.confirm(msg, function (confirm) {
|
2014-10-08 15:36:47 -04:00
|
|
|
if (!confirm) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-06 14:12:02 -04:00
|
|
|
const route = action === 'purge' ? '' : '/state';
|
|
|
|
|
const method = action === 'restore' ? 'put' : 'del';
|
|
|
|
|
api[method](`/posts/${pid}${route}`, undefined, undefined, err => app.alertError(err.status.message));
|
2014-10-08 15:36:47 -04:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function openChat(button) {
|
2015-04-02 17:11:55 +08:00
|
|
|
var post = button.parents('[data-pid]');
|
2014-10-08 15:36:47 -04:00
|
|
|
|
2015-12-16 13:35:24 +02:00
|
|
|
app.newChat(post.attr('data-uid'));
|
2014-10-08 15:36:47 -04:00
|
|
|
button.parents('.btn-group').find('.dropdown-toggle').click();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-07 01:38:27 -04:00
|
|
|
function showStaleWarning(callback) {
|
2017-05-09 14:52:07 -04:00
|
|
|
var staleThreshold = Math.min(Date.now() - (1000 * 60 * 60 * 24 * ajaxify.data.topicStaleDays), 8640000000000000);
|
|
|
|
|
if (staleReplyAnyway || ajaxify.data.lastposttime >= staleThreshold) {
|
2016-06-21 13:37:17 +03:00
|
|
|
return callback();
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
translator.translate('[[topic:stale.warning]]', function (translated) {
|
2016-06-21 13:37:17 +03:00
|
|
|
var warning = bootbox.dialog({
|
2017-02-18 02:38:03 -07:00
|
|
|
title: '[[topic:stale.title]]',
|
|
|
|
|
message: translated,
|
|
|
|
|
buttons: {
|
|
|
|
|
reply: {
|
|
|
|
|
label: '[[topic:stale.reply_anyway]]',
|
|
|
|
|
className: 'btn-link',
|
|
|
|
|
callback: function () {
|
|
|
|
|
staleReplyAnyway = true;
|
|
|
|
|
callback();
|
2016-06-21 13:37:17 +03:00
|
|
|
},
|
2017-02-18 02:38:03 -07:00
|
|
|
},
|
|
|
|
|
create: {
|
|
|
|
|
label: '[[topic:stale.create]]',
|
|
|
|
|
className: 'btn-primary',
|
|
|
|
|
callback: function () {
|
|
|
|
|
translator.translate('[[topic:link_back, ' + ajaxify.data.title + ', ' + config.relative_path + '/topic/' + ajaxify.data.slug + ']]', function (body) {
|
|
|
|
|
$(window).trigger('action:composer.topic.new', {
|
|
|
|
|
cid: ajaxify.data.cid,
|
|
|
|
|
body: body,
|
2016-06-21 13:37:17 +03:00
|
|
|
});
|
2017-02-18 02:38:03 -07:00
|
|
|
});
|
2017-02-17 19:31:21 -07:00
|
|
|
},
|
|
|
|
|
},
|
2017-02-18 02:38:03 -07:00
|
|
|
},
|
|
|
|
|
});
|
2015-10-07 01:38:27 -04:00
|
|
|
|
2016-06-21 13:37:17 +03:00
|
|
|
warning.modal();
|
|
|
|
|
});
|
2015-10-06 05:28:05 -04:00
|
|
|
}
|
|
|
|
|
|
2014-10-08 15:36:47 -04:00
|
|
|
return PostTools;
|
|
|
|
|
});
|