Slight performance improvement for the Anonymizer and ReportButton.

This commit is contained in:
Nicolas Stepien 2012-03-06 22:54:37 +01:00
parent f3e4c5b64a
commit 14d48f59b2
2 changed files with 23 additions and 26 deletions

View File

@ -2810,15 +2810,12 @@
return g.callbacks.push(this.node); return g.callbacks.push(this.node);
}, },
node: function(post) { node: function(post) {
var name, trip; var name, node;
name = $('.commentpostername, .postername', post.el); name = $('.commentpostername, .postername', post.el);
name.textContent = 'Anonymous'; name.textContent = 'Anonymous';
if (trip = $('.postertrip', post.el)) { node = name.nextElementSibling;
if (trip.parentNode.nodeName === 'A') { if (node.className === 'postertrip' || node.nodeName === 'A') {
return $.rm(trip.parentNode); return $.rm(node);
} else {
return $.rm(trip);
}
} }
} }
}; };
@ -3412,16 +3409,17 @@
ReportButton = { ReportButton = {
init: function() { init: function() {
this.a = $.el('a', {
className: 'reportbutton',
innerHTML: '[ ! ]',
href: 'javascript:;'
});
return g.callbacks.push(this.node); return g.callbacks.push(this.node);
}, },
node: function(post) { node: function(post) {
var a; var a;
if (!(a = $('.reportbutton', post.el))) { if (!(a = $('.reportbutton', post.el))) {
a = $.el('a', { a = ReportButton.a.cloneNode(true);
className: 'reportbutton',
innerHTML: '[ ! ]',
href: 'javascript:;'
});
$.after($('span[id]', post.el), [$.tn(' '), a]); $.after($('span[id]', post.el), [$.tn(' '), a]);
} }
return $.on(a, 'click', ReportButton.report); return $.on(a, 'click', ReportButton.report);
@ -3506,7 +3504,7 @@
if (!g.REPLY) return; if (!g.REPLY) return;
count = this.replies.length; count = this.replies.length;
if (conf['Unread Count']) d.title = "(" + count + ") " + this.title; if (conf['Unread Count']) d.title = "(" + count + ") " + this.title;
if (!(conf['Unread Favicon'] && count < 2 || forceUpdate)) return; if (!(conf['Unread Favicon'] && (count < 2 || forceUpdate))) return;
Favicon.el.href = g.dead ? count ? Favicon.unreadDead : Favicon.dead : count ? Favicon.unread : Favicon["default"]; Favicon.el.href = g.dead ? count ? Favicon.unreadDead : Favicon.dead : count ? Favicon.unread : Favicon["default"];
return $.add(d.head, Favicon.el); return $.add(d.head, Favicon.el);
} }
@ -3679,7 +3677,7 @@
a = post.img.parentNode; a = post.img.parentNode;
$.on(a, 'click', ImageExpand.cb.toggle); $.on(a, 'click', ImageExpand.cb.toggle);
if (ImageExpand.on && !post.root.hidden && post["class"] !== 'inline') { if (ImageExpand.on && !post.root.hidden && post["class"] !== 'inline') {
return ImageExpand.expand(a.firstChild); return ImageExpand.expand(post.img);
} }
}, },
cb: { cb: {

View File

@ -2367,11 +2367,9 @@ Anonymize =
node: (post) -> node: (post) ->
name = $ '.commentpostername, .postername', post.el name = $ '.commentpostername, .postername', post.el
name.textContent = 'Anonymous' name.textContent = 'Anonymous'
if trip = $ '.postertrip', post.el node = name.nextElementSibling
if trip.parentNode.nodeName is 'A' if node.className is 'postertrip' or node.nodeName is 'A'
$.rm trip.parentNode $.rm node
else
$.rm trip
Sauce = Sauce =
init: -> init: ->
@ -2806,13 +2804,14 @@ QuoteCT =
ReportButton = ReportButton =
init: -> init: ->
@a = $.el 'a',
className: 'reportbutton'
innerHTML: '[&nbsp;!&nbsp;]'
href: 'javascript:;'
g.callbacks.push @node g.callbacks.push @node
node: (post) -> node: (post) ->
if not a = $ '.reportbutton', post.el unless a = $ '.reportbutton', post.el
a = $.el 'a', a = ReportButton.a.cloneNode true
className: 'reportbutton'
innerHTML: '[&nbsp;!&nbsp;]'
href: 'javascript:;'
$.after $('span[id]', post.el), [$.tn(' '), a] $.after $('span[id]', post.el), [$.tn(' '), a]
$.on a, 'click', ReportButton.report $.on a, 'click', ReportButton.report
report: -> report: ->
@ -2882,7 +2881,7 @@ Unread =
if conf['Unread Count'] if conf['Unread Count']
d.title = "(#{count}) #{@title}" d.title = "(#{count}) #{@title}"
unless conf['Unread Favicon'] and count < 2 or forceUpdate unless conf['Unread Favicon'] and (count < 2 or forceUpdate)
return return
Favicon.el.href = Favicon.el.href =
@ -3012,7 +3011,7 @@ ImageExpand =
a = post.img.parentNode a = post.img.parentNode
$.on a, 'click', ImageExpand.cb.toggle $.on a, 'click', ImageExpand.cb.toggle
if ImageExpand.on and !post.root.hidden and post.class isnt 'inline' if ImageExpand.on and !post.root.hidden and post.class isnt 'inline'
ImageExpand.expand a.firstChild ImageExpand.expand post.img
cb: cb:
toggle: (e) -> toggle: (e) ->
return if e.shiftKey or e.altKey or e.ctrlKey or e.metaKey or e.button isnt 0 return if e.shiftKey or e.altKey or e.ctrlKey or e.metaKey or e.button isnt 0