mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 10:29:35 +08:00
do not select the marker in Chrome
This commit is contained in:
parent
d9a16079a5
commit
9c820443fa
|
@ -39,6 +39,7 @@ Discourse.QuoteButtonController = Discourse.Controller.extend({
|
|||
var selection = window.getSelection();
|
||||
// no selections
|
||||
if (selection.rangeCount === 0) return;
|
||||
|
||||
// retrieve the selected range
|
||||
var range = selection.getRangeAt(0),
|
||||
cloned = range.cloneRange(),
|
||||
|
@ -55,7 +56,6 @@ Discourse.QuoteButtonController = Discourse.Controller.extend({
|
|||
if (this.get('buffer') === selectedText) return;
|
||||
|
||||
// we need to retrieve the post data from the posts collection in the topic controller
|
||||
|
||||
var postStream = this.get('controllers.topic.postStream');
|
||||
this.set('post', postStream.findLoadedPost(postId));
|
||||
this.set('buffer', selectedText);
|
||||
|
@ -64,31 +64,32 @@ Discourse.QuoteButtonController = Discourse.Controller.extend({
|
|||
// (ie. moves the end point to the start point)
|
||||
range.collapse(true);
|
||||
|
||||
// create a marker element containing a single invisible character
|
||||
// create a marker element
|
||||
var markerElement = document.createElement("span");
|
||||
// containing a single invisible character
|
||||
markerElement.appendChild(document.createTextNode("\ufeff"));
|
||||
// insert it at the beginning of our range
|
||||
// and insert it at the beginning of our selection range
|
||||
range.insertNode(markerElement);
|
||||
|
||||
// work around chrome that would sometimes lose the selection
|
||||
// retrieve the position of the market
|
||||
var markerOffset = $(markerElement).offset(),
|
||||
$quoteButton = $('.quote-button');
|
||||
|
||||
// remove the marker
|
||||
markerElement.parentNode.removeChild(markerElement);
|
||||
|
||||
// work around Chrome that would sometimes lose the selection
|
||||
var sel = window.getSelection();
|
||||
sel.removeAllRanges();
|
||||
sel.addRange(cloned);
|
||||
|
||||
// move the quote button at the beginning of the selection
|
||||
var markerOffset = $(markerElement).offset(),
|
||||
$quoteButton = $('.quote-button');
|
||||
|
||||
|
||||
// move the quote button above the marker
|
||||
Em.run.schedule('afterRender', function() {
|
||||
$quoteButton.offset({
|
||||
top: markerOffset.top - $quoteButton.outerHeight() - 5,
|
||||
left: markerOffset.left
|
||||
});
|
||||
});
|
||||
|
||||
// remove the marker
|
||||
markerElement.parentNode.removeChild(markerElement);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user