Add quote previewing event listeners only when needed.

This commit is contained in:
Nicolas Stepien 2012-02-10 21:00:28 +01:00
parent d1cf993e14
commit fcc01e6a39
2 changed files with 19 additions and 29 deletions

View File

@ -2797,11 +2797,7 @@
continue;
}
link = a.cloneNode(true);
if (conf['Quote Preview']) {
$.on(link, 'mouseover', quotePreview.mouseover);
$.on(link, 'mousemove', ui.hover);
$.on(link, 'mouseout', quotePreview.mouseout);
}
if (conf['Quote Preview']) $.on(link, 'mouseover', quotePreview.mouseover);
if (conf['Quote Inline']) $.on(link, 'click', quoteInline.toggle);
if (!((container = $('.container', el)) && container.parentNode === el)) {
container = $.el('span', {
@ -2945,20 +2941,15 @@
return g.callbacks.push(this.node);
},
node: function(root) {
var quote, _i, _len, _ref, _results;
var quote, _i, _len, _ref;
_ref = $$('.quotelink, .backlink', root);
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
quote = _ref[_i];
if (!quote.hash) continue;
$.on(quote, 'mouseover', quotePreview.mouseover);
$.on(quote, 'mousemove', ui.hover);
_results.push($.on(quote, 'mouseout', quotePreview.mouseout));
if (quote.hash) $.on(quote, 'mouseover', quotePreview.mouseover);
}
return _results;
},
mouseover: function(e) {
var el, id, qp, quote, replyID, threadID, _i, _len, _ref, _results;
var el, id, qp, quote, replyID, threadID, _i, _len, _ref;
qp = ui.el = $.el('div', {
id: 'qp',
className: 'reply dialog'
@ -2971,16 +2962,10 @@
if (/\bbacklink\b/.test(this.className)) {
replyID = $.x('preceding-sibling::input', this.parentNode).name;
_ref = $$('.quotelink', qp);
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
quote = _ref[_i];
if (quote.hash.slice(1) === replyID) {
_results.push(quote.className = 'forwardlink');
} else {
_results.push(void 0);
}
if (quote.hash.slice(1) === replyID) quote.className = 'forwardlink';
}
return _results;
}
} else {
qp.innerHTML = "Loading " + id + "...";
@ -2988,13 +2973,17 @@
$.cache(this.pathname, (function() {
return quotePreview.parse(this, id, threadID);
}));
return ui.hover(e);
ui.hover(e);
}
$.on(this, 'mousemove', ui.hover);
return $.on(this, 'mouseout', quotePreview.mouseout);
},
mouseout: function() {
var el;
if (el = $.id(this.hash.slice(1))) $.removeClass(el, 'qphl');
return ui.hoverend();
ui.hoverend();
$.off(this, 'mousemove', ui.hover);
return $.off(this, 'mouseout', quotePreview.mouseout);
},
parse: function(req, id, threadID) {
var body, html, op, qp, reply, _i, _len, _ref;

View File

@ -2215,8 +2215,6 @@ quoteBacklink =
link = a.cloneNode true
if conf['Quote Preview']
$.on link, 'mouseover', quotePreview.mouseover
$.on link, 'mousemove', ui.hover
$.on link, 'mouseout', quotePreview.mouseout
if conf['Quote Inline']
$.on link, 'click', quoteInline.toggle
unless (container = $ '.container', el) and container.parentNode is el
@ -2315,10 +2313,8 @@ quotePreview =
g.callbacks.push @node
node: (root) ->
for quote in $$ '.quotelink, .backlink', root
continue unless quote.hash
$.on quote, 'mouseover', quotePreview.mouseover
$.on quote, 'mousemove', ui.hover
$.on quote, 'mouseout', quotePreview.mouseout
$.on quote, 'mouseover', quotePreview.mouseover if quote.hash
return
mouseover: (e) ->
qp = ui.el = $.el 'div',
id: 'qp'
@ -2339,9 +2335,14 @@ quotePreview =
threadID = @pathname.split('/').pop() or $.x('ancestor::div[@class="thread"]/div', @).id
$.cache @pathname, (-> quotePreview.parse @, id, threadID)
ui.hover e
$.on @, 'mousemove', ui.hover
$.on @, 'mouseout', quotePreview.mouseout
mouseout: ->
$.removeClass el, 'qphl' if el = $.id @hash[1..]
if el = $.id @hash[1..]
$.removeClass el, 'qphl'
ui.hoverend()
$.off @, 'mousemove', ui.hover
$.off @, 'mouseout', quotePreview.mouseout
parse: (req, id, threadID) ->
return unless (qp = ui.el) and (qp.innerHTML is "Loading #{id}...")