mirror of
https://github.com/flarum/core.git
synced 2025-07-29 12:40:40 +02:00
Support quote button on mobile; make reply button behaviour consistent
closes flarum/core#972
This commit is contained in:
16
extensions/mentions/js/forum/dist/extension.js
vendored
16
extensions/mentions/js/forum/dist/extension.js
vendored
@@ -660,7 +660,7 @@ System.register('flarum/mentions/addPostQuoteButton', ['flarum/extend', 'flarum/
|
|||||||
// button into it.
|
// button into it.
|
||||||
var $container = $('<div class="Post-quoteButtonContainer"></div>');
|
var $container = $('<div class="Post-quoteButtonContainer"></div>');
|
||||||
|
|
||||||
this.$().after($container).on('mouseup', function (e) {
|
var handler = function handler(e) {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
var content = selectedText($postBody);
|
var content = selectedText($postBody);
|
||||||
if (content) {
|
if (content) {
|
||||||
@@ -678,7 +678,10 @@ System.register('flarum/mentions/addPostQuoteButton', ['flarum/extend', 'flarum/
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 1);
|
}, 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';
|
'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";
|
"use strict";
|
||||||
|
|
||||||
var extend, Button, CommentPost, reply, selectedText;
|
var extend, Button, CommentPost, reply;
|
||||||
|
|
||||||
_export('default', function () {
|
_export('default', function () {
|
||||||
extend(CommentPost.prototype, 'actionItems', function (items) {
|
extend(CommentPost.prototype, 'actionItems', function (items) {
|
||||||
var _this = this;
|
|
||||||
|
|
||||||
var post = this.props.post;
|
var post = this.props.post;
|
||||||
|
|
||||||
@@ -716,7 +718,7 @@ System.register('flarum/mentions/addPostReplyAction', ['flarum/extend', 'flarum/
|
|||||||
className: 'Button Button--link',
|
className: 'Button Button--link',
|
||||||
children: app.translator.trans('flarum-mentions.forum.post.reply_link'),
|
children: app.translator.trans('flarum-mentions.forum.post.reply_link'),
|
||||||
onclick: function onclick() {
|
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;
|
CommentPost = _flarumComponentsCommentPost.default;
|
||||||
}, function (_flarumMentionsUtilsReply) {
|
}, function (_flarumMentionsUtilsReply) {
|
||||||
reply = _flarumMentionsUtilsReply.default;
|
reply = _flarumMentionsUtilsReply.default;
|
||||||
}, function (_flarumMentionsUtilsSelectedText) {
|
|
||||||
selectedText = _flarumMentionsUtilsSelectedText.default;
|
|
||||||
}],
|
}],
|
||||||
execute: function () {}
|
execute: function () {}
|
||||||
};
|
};
|
||||||
|
@@ -16,26 +16,27 @@ export default function addPostQuoteButton() {
|
|||||||
// button into it.
|
// button into it.
|
||||||
const $container = $('<div class="Post-quoteButtonContainer"></div>');
|
const $container = $('<div class="Post-quoteButtonContainer"></div>');
|
||||||
|
|
||||||
this.$()
|
const handler = function(e) {
|
||||||
.after($container)
|
setTimeout(() => {
|
||||||
.on('mouseup', function(e) {
|
const content = selectedText($postBody);
|
||||||
setTimeout(() => {
|
if (content) {
|
||||||
const content = selectedText($postBody);
|
const button = new PostQuoteButton({post, content});
|
||||||
if (content) {
|
m.render($container[0], button.render());
|
||||||
const button = new PostQuoteButton({post, content});
|
|
||||||
m.render($container[0], button.render());
|
|
||||||
|
|
||||||
const rects = window.getSelection().getRangeAt(0).getClientRects();
|
const rects = window.getSelection().getRangeAt(0).getClientRects();
|
||||||
const firstRect = rects[0];
|
const firstRect = rects[0];
|
||||||
|
|
||||||
if (e.clientY < firstRect.bottom && e.clientX - firstRect.right < firstRect.left - e.clientX) {
|
if (e.clientY < firstRect.bottom && e.clientX - firstRect.right < firstRect.left - e.clientX) {
|
||||||
button.showStart(firstRect.left, firstRect.top);
|
button.showStart(firstRect.left, firstRect.top);
|
||||||
} else {
|
} else {
|
||||||
const lastRect = rects[rects.length - 1];
|
const lastRect = rects[rects.length - 1];
|
||||||
button.showEnd(lastRect.right, lastRect.bottom);
|
button.showEnd(lastRect.right, lastRect.bottom);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, 1);
|
}
|
||||||
});
|
}, 1);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.$().after($container).on('mouseup', handler);
|
||||||
|
document.addEventListener('selectionchange', handler, false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,6 @@ import Button from 'flarum/components/Button';
|
|||||||
import CommentPost from 'flarum/components/CommentPost';
|
import CommentPost from 'flarum/components/CommentPost';
|
||||||
|
|
||||||
import reply from 'flarum/mentions/utils/reply';
|
import reply from 'flarum/mentions/utils/reply';
|
||||||
import selectedText from 'flarum/mentions/utils/selectedText';
|
|
||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
extend(CommentPost.prototype, 'actionItems', function (items) {
|
extend(CommentPost.prototype, 'actionItems', function (items) {
|
||||||
@@ -16,9 +15,7 @@ export default function () {
|
|||||||
Button.component({
|
Button.component({
|
||||||
className: 'Button Button--link',
|
className: 'Button Button--link',
|
||||||
children: app.translator.trans('flarum-mentions.forum.post.reply_link'),
|
children: app.translator.trans('flarum-mentions.forum.post.reply_link'),
|
||||||
onclick: () => {
|
onclick: () => reply(post)
|
||||||
reply(post, selectedText(this.$('.Post-body')));
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user