diff --git a/extensions/mentions/js/forum/dist/extension.js b/extensions/mentions/js/forum/dist/extension.js index 784031bb1..db9297818 100644 --- a/extensions/mentions/js/forum/dist/extension.js +++ b/extensions/mentions/js/forum/dist/extension.js @@ -660,7 +660,7 @@ System.register('flarum/mentions/addPostQuoteButton', ['flarum/extend', 'flarum/ // button into it. var $container = $('
'); - this.$().after($container).on('mouseup', function (e) { + var handler = function handler(e) { setTimeout(function () { var content = selectedText($postBody); if (content) { @@ -678,7 +678,10 @@ System.register('flarum/mentions/addPostQuoteButton', ['flarum/extend', 'flarum/ } } }, 1); - }); + }; + + this.$().after($container).on('mouseup', handler); + document.addEventListener('selectionchange', handler, false); }); } @@ -699,14 +702,13 @@ System.register('flarum/mentions/addPostQuoteButton', ['flarum/extend', 'flarum/ });; 'use strict'; -System.register('flarum/mentions/addPostReplyAction', ['flarum/extend', 'flarum/components/Button', 'flarum/components/CommentPost', 'flarum/mentions/utils/reply', 'flarum/mentions/utils/selectedText'], function (_export, _context) { +System.register('flarum/mentions/addPostReplyAction', ['flarum/extend', 'flarum/components/Button', 'flarum/components/CommentPost', 'flarum/mentions/utils/reply'], function (_export, _context) { "use strict"; - var extend, Button, CommentPost, reply, selectedText; + var extend, Button, CommentPost, reply; _export('default', function () { extend(CommentPost.prototype, 'actionItems', function (items) { - var _this = this; var post = this.props.post; @@ -716,7 +718,7 @@ System.register('flarum/mentions/addPostReplyAction', ['flarum/extend', 'flarum/ className: 'Button Button--link', children: app.translator.trans('flarum-mentions.forum.post.reply_link'), onclick: function onclick() { - reply(post, selectedText(_this.$('.Post-body'))); + return reply(post); } })); }); @@ -731,8 +733,6 @@ System.register('flarum/mentions/addPostReplyAction', ['flarum/extend', 'flarum/ CommentPost = _flarumComponentsCommentPost.default; }, function (_flarumMentionsUtilsReply) { reply = _flarumMentionsUtilsReply.default; - }, function (_flarumMentionsUtilsSelectedText) { - selectedText = _flarumMentionsUtilsSelectedText.default; }], execute: function () {} }; diff --git a/extensions/mentions/js/forum/src/addPostQuoteButton.js b/extensions/mentions/js/forum/src/addPostQuoteButton.js index 4408a0b43..6dfd42bd5 100644 --- a/extensions/mentions/js/forum/src/addPostQuoteButton.js +++ b/extensions/mentions/js/forum/src/addPostQuoteButton.js @@ -16,26 +16,27 @@ export default function addPostQuoteButton() { // button into it. const $container = $(''); - this.$() - .after($container) - .on('mouseup', function(e) { - setTimeout(() => { - const content = selectedText($postBody); - if (content) { - const button = new PostQuoteButton({post, content}); - m.render($container[0], button.render()); + const handler = function(e) { + setTimeout(() => { + const content = selectedText($postBody); + if (content) { + const button = new PostQuoteButton({post, content}); + m.render($container[0], button.render()); - const rects = window.getSelection().getRangeAt(0).getClientRects(); - const firstRect = rects[0]; + const rects = window.getSelection().getRangeAt(0).getClientRects(); + const firstRect = rects[0]; - if (e.clientY < firstRect.bottom && e.clientX - firstRect.right < firstRect.left - e.clientX) { - button.showStart(firstRect.left, firstRect.top); - } else { - const lastRect = rects[rects.length - 1]; - button.showEnd(lastRect.right, lastRect.bottom); - } + if (e.clientY < firstRect.bottom && e.clientX - firstRect.right < firstRect.left - e.clientX) { + button.showStart(firstRect.left, firstRect.top); + } else { + const lastRect = rects[rects.length - 1]; + button.showEnd(lastRect.right, lastRect.bottom); } - }, 1); - }); + } + }, 1); + }; + + this.$().after($container).on('mouseup', handler); + document.addEventListener('selectionchange', handler, false); }); } diff --git a/extensions/mentions/js/forum/src/addPostReplyAction.js b/extensions/mentions/js/forum/src/addPostReplyAction.js index 0172d1809..e6eb2c2cb 100644 --- a/extensions/mentions/js/forum/src/addPostReplyAction.js +++ b/extensions/mentions/js/forum/src/addPostReplyAction.js @@ -3,7 +3,6 @@ import Button from 'flarum/components/Button'; import CommentPost from 'flarum/components/CommentPost'; import reply from 'flarum/mentions/utils/reply'; -import selectedText from 'flarum/mentions/utils/selectedText'; export default function () { extend(CommentPost.prototype, 'actionItems', function (items) { @@ -16,9 +15,7 @@ export default function () { Button.component({ className: 'Button Button--link', children: app.translator.trans('flarum-mentions.forum.post.reply_link'), - onclick: () => { - reply(post, selectedText(this.$('.Post-body'))); - } + onclick: () => reply(post) }) ); });