mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-04-30 16:04:36 -04:00
FIX: quote reply button was wrong when there is a custom header
This commit is contained in:
parent
ade4dd32de
commit
aecf03c4f5
2 changed files with 27 additions and 20 deletions
app/assets/javascripts/discourse
|
@ -16,25 +16,35 @@ Discourse.QuoteButtonController = Discourse.Controller.extend({
|
||||||
$LAB.script(assetPath('defer/html-sanitizer-bundle'));
|
$LAB.script(assetPath('defer/html-sanitizer-bundle'));
|
||||||
},
|
},
|
||||||
|
|
||||||
// If the buffer is cleared, clear out other state (post)
|
/**
|
||||||
bufferChanged: (function() {
|
If the buffer is cleared, clear out other state (post)
|
||||||
|
**/
|
||||||
|
bufferChanged: function() {
|
||||||
if (this.blank('buffer')) this.set('post', null);
|
if (this.blank('buffer')) this.set('post', null);
|
||||||
}).observes('buffer'),
|
}.observes('buffer'),
|
||||||
|
|
||||||
|
/**
|
||||||
|
Save the currently selected text and displays the
|
||||||
|
"quote reply" buttong
|
||||||
|
|
||||||
|
@method selectText
|
||||||
|
**/
|
||||||
selectText: function(e) {
|
selectText: function(e) {
|
||||||
// anonymous users cannot "quote-reply"
|
// anonymous users cannot "quote-reply"
|
||||||
if (!Discourse.get('currentUser')) return;
|
if (!Discourse.get('currentUser')) return;
|
||||||
// there is no need to display the "quote-reply" button if we can't create a post
|
// don't display the "quote-reply" button if we can't create a post
|
||||||
if (!this.get('controllers.topic.content.can_create_post')) return;
|
if (!this.get('controllers.topic.content.can_create_post')) return;
|
||||||
|
|
||||||
// retrieve the selected range
|
// retrieve the selected range
|
||||||
var range = window.getSelection().getRangeAt(0);
|
var range = window.getSelection().getRangeAt(0);
|
||||||
var cloned = range.cloneRange();
|
var cloned = range.cloneRange();
|
||||||
|
|
||||||
// do not be present the "quote reply" button if you select text spanning two posts
|
// don't display the "quote reply" button if you select text spanning two posts
|
||||||
// this basically look for the first "DIV" container...
|
// this basically look for the first "DIV" container...
|
||||||
var commonDivAncestorContainer = range.commonAncestorContainer;
|
var commonDivAncestorContainer = range.commonAncestorContainer;
|
||||||
while (commonDivAncestorContainer.nodeName !== 'DIV') commonDivAncestorContainer = commonDivAncestorContainer.parentNode;
|
while (commonDivAncestorContainer.nodeName !== 'DIV') {
|
||||||
|
commonDivAncestorContainer = commonDivAncestorContainer.parentNode;
|
||||||
|
}
|
||||||
// ... and check it has the 'cooked' class (which indicates we're in a post)
|
// ... and check it has the 'cooked' class (which indicates we're in a post)
|
||||||
if (commonDivAncestorContainer.className.indexOf('cooked') === -1) return;
|
if (commonDivAncestorContainer.className.indexOf('cooked') === -1) return;
|
||||||
|
|
||||||
|
@ -55,23 +65,20 @@ Discourse.QuoteButtonController = Discourse.Controller.extend({
|
||||||
// insert it at the beginning of our range
|
// insert it at the beginning of our range
|
||||||
range.insertNode(markerElement);
|
range.insertNode(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);
|
||||||
|
|
||||||
// find marker position (cf. http://www.quirksmode.org/js/findpos.html)
|
|
||||||
var obj = markerElement, left = 0, top = 0;
|
|
||||||
do {
|
|
||||||
left += obj.offsetLeft;
|
|
||||||
top += obj.offsetTop;
|
|
||||||
obj = obj.offsetParent;
|
|
||||||
} while (obj.offsetParent);
|
|
||||||
|
|
||||||
// move the quote button at the beginning of the selection
|
// move the quote button at the beginning of the selection
|
||||||
var $quoteButton = $('.quote-button');
|
var markerOffset = $(markerElement).offset(),
|
||||||
$quoteButton.css({
|
$quoteButton = $('.quote-button');
|
||||||
top: top - $quoteButton.outerHeight() - 5,
|
|
||||||
left: left
|
Em.run.next(function(){
|
||||||
|
$quoteButton.offset({
|
||||||
|
top: markerOffset.top - $quoteButton.outerHeight() - 5,
|
||||||
|
left: markerOffset.left
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// remove the marker
|
// remove the marker
|
||||||
|
|
|
@ -15,9 +15,9 @@ Discourse.QuoteButtonView = Discourse.View.extend({
|
||||||
buffer.push(Em.String.i18n("post.quote_reply"));
|
buffer.push(Em.String.i18n("post.quote_reply"));
|
||||||
},
|
},
|
||||||
|
|
||||||
hasBuffer: (function() {
|
hasBuffer: function() {
|
||||||
return this.present('controller.buffer') ? 'visible' : null;
|
return this.present('controller.buffer') ? 'visible' : null;
|
||||||
}).property('controller.buffer'),
|
}.property('controller.buffer'),
|
||||||
|
|
||||||
willDestroyElement: function() {
|
willDestroyElement: function() {
|
||||||
$(document).off("mousedown.quote-button");
|
$(document).off("mousedown.quote-button");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue