From fcc01e6a39bddf60edd55941856e570718fae47f Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 10 Feb 2012 21:00:28 +0100 Subject: [PATCH] Add quote previewing event listeners only when needed. --- 4chan_x.user.js | 33 +++++++++++---------------------- script.coffee | 15 ++++++++------- 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 8b3b42475..dc4db8fe5 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -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; diff --git a/script.coffee b/script.coffee index c2bc8d9dc..82f5c32fd 100644 --- a/script.coffee +++ b/script.coffee @@ -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}...")