ReplyHiding refactor.

This commit is contained in:
Nicolas Stepien 2012-03-10 20:50:45 +01:00
parent 628ae5d9db
commit dd77d0d89d
2 changed files with 81 additions and 111 deletions

View File

@ -610,7 +610,7 @@
continue; continue;
} }
} else { } else {
ReplyHiding.hideHide(post.el); ReplyHiding.hide(post.root);
} }
return; return;
} }
@ -883,76 +883,61 @@
ReplyHiding = { ReplyHiding = {
init: function() { init: function() {
this.a = $.el('a', { this.td = $.el('td', {
textContent: '[ - ]', noWrap: true,
href: 'javascript:;' className: 'replyhider',
innerHTML: '<a href="javascript:;">[ - ]</a>'
}); });
return g.callbacks.push(this.node); return g.callbacks.push(this.node);
}, },
node: function(post) { node: function(post) {
var a, dd; var td;
if (post["class"]) return; if (post["class"]) return;
dd = post.el.previousSibling; td = ReplyHiding.td.cloneNode(true);
dd.className = 'replyhider'; $.on(td.firstChild, 'click', ReplyHiding.toggle);
a = ReplyHiding.a.cloneNode(true); $.replace(post.el.previousSibling, td);
$.on(a, 'click', ReplyHiding.cb.hide); if (post.id in g.hiddenReplies) return ReplyHiding.hide(post.root);
$.replace(dd.firstChild, a);
if (post.id in g.hiddenReplies) return ReplyHiding.hide(post.el);
}, },
cb: { toggle: function() {
hide: function() { var id, parent, quote, table, _i, _j, _len, _len2, _ref, _ref2;
var reply; parent = this.parentNode;
reply = this.parentNode.nextSibling; if (parent.className === 'replyhider') {
return ReplyHiding.hide(reply); ReplyHiding.hide(parent.parentNode.parentNode.parentNode);
}, id = parent.nextSibling.id;
show: function() { _ref = $$(".quotelink[href='#" + id + "'], .backlink[href='#" + id + "']");
var div, table; for (_i = 0, _len = _ref.length; _i < _len; _i++) {
div = this.parentNode; quote = _ref[_i];
table = div.nextSibling; $.addClass(quote, 'filtered');
ReplyHiding.show(table); }
return $.rm(div); g.hiddenReplies[id] = Date.now();
} else {
table = parent.nextSibling;
table.hidden = false;
$.rm(parent);
id = table.firstChild.firstChild.lastChild.id;
_ref2 = $$(".quotelink[href='#" + id + "'], .backlink[href='#" + id + "']");
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
quote = _ref2[_j];
$.removeClass(quote, 'filtered');
}
delete g.hiddenReplies[id];
} }
},
hide: function(reply) {
var id, quote, _i, _len, _ref;
ReplyHiding.hideHide(reply);
id = reply.id;
_ref = $$(".quotelink[href='#" + id + "'], .backlink[href='#" + id + "']");
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
quote = _ref[_i];
$.addClass(quote, 'filtered');
}
g.hiddenReplies[id] = Date.now();
return $.set("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies); return $.set("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies);
}, },
hideHide: function(reply) { hide: function(table) {
var div, name, table, trip, uid, _ref, _ref2; var div, name, trip, uid, _ref, _ref2;
table = reply.parentNode.parentNode.parentNode;
if (table.hidden) return; if (table.hidden) return;
table.hidden = true; table.hidden = true;
if (conf['Show Stubs']) { if (!conf['Show Stubs']) return;
name = $('.commentpostername', reply).textContent; name = $('td[id] > .commentpostername', table).textContent;
uid = ((_ref = $('.posteruid', reply)) != null ? _ref.textContent : void 0) || ''; uid = ((_ref = $('td[id] > .posteruid', table)) != null ? _ref.textContent : void 0) || '';
trip = ((_ref2 = $('.postertrip', reply)) != null ? _ref2.textContent : void 0) || ''; trip = ((_ref2 = $('td[id] > .postertrip', table)) != null ? _ref2.textContent : void 0) || '';
div = $.el('div', { div = $.el('div', {
className: 'stub', className: 'stub',
innerHTML: "<a href=javascript:;><span>[ + ]</span> " + name + " " + uid + " " + trip + "</a>" innerHTML: "<a href=javascript:;><span>[ + ]</span> " + name + " " + uid + " " + trip + "</a>"
}); });
$.on($('a', div), 'click', ReplyHiding.cb.show); $.on(div.firstChild, 'click', ReplyHiding.toggle);
return $.before(table, div); return $.before(table, div);
}
},
show: function(table) {
var id, quote, _i, _len, _ref;
table.hidden = false;
id = $('td[id]', table).id;
_ref = $$(".quotelink[href='#" + id + "'], .backlink[href='#" + id + "']");
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
quote = _ref[_i];
$.removeClass(quote, 'filtered');
}
delete g.hiddenReplies[id];
return $.set("hiddenReplies/" + g.BOARD + "/", g.hiddenReplies);
} }
}; };

View File

@ -544,7 +544,7 @@ Filter =
else else
continue continue
else else
ReplyHiding.hideHide post.el ReplyHiding.hide post.root
return return
# Highlight # Highlight
@ -742,70 +742,55 @@ ExpandThread =
ReplyHiding = ReplyHiding =
init: -> init: ->
@a = $.el 'a', @td = $.el 'td',
textContent: '[ - ]' noWrap: true
href: 'javascript:;' className: 'replyhider'
innerHTML: '<a href="javascript:;">[ - ]</a>'
g.callbacks.push @node g.callbacks.push @node
node: (post) -> node: (post) ->
return if post.class return if post.class
dd = post.el.previousSibling td = ReplyHiding.td.cloneNode true
dd.className = 'replyhider' $.on td.firstChild, 'click', ReplyHiding.toggle
a = ReplyHiding.a.cloneNode true $.replace post.el.previousSibling, td
$.on a, 'click', ReplyHiding.cb.hide
$.replace dd.firstChild, a
if post.id of g.hiddenReplies if post.id of g.hiddenReplies
ReplyHiding.hide post.el ReplyHiding.hide post.root
cb: toggle: ->
hide: -> parent = @parentNode
reply = @parentNode.nextSibling if parent.className is 'replyhider'
ReplyHiding.hide reply ReplyHiding.hide parent.parentNode.parentNode.parentNode
id = parent.nextSibling.id
show: -> for quote in $$ ".quotelink[href='##{id}'], .backlink[href='##{id}']"
div = @parentNode $.addClass quote, 'filtered'
table = div.nextSibling g.hiddenReplies[id] = Date.now()
ReplyHiding.show table else
table = parent.nextSibling
$.rm div table.hidden = false
$.rm parent
hide: (reply) -> id = table.firstChild.firstChild.lastChild.id
ReplyHiding.hideHide reply for quote in $$ ".quotelink[href='##{id}'], .backlink[href='##{id}']"
$.removeClass quote, 'filtered'
id = reply.id delete g.hiddenReplies[id]
for quote in $$ ".quotelink[href='##{id}'], .backlink[href='##{id}']"
$.addClass quote, 'filtered'
g.hiddenReplies[id] = Date.now()
$.set "hiddenReplies/#{g.BOARD}/", g.hiddenReplies $.set "hiddenReplies/#{g.BOARD}/", g.hiddenReplies
hideHide: (reply) -> hide: (table) ->
table = reply.parentNode.parentNode.parentNode return if table.hidden # already hidden by filter
return if table.hidden #already hidden by filter
table.hidden = true table.hidden = true
if conf['Show Stubs'] return unless conf['Show Stubs']
name = $('.commentpostername', reply).textContent
uid = $('.posteruid', reply)?.textContent or ''
trip = $('.postertrip', reply)?.textContent or ''
div = $.el 'div', name = $('td[id] > .commentpostername', table).textContent
className: 'stub' uid = $('td[id] > .posteruid', table)?.textContent or ''
innerHTML: "<a href=javascript:;><span>[ + ]</span> #{name} #{uid} #{trip}</a>" trip = $('td[id] > .postertrip', table)?.textContent or ''
$.on $('a', div), 'click', ReplyHiding.cb.show
$.before table, div
show: (table) -> div = $.el 'div',
table.hidden = false className: 'stub'
innerHTML: "<a href=javascript:;><span>[ + ]</span> #{name} #{uid} #{trip}</a>"
id = $('td[id]', table).id $.on div.firstChild, 'click', ReplyHiding.toggle
for quote in $$ ".quotelink[href='##{id}'], .backlink[href='##{id}']" $.before table, div
$.removeClass quote, 'filtered'
delete g.hiddenReplies[id]
$.set "hiddenReplies/#{g.BOARD}/", g.hiddenReplies
Keybinds = Keybinds =
init: -> init: ->