Separate node callbacks from features' inits for profiling purposes.

This commit is contained in:
Nicolas Stepien 2012-02-10 19:59:24 +01:00
parent 658a969bc3
commit d1cf993e14
2 changed files with 311 additions and 283 deletions

View File

@ -612,7 +612,9 @@
strikethroughQuotes = { strikethroughQuotes = {
init: function() { init: function() {
return g.callbacks.push(function(root) { return g.callbacks.push(this.node);
},
node: function(root) {
var el, quote, _i, _len, _ref; var el, quote, _i, _len, _ref;
if (root.className === 'inline') return; if (root.className === 'inline') return;
_ref = $$('.quotelink', root); _ref = $$('.quotelink', root);
@ -623,7 +625,6 @@
if (conf['Recursive Filtering']) root.hidden = true; if (conf['Recursive Filtering']) root.hidden = true;
} }
} }
});
} }
}; };
@ -794,7 +795,9 @@
replyHiding = { replyHiding = {
init: function() { init: function() {
return g.callbacks.push(function(root) { return g.callbacks.push(this.node);
},
node: function(root) {
var a, dd, id, reply; var a, dd, id, reply;
if (!(dd = $('.doubledash', root))) return; if (!(dd = $('.doubledash', root))) return;
dd.className = 'replyhider'; dd.className = 'replyhider';
@ -807,7 +810,6 @@
reply = dd.nextSibling; reply = dd.nextSibling;
id = reply.id; id = reply.id;
if (id in g.hiddenReplies) return replyHiding.hide(reply); if (id in g.hiddenReplies) return replyHiding.hide(reply);
});
}, },
cb: { cb: {
hide: function() { hide: function() {
@ -1202,9 +1204,7 @@
form = d.forms[0]; form = d.forms[0];
$.before(form, link); $.before(form, link);
} }
g.callbacks.push(function(root) { g.callbacks.push(this.node);
return $.on($('.quotejs + .quotejs', root), 'click', qr.quote);
});
iframe = $.el('iframe', { iframe = $.el('iframe', {
id: 'iframe', id: 'iframe',
hidden: true, hidden: true,
@ -1235,6 +1235,9 @@
$.on(d, 'dragend', qr.drag); $.on(d, 'dragend', qr.drag);
return window.location = 'javascript:void(Recaptcha.focus_response_field=function(){})'; return window.location = 'javascript:void(Recaptcha.focus_response_field=function(){})';
}, },
node: function(root) {
return $.on($('.quotejs + .quotejs', root), 'click', qr.quote);
},
open: function() { open: function() {
if (qr.el) { if (qr.el) {
qr.el.hidden = false; qr.el.hidden = false;
@ -2570,7 +2573,9 @@
anonymize = { anonymize = {
init: function() { init: function() {
return g.callbacks.push(function(root) { return g.callbacks.push(this.node);
},
node: function(root) {
var name, trip; var name, trip;
name = $('.commentpostername, .postername', root); name = $('.commentpostername, .postername', root);
name.textContent = 'Anonymous'; name.textContent = 'Anonymous';
@ -2581,7 +2586,6 @@
return $.rm(trip); return $.rm(trip);
} }
} }
});
} }
}; };
@ -2627,7 +2631,9 @@
revealSpoilers = { revealSpoilers = {
init: function() { init: function() {
return g.callbacks.push(function(root) { return g.callbacks.push(this.node);
},
node: function(root) {
var board, img, imgID, _, _ref; var board, img, imgID, _, _ref;
if (!(img = $('img[alt^=Spoiler]', root)) || root.className === 'inline') { if (!(img = $('img[alt^=Spoiler]', root)) || root.className === 'inline') {
return; return;
@ -2636,7 +2642,6 @@
img.removeAttribute('width'); img.removeAttribute('width');
_ref = img.parentNode.href.match(/(\w+)\/src\/(\d+)/), _ = _ref[0], board = _ref[1], imgID = _ref[2]; _ref = img.parentNode.href.match(/(\w+)\/src\/(\d+)/), _ = _ref[0], board = _ref[1], imgID = _ref[2];
return img.src = "http://0.thumbs.4chan.org/" + board + "/thumb/" + imgID + "s.jpg"; return img.src = "http://0.thumbs.4chan.org/" + board + "/thumb/" + imgID + "s.jpg";
});
} }
}; };
@ -2656,7 +2661,7 @@
hour = chanOffset + Number(hour); hour = chanOffset + Number(hour);
return new Date(year, month, day, hour, min); return new Date(year, month, day, hour, min);
}; };
return g.callbacks.push(Time.node); return g.callbacks.push(this.node);
}, },
node: function(root) { node: function(root) {
var node, time; var node, time;
@ -2769,7 +2774,9 @@
var format; var format;
format = conf['backlink'].replace(/%id/g, "' + id + '"); format = conf['backlink'].replace(/%id/g, "' + id + '");
quoteBacklink.funk = Function('id', "return '" + format + "'"); quoteBacklink.funk = Function('id', "return '" + format + "'");
return g.callbacks.push(function(root) { return g.callbacks.push(this.node);
},
node: function(root) {
var a, container, el, id, link, qid, quote, quotes, _i, _len, _ref, _results; var a, container, el, id, link, qid, quote, quotes, _i, _len, _ref, _results;
if (/\binline\b/.test(root.className)) return; if (/\binline\b/.test(root.className)) return;
quotes = {}; quotes = {};
@ -2806,13 +2813,14 @@
_results.push($.add(container, $.tn(' '), link)); _results.push($.add(container, $.tn(' '), link));
} }
return _results; return _results;
});
} }
}; };
quoteInline = { quoteInline = {
init: function() { init: function() {
return g.callbacks.push(function(root) { return g.callbacks.push(this.node);
},
node: function(root) {
var quote, _i, _len, _ref, _results; var quote, _i, _len, _ref, _results;
_ref = $$('.quotelink, .backlink', root); _ref = $$('.quotelink, .backlink', root);
_results = []; _results = [];
@ -2823,7 +2831,6 @@
_results.push($.on(quote, 'click', quoteInline.toggle)); _results.push($.on(quote, 'click', quoteInline.toggle));
} }
return _results; return _results;
});
}, },
toggle: function(e) { toggle: function(e) {
var id; var id;
@ -2935,7 +2942,9 @@
quotePreview = { quotePreview = {
init: function() { init: function() {
return g.callbacks.push(function(root) { return g.callbacks.push(this.node);
},
node: function(root) {
var quote, _i, _len, _ref, _results; var quote, _i, _len, _ref, _results;
_ref = $$('.quotelink, .backlink', root); _ref = $$('.quotelink, .backlink', root);
_results = []; _results = [];
@ -2947,7 +2956,6 @@
_results.push($.on(quote, 'mouseout', quotePreview.mouseout)); _results.push($.on(quote, 'mouseout', quotePreview.mouseout));
} }
return _results; 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, _results;
@ -3018,7 +3026,9 @@
quoteOP = { quoteOP = {
init: function() { init: function() {
return g.callbacks.push(function(root) { return g.callbacks.push(this.node);
},
node: function(root) {
var quote, tid, _i, _len, _ref, _results; var quote, tid, _i, _len, _ref, _results;
if (root.className === 'inline') return; if (root.className === 'inline') return;
tid = g.THREAD_ID || $.x('ancestor::div[contains(@class,"thread")]/div', root).id; tid = g.THREAD_ID || $.x('ancestor::div[contains(@class,"thread")]/div', root).id;
@ -3033,13 +3043,14 @@
} }
} }
return _results; return _results;
});
} }
}; };
quoteDR = { quoteDR = {
init: function() { init: function() {
return g.callbacks.push(function(root) { return g.callbacks.push(this.node);
},
node: function(root) {
var quote, tid, _i, _len, _ref, _results; var quote, tid, _i, _len, _ref, _results;
if (root.className === 'inline') return; if (root.className === 'inline') return;
tid = g.THREAD_ID || $.x('ancestor::div[contains(@class,"thread")]/div', root).id; tid = g.THREAD_ID || $.x('ancestor::div[contains(@class,"thread")]/div', root).id;
@ -3054,13 +3065,14 @@
} }
} }
return _results; return _results;
});
} }
}; };
reportButton = { reportButton = {
init: function() { init: function() {
return g.callbacks.push(function(root) { return g.callbacks.push(this.node);
},
node: function(root) {
var a, span; var a, span;
if (!(a = $('.reportbutton', root))) { if (!(a = $('.reportbutton', root))) {
span = $('span[id]', root); span = $('span[id]', root);
@ -3073,7 +3085,6 @@
$.after(span, $.tn(' ')); $.after(span, $.tn(' '));
} }
return $.on(a, 'click', reportButton.report); return $.on(a, 'click', reportButton.report);
});
}, },
report: function() { report: function() {
var id, set, url; var id, set, url;
@ -3100,7 +3111,7 @@
return 151; return 151;
} }
})(); })();
return g.callbacks.push(threadStats.node); return g.callbacks.push(this.node);
}, },
node: function(root) { node: function(root) {
var imgcount; var imgcount;
@ -3120,7 +3131,7 @@
this.title = d.title; this.title = d.title;
unread.update(); unread.update();
$.on(window, 'scroll', unread.scroll); $.on(window, 'scroll', unread.scroll);
return g.callbacks.push(unread.node); return g.callbacks.push(this.node);
}, },
replies: [], replies: [],
node: function(root) { node: function(root) {
@ -3257,13 +3268,14 @@
imgHover = { imgHover = {
init: function() { init: function() {
return g.callbacks.push(function(root) { return g.callbacks.push(this.node);
},
node: function(root) {
var thumb; var thumb;
if (!(thumb = $('img[md5]', root))) return; if (!(thumb = $('img[md5]', root))) return;
$.on(thumb, 'mouseover', imgHover.mouseover); $.on(thumb, 'mouseover', imgHover.mouseover);
$.on(thumb, 'mousemove', ui.hover); $.on(thumb, 'mousemove', ui.hover);
return $.on(thumb, 'mouseout', ui.hoverend); return $.on(thumb, 'mouseout', ui.hoverend);
});
}, },
mouseover: function() { mouseover: function() {
ui.el = $.el('img', { ui.el = $.el('img', {
@ -3276,18 +3288,19 @@
imgGif = { imgGif = {
init: function() { init: function() {
return g.callbacks.push(function(root) { return g.callbacks.push(this.node);
},
node: function(root) {
var src, thumb; var src, thumb;
if (root.hidden || !(thumb = $('img[md5]', root))) return; if (root.hidden || !(thumb = $('img[md5]', root))) return;
src = thumb.parentNode.href; src = thumb.parentNode.href;
if (/gif$/.test(src)) return thumb.src = src; if (/gif$/.test(src)) return thumb.src = src;
});
} }
}; };
imgExpand = { imgExpand = {
init: function() { init: function() {
g.callbacks.push(imgExpand.node); g.callbacks.push(this.node);
return imgExpand.dialog(); return imgExpand.dialog();
}, },
node: function(root) { node: function(root) {

View File

@ -455,7 +455,8 @@ filter =
strikethroughQuotes = strikethroughQuotes =
init: -> init: ->
g.callbacks.push (root) -> g.callbacks.push @node
node: (root) ->
return if root.className is 'inline' return if root.className is 'inline'
for quote in $$ '.quotelink', root for quote in $$ '.quotelink', root
if (el = $.id quote.hash[1..]) and el.parentNode.parentNode.parentNode.hidden if (el = $.id quote.hash[1..]) and el.parentNode.parentNode.parentNode.hidden
@ -578,7 +579,9 @@ expandThread =
replyHiding = replyHiding =
init: -> init: ->
g.callbacks.push (root) -> g.callbacks.push @node
node: (root) ->
return unless dd = $ '.doubledash', root return unless dd = $ '.doubledash', root
dd.className = 'replyhider' dd.className = 'replyhider'
a = $.el 'a', a = $.el 'a',
@ -875,8 +878,7 @@ qr =
$('textarea', qr.el).focus() $('textarea', qr.el).focus()
form = d.forms[0] form = d.forms[0]
$.before form, link $.before form, link
g.callbacks.push (root) -> g.callbacks.push @node
$.on $('.quotejs + .quotejs', root), 'click', qr.quote
iframe = $.el 'iframe', iframe = $.el 'iframe',
id: 'iframe' id: 'iframe'
@ -901,6 +903,9 @@ qr =
# prevent original captcha input from being focused on reload # prevent original captcha input from being focused on reload
window.location = 'javascript:void(Recaptcha.focus_response_field=function(){})' window.location = 'javascript:void(Recaptcha.focus_response_field=function(){})'
node: (root) ->
$.on $('.quotejs + .quotejs', root), 'click', qr.quote
open: -> open: ->
if qr.el if qr.el
qr.el.hidden = false qr.el.hidden = false
@ -2047,7 +2052,8 @@ watcher =
anonymize = anonymize =
init: -> init: ->
g.callbacks.push (root) -> g.callbacks.push @node
node: (root) ->
name = $ '.commentpostername, .postername', root name = $ '.commentpostername, .postername', root
name.textContent = 'Anonymous' name.textContent = 'Anonymous'
if trip = $ '.postertrip', root if trip = $ '.postertrip', root
@ -2086,7 +2092,8 @@ sauce =
revealSpoilers = revealSpoilers =
init: -> init: ->
g.callbacks.push (root) -> g.callbacks.push @node
node: (root) ->
return if not (img = $ 'img[alt^=Spoiler]', root) or root.className is 'inline' return if not (img = $ 'img[alt^=Spoiler]', root) or root.className is 'inline'
img.removeAttribute 'height' img.removeAttribute 'height'
img.removeAttribute 'width' img.removeAttribute 'width'
@ -2114,7 +2121,7 @@ Time =
hour = chanOffset + Number hour hour = chanOffset + Number hour
new Date year, month, day, hour, min new Date year, month, day, hour, min
g.callbacks.push Time.node g.callbacks.push @node
node: (root) -> node: (root) ->
return if root.className is 'inline' return if root.className is 'inline'
node = $('.posttime', root) or $('span[id]', root).previousSibling node = $('.posttime', root) or $('span[id]', root).previousSibling
@ -2187,7 +2194,8 @@ quoteBacklink =
init: -> init: ->
format = conf['backlink'].replace /%id/g, "' + id + '" format = conf['backlink'].replace /%id/g, "' + id + '"
quoteBacklink.funk = Function 'id', "return '#{format}'" quoteBacklink.funk = Function 'id', "return '#{format}'"
g.callbacks.push (root) -> g.callbacks.push @node
node: (root) ->
return if /\binline\b/.test root.className return if /\binline\b/.test root.className
quotes = {} quotes = {}
for quote in $$ '.quotelink', root for quote in $$ '.quotelink', root
@ -2219,7 +2227,8 @@ quoteBacklink =
quoteInline = quoteInline =
init: -> init: ->
g.callbacks.push (root) -> g.callbacks.push @node
node: (root) ->
for quote in $$ '.quotelink, .backlink', root for quote in $$ '.quotelink, .backlink', root
continue unless quote.hash continue unless quote.hash
quote.removeAttribute 'onclick' quote.removeAttribute 'onclick'
@ -2303,7 +2312,8 @@ quoteInline =
quotePreview = quotePreview =
init: -> init: ->
g.callbacks.push (root) -> g.callbacks.push @node
node: (root) ->
for quote in $$ '.quotelink, .backlink', root for quote in $$ '.quotelink, .backlink', root
continue unless quote.hash continue unless quote.hash
$.on quote, 'mouseover', quotePreview.mouseover $.on quote, 'mouseover', quotePreview.mouseover
@ -2354,7 +2364,8 @@ quotePreview =
quoteOP = quoteOP =
init: -> init: ->
g.callbacks.push (root) -> g.callbacks.push @node
node: (root) ->
return if root.className is 'inline' return if root.className is 'inline'
tid = g.THREAD_ID or $.x('ancestor::div[contains(@class,"thread")]/div', root).id tid = g.THREAD_ID or $.x('ancestor::div[contains(@class,"thread")]/div', root).id
for quote in $$ '.quotelink', root for quote in $$ '.quotelink', root
@ -2363,7 +2374,8 @@ quoteOP =
quoteDR = quoteDR =
init: -> init: ->
g.callbacks.push (root) -> g.callbacks.push @node
node: (root) ->
return if root.className is 'inline' return if root.className is 'inline'
tid = g.THREAD_ID or $.x('ancestor::div[contains(@class,"thread")]/div', root).id tid = g.THREAD_ID or $.x('ancestor::div[contains(@class,"thread")]/div', root).id
for quote in $$ '.quotelink', root for quote in $$ '.quotelink', root
@ -2373,7 +2385,8 @@ quoteDR =
reportButton = reportButton =
init: -> init: ->
g.callbacks.push (root) -> g.callbacks.push @node
node: (root) ->
if not a = $ '.reportbutton', root if not a = $ '.reportbutton', root
span = $ 'span[id]', root span = $ 'span[id]', root
a = $.el 'a', a = $.el 'a',
@ -2401,7 +2414,7 @@ threadStats =
251 251
else else
151 151
g.callbacks.push threadStats.node g.callbacks.push @node
node: (root) -> node: (root) ->
return if /\binline\b/.test root.className return if /\binline\b/.test root.className
$.id('postcount').textContent = ++threadStats.posts $.id('postcount').textContent = ++threadStats.posts
@ -2416,7 +2429,7 @@ unread =
@title = d.title @title = d.title
unread.update() unread.update()
$.on window, 'scroll', unread.scroll $.on window, 'scroll', unread.scroll
g.callbacks.push unread.node g.callbacks.push @node
replies: [] replies: []
@ -2527,7 +2540,8 @@ redirect =
imgHover = imgHover =
init: -> init: ->
g.callbacks.push (root) -> g.callbacks.push @node
node: (root) ->
return unless thumb = $ 'img[md5]', root return unless thumb = $ 'img[md5]', root
$.on thumb, 'mouseover', imgHover.mouseover $.on thumb, 'mouseover', imgHover.mouseover
$.on thumb, 'mousemove', ui.hover $.on thumb, 'mousemove', ui.hover
@ -2540,7 +2554,8 @@ imgHover =
imgGif = imgGif =
init: -> init: ->
g.callbacks.push (root) -> g.callbacks.push @node
node: (root) ->
return if root.hidden or !thumb = $ 'img[md5]', root return if root.hidden or !thumb = $ 'img[md5]', root
src = thumb.parentNode.href src = thumb.parentNode.href
if /gif$/.test src if /gif$/.test src
@ -2548,7 +2563,7 @@ imgGif =
imgExpand = imgExpand =
init: -> init: ->
g.callbacks.push imgExpand.node g.callbacks.push @node
imgExpand.dialog() imgExpand.dialog()
node: (root) -> node: (root) ->