quoteInline refactor

This commit is contained in:
Nicolas Stepien 2011-10-04 19:05:09 +02:00
parent 4382457afb
commit b25a4fcbc2
2 changed files with 57 additions and 42 deletions

View File

@ -2428,36 +2428,33 @@
}); });
}, },
toggle: function(e) { toggle: function(e) {
var el, hidden, id, inline, inlined, root, table, threadID, _i, _len, _ref; var id;
if (e.shiftKey || e.altKey || e.ctrlKey || e.button !== 0) { if (e.shiftKey || e.altKey || e.ctrlKey || e.button !== 0) {
return; return;
} }
e.preventDefault(); e.preventDefault();
id = this.hash.slice(1); id = this.hash.slice(1);
if (table = $("#i" + id, $.x('ancestor::td[1]', this))) { if (this.classList.contains('inlined')) {
$.rm(table); quoteInline.rm(this, id);
$.removeClass(this, 'inlined'); } else {
_ref = $$('input', table); if ($.x('ancestor::td[@id]', this).id === id) {
for (_i = 0, _len = _ref.length; _i < _len; _i++) { return;
inlined = _ref[_i];
if (hidden = $.id(inlined.name)) {
$.x('ancestor::table[1]', hidden).hidden = false;
}
} }
return; quoteInline.add(this, id);
} }
root = this.parentNode.nodeName === 'FONT' ? this.parentNode : this.nextSibling ? this.nextSibling : this; return this.classList.toggle('inlined');
},
add: function(q, id) {
var el, inline, root, threadID;
root = q.parentNode.nodeName === 'FONT' ? q.parentNode : q.nextSibling ? q.nextSibling : q;
if (el = $.id(id)) { if (el = $.id(id)) {
inline = quoteInline.table(id, el.innerHTML); inline = quoteInline.table(id, el.innerHTML);
if (this.className === 'backlink') { if (q.className === 'backlink') {
if ($("a.backlink[href='#" + id + "']", el)) { $.after(q.parentNode, inline);
return; $.x('ancestor::table', el).hidden = true;
} return;
$.after(this.parentNode, inline);
$.x('ancestor::table[1]', el).hidden = true;
} else {
$.after(root, inline);
} }
return $.after(root, inline);
} else { } else {
inline = $.el('td', { inline = $.el('td', {
className: 'reply inline', className: 'reply inline',
@ -2465,13 +2462,24 @@
innerHTML: "Loading " + id + "..." innerHTML: "Loading " + id + "..."
}); });
$.after(root, inline); $.after(root, inline);
pathname = this.pathname; pathname = q.pathname;
threadID = pathname.split('/').pop(); threadID = pathname.split('/').pop();
$.cache(pathname, (function() { return $.cache(pathname, (function() {
return quoteInline.parse(this, pathname, id, threadID, inline); return quoteInline.parse(this, pathname, id, threadID, inline);
})); }));
} }
return $.addClass(this, 'inlined'); },
rm: function(q, id) {
var hidden, inlined, table, _i, _len, _ref;
table = $.x("following::*[@id='i" + id + "']", q);
_ref = $$('input', table);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
inlined = _ref[_i];
if (hidden = $.id(inlined.name)) {
$.x('ancestor::table[1]', hidden).hidden = false;
}
}
return $.rm(table);
}, },
parse: function(req, pathname, id, threadID, inline) { parse: function(req, pathname, id, threadID, inline) {
var body, href, html, link, newInline, op, quote, reply, _i, _j, _len, _len2, _ref, _ref2; var body, href, html, link, newInline, op, quote, reply, _i, _j, _len, _len2, _ref, _ref2;
@ -2486,7 +2494,7 @@
innerHTML: req.responseText innerHTML: req.responseText
}); });
if (id === threadID) { if (id === threadID) {
op = threading.op($('form[name=delform] > *', body)); op = threading.op($('body > form', body).firstChild);
html = op.innerHTML; html = op.innerHTML;
} else { } else {
_ref = $$('td.reply', body); _ref = $$('td.reply', body);

View File

@ -1792,35 +1792,42 @@ quoteInline =
$.bind quote, 'click', quoteInline.toggle $.bind quote, 'click', quoteInline.toggle
toggle: (e) -> toggle: (e) ->
return if e.shiftKey or e.altKey or e.ctrlKey or e.button isnt 0 return if e.shiftKey or e.altKey or e.ctrlKey or e.button isnt 0
e.preventDefault() e.preventDefault()
id = @hash[1..] id = @hash[1..]
if table = $ "#i#{id}", $.x 'ancestor::td[1]', @ if @classList.contains 'inlined'
$.rm table quoteInline.rm @, id
$.removeClass @, 'inlined' else
for inlined in $$ 'input', table return if $.x('ancestor::td[@id]', @).id is id
if hidden = $.id inlined.name quoteInline.add @, id
$.x('ancestor::table[1]', hidden).hidden = false @classList.toggle 'inlined'
return
root = if @parentNode.nodeName is 'FONT' then @parentNode else if @nextSibling then @nextSibling else @ add: (q, id) ->
root = if q.parentNode.nodeName is 'FONT' then q.parentNode else if q.nextSibling then q.nextSibling else q
if el = $.id id if el = $.id id
inline = quoteInline.table id, el.innerHTML inline = quoteInline.table id, el.innerHTML
if @className is 'backlink' if q.className is 'backlink'
return if $("a.backlink[href='##{id}']", el) $.after q.parentNode, inline
$.after @parentNode, inline $.x('ancestor::table', el).hidden = true
$.x('ancestor::table[1]', el).hidden = true return
else $.after root, inline
$.after root, inline
else else
inline = $.el 'td', inline = $.el 'td',
className: 'reply inline' className: 'reply inline'
id: "i#{id}" id: "i#{id}"
innerHTML: "Loading #{id}..." innerHTML: "Loading #{id}..."
$.after root, inline $.after root, inline
{pathname} = @ {pathname} = q
threadID = pathname.split('/').pop() threadID = pathname.split('/').pop()
$.cache pathname, (-> quoteInline.parse @, pathname, id, threadID, inline) $.cache pathname, (-> quoteInline.parse @, pathname, id, threadID, inline)
$.addClass @, 'inlined'
rm: (q, id) ->
#select the corresponding table or loading td
table = $.x "following::*[@id='i#{id}']", q
for inlined in $$ 'input', table
if hidden = $.id inlined.name
$.x('ancestor::table[1]', hidden).hidden = false
$.rm table
parse: (req, pathname, id, threadID, inline) -> parse: (req, pathname, id, threadID, inline) ->
return unless inline.parentNode return unless inline.parentNode
@ -1831,7 +1838,7 @@ quoteInline =
body = $.el 'body', body = $.el 'body',
innerHTML: req.responseText innerHTML: req.responseText
if id == threadID #OP if id == threadID #OP
op = threading.op $ 'form[name=delform] > *', body op = threading.op $('body > form', body).firstChild
html = op.innerHTML html = op.innerHTML
else else
for reply in $$ 'td.reply', body for reply in $$ 'td.reply', body