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

View File

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