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();
|
var selection = window.getSelection();
|
||||||
// no selections
|
// no selections
|
||||||
if (selection.rangeCount === 0) return;
|
if (selection.rangeCount === 0) return;
|
||||||
|
|
||||||
// retrieve the selected range
|
// retrieve the selected range
|
||||||
var range = selection.getRangeAt(0),
|
var range = selection.getRangeAt(0),
|
||||||
cloned = range.cloneRange(),
|
cloned = range.cloneRange(),
|
||||||
|
@ -55,7 +56,6 @@ Discourse.QuoteButtonController = Discourse.Controller.extend({
|
||||||
if (this.get('buffer') === selectedText) return;
|
if (this.get('buffer') === selectedText) return;
|
||||||
|
|
||||||
// we need to retrieve the post data from the posts collection in the topic controller
|
// we need to retrieve the post data from the posts collection in the topic controller
|
||||||
|
|
||||||
var postStream = this.get('controllers.topic.postStream');
|
var postStream = this.get('controllers.topic.postStream');
|
||||||
this.set('post', postStream.findLoadedPost(postId));
|
this.set('post', postStream.findLoadedPost(postId));
|
||||||
this.set('buffer', selectedText);
|
this.set('buffer', selectedText);
|
||||||
|
@ -64,31 +64,32 @@ Discourse.QuoteButtonController = Discourse.Controller.extend({
|
||||||
// (ie. moves the end point to the start point)
|
// (ie. moves the end point to the start point)
|
||||||
range.collapse(true);
|
range.collapse(true);
|
||||||
|
|
||||||
// create a marker element containing a single invisible character
|
// create a marker element
|
||||||
var markerElement = document.createElement("span");
|
var markerElement = document.createElement("span");
|
||||||
|
// containing a single invisible character
|
||||||
markerElement.appendChild(document.createTextNode("\ufeff"));
|
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);
|
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();
|
var sel = window.getSelection();
|
||||||
sel.removeAllRanges();
|
sel.removeAllRanges();
|
||||||
sel.addRange(cloned);
|
sel.addRange(cloned);
|
||||||
|
|
||||||
// move the quote button at the beginning of the selection
|
// move the quote button above the marker
|
||||||
var markerOffset = $(markerElement).offset(),
|
|
||||||
$quoteButton = $('.quote-button');
|
|
||||||
|
|
||||||
|
|
||||||
Em.run.schedule('afterRender', function() {
|
Em.run.schedule('afterRender', function() {
|
||||||
$quoteButton.offset({
|
$quoteButton.offset({
|
||||||
top: markerOffset.top - $quoteButton.outerHeight() - 5,
|
top: markerOffset.top - $quoteButton.outerHeight() - 5,
|
||||||
left: markerOffset.left
|
left: markerOffset.left
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// remove the marker
|
|
||||||
markerElement.parentNode.removeChild(markerElement);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue