From c285eb7fcdb03cacbbdcfc3a89a2b97dca9107e8 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Thu, 16 Feb 2017 15:01:06 +0300 Subject: [PATCH] closes #5450 --- package.json | 2 +- public/src/client/topic/postTools.js | 47 +++++++++++++++++----------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index f01ae0f487..bc9b07489b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/public/src/client/topic/postTools.js b/public/src/client/topic/postTools.js index e3b2e49c14..f9b2090f3a 100644 --- a/public/src/client/topic/postTools.js +++ b/public/src/client/topic/postTools.js @@ -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) {