mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-17 21:12:50 +01:00
closes #5450
This commit is contained in:
@@ -52,7 +52,7 @@
|
||||
"morgan": "^1.3.2",
|
||||
"mousetrap": "^1.5.3",
|
||||
"nconf": "~0.8.2",
|
||||
"nodebb-plugin-composer-default": "4.4.0",
|
||||
"nodebb-plugin-composer-default": "4.3.9",
|
||||
"nodebb-plugin-dbsearch": "1.0.5",
|
||||
"nodebb-plugin-emoji-extended": "1.1.1",
|
||||
"nodebb-plugin-emoji-one": "1.1.5",
|
||||
|
||||
@@ -197,7 +197,7 @@ define('forum/topic/postTools', [
|
||||
}
|
||||
|
||||
function onReplyClicked(button, tid) {
|
||||
var selectedText = getSelectedText(button);
|
||||
var selectedNode = getSelectedNode();
|
||||
|
||||
showStaleWarning(function () {
|
||||
var username = getUserName(button);
|
||||
@@ -207,15 +207,15 @@ define('forum/topic/postTools', [
|
||||
|
||||
var toPid = button.is('[component="post/reply"]') ? getData(button, 'data-pid') : null;
|
||||
|
||||
if (selectedText) {
|
||||
if (selectedNode.text && (!toPid || !selectedNode.pid || toPid === selectedNode.pid)) {
|
||||
username = username || selectedNode.username;
|
||||
$(window).trigger('action:composer.addQuote', {
|
||||
tid: tid,
|
||||
slug: ajaxify.data.slug,
|
||||
index: getData(button, 'data-index'),
|
||||
pid: toPid,
|
||||
topicName: ajaxify.data.titleRaw,
|
||||
username: username,
|
||||
text: selectedText
|
||||
text: selectedNode.text,
|
||||
selectedPid: selectedNode.pid
|
||||
});
|
||||
} else {
|
||||
$(window).trigger('action:composer.post.new', {
|
||||
@@ -229,16 +229,14 @@ define('forum/topic/postTools', [
|
||||
}
|
||||
|
||||
function onQuoteClicked(button, tid) {
|
||||
var selectedText = getSelectedText(button);
|
||||
var selectedNode = getSelectedNode();
|
||||
|
||||
showStaleWarning(function () {
|
||||
|
||||
function quote(text) {
|
||||
$(window).trigger('action:composer.addQuote', {
|
||||
tid: tid,
|
||||
slug: ajaxify.data.slug,
|
||||
index: getData(button, 'data-index'),
|
||||
pid: pid,
|
||||
pid: toPid,
|
||||
username: username,
|
||||
topicName: ajaxify.data.titleRaw,
|
||||
text: text
|
||||
@@ -246,12 +244,12 @@ define('forum/topic/postTools', [
|
||||
}
|
||||
|
||||
var username = getUserName(button);
|
||||
var pid = getData(button, 'data-pid');
|
||||
var toPid = getData(button, 'data-pid');
|
||||
|
||||
if (selectedText) {
|
||||
return quote(selectedText);
|
||||
if (selectedNode.text && toPid && toPid === selectedNode.pid) {
|
||||
return quote(selectedNode.text);
|
||||
}
|
||||
socket.emit('posts.getRawPost', pid, function (err, post) {
|
||||
socket.emit('posts.getRawPost', toPid, function (err, post) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
@@ -261,12 +259,20 @@ define('forum/topic/postTools', [
|
||||
});
|
||||
}
|
||||
|
||||
function getSelectedText(button) {
|
||||
var selectionText = '';
|
||||
function getSelectedNode() {
|
||||
var selectedText = '';
|
||||
var selectedPid;
|
||||
var username = '';
|
||||
var selection = window.getSelection ? window.getSelection() : document.selection.createRange();
|
||||
var content = button.parents('[component="post"]').find('[component="post/content"]').get(0);
|
||||
var postContents = $('[component="post"] [component="post/content"]');
|
||||
var content;
|
||||
postContents.each(function(index, el) {
|
||||
if (selection && selection.containsNode && el && selection.containsNode(el, true)) {
|
||||
content = el;
|
||||
}
|
||||
});
|
||||
|
||||
if (selection && selection.containsNode && content && selection.containsNode(content, true)) {
|
||||
if (content) {
|
||||
var bounds = document.createRange();
|
||||
bounds.selectNodeContents(content);
|
||||
var range = selection.getRangeAt(0).cloneRange();
|
||||
@@ -277,10 +283,13 @@ define('forum/topic/postTools', [
|
||||
range.setEnd(bounds.endContainer, bounds.endOffset);
|
||||
}
|
||||
bounds.detach();
|
||||
selectionText = range.toString();
|
||||
selectedText = range.toString();
|
||||
var postEl = $(content).parents('[component="post"]');
|
||||
selectedPid = postEl.attr('data-pid');
|
||||
username = getUserName($(content));
|
||||
range.detach();
|
||||
}
|
||||
return selectionText;
|
||||
return {text: selectedText, pid: selectedPid, username: username};
|
||||
}
|
||||
|
||||
function bookmarkPost(button, pid) {
|
||||
|
||||
Reference in New Issue
Block a user