diff --git a/app/assets/javascripts/discourse/controllers/quote_button_controller.js b/app/assets/javascripts/discourse/controllers/quote_button_controller.js index e0713bb8945..8c1b9110ac8 100644 --- a/app/assets/javascripts/discourse/controllers/quote_button_controller.js +++ b/app/assets/javascripts/discourse/controllers/quote_button_controller.js @@ -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); }, /**