Support quote button on mobile; make reply button behaviour consistent

closes flarum/core#972
This commit is contained in:
Toby Zerner 2016-06-03 11:24:33 +09:30
parent 999ef82d55
commit bfa9a1d68e
3 changed files with 28 additions and 30 deletions

View File

@ -660,7 +660,7 @@ System.register('flarum/mentions/addPostQuoteButton', ['flarum/extend', 'flarum/
// button into it.
var $container = $('<div class="Post-quoteButtonContainer"></div>');
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 () {}
};

View File

@ -16,26 +16,27 @@ export default function addPostQuoteButton() {
// button into it.
const $container = $('<div class="Post-quoteButtonContainer"></div>');
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);
});
}

View File

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