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

View File

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