Fix Quote Inlining.

ohboyherewego.diff
This commit is contained in:
Nicolas Stepien 2012-05-03 10:10:44 +02:00
parent 1433baacfd
commit 1e50568520
2 changed files with 120 additions and 112 deletions

View File

@ -3117,11 +3117,11 @@
return; return;
} }
e.preventDefault(); e.preventDefault();
id = this.hash.slice(1); id = this.hash.slice(2);
if (/\binlined\b/.test(this.className)) { if (/\binlined\b/.test(this.className)) {
QuoteInline.rm(this, id); QuoteInline.rm(this, id);
} else { } else {
if ($.x("ancestor::*[@id='" + id + "']", this)) { if ($.x("ancestor::div[contains(@id,'p" + id + "')]", this)) {
return; return;
} }
QuoteInline.add(this, id); QuoteInline.add(this, id);
@ -3129,61 +3129,60 @@
return this.classList.toggle('inlined'); return this.classList.toggle('inlined');
}, },
add: function(q, id) { add: function(q, id) {
var el, i, inline, pathname, root, table, threadID; var clonePost, el, i, inline, pathname, root;
root = q.parentNode.nodeName === 'FONT' ? q.parentNode : q.nextSibling ? q.nextSibling : q; root = $.x('ancestor::*[parent::blockquote]', q);
if (el = $.id(id)) { if (el = $.id("p" + id)) {
inline = QuoteInline.table(id, el.innerHTML); $.removeClass(el, 'qphl');
if ((i = Unread.replies.indexOf(el.parentNode.parentNode.parentNode)) !== -1) { clonePost = QuoteInline.clone(id, el);
if (/\bbacklink\b/.test(q.className)) {
$.after(q.parentNode, clonePost);
if (Conf['Forward Hiding']) {
$.addClass(el.parentNode, 'forwarded');
++el.dataset.forwarded || (el.dataset.forwarded = 1);
}
} else {
$.after(root, clonePost);
}
if ((i = Unread.replies.indexOf(el)) !== -1) {
Unread.replies.splice(i, 1); Unread.replies.splice(i, 1);
Unread.update(true); Unread.update(true);
} }
if (/\bbacklink\b/.test(q.className)) { return;
$.after(q.parentNode, inline);
if (Conf['Forward Hiding']) {
table = $.x('ancestor::table', el);
$.addClass(table, 'forwarded');
++table.title || (table.title = 1);
}
return;
}
return $.after(root, inline);
} else {
inline = $.el('td', {
className: 'reply inline',
id: "i" + id,
innerHTML: "Loading " + id + "..."
});
$.after(root, inline);
pathname = q.pathname;
threadID = pathname.split('/').pop();
return $.cache(pathname, (function() {
return QuoteInline.parse(this, pathname, id, threadID, inline);
}));
} }
inline = $.el('div', {
className: 'inline',
id: "i" + id,
textContent: "Loading " + id + "..."
});
$.after(root, inline);
pathname = q.pathname;
return $.cache(pathname, function() {
return QuoteInline.parse(this, pathname, id, inline);
});
}, },
rm: function(q, id) { rm: function(q, id) {
var inlined, table, _i, _len, _ref; var div, inlined, _i, _len, _ref;
table = $.x("following::*[@id='i" + id + "']", q); div = $.x("following::div[@id='i_pc" + id + "']", q);
$.rm(table); $.rm(div);
if (!Conf['Forward Hiding']) { if (!Conf['Forward Hiding']) {
return; return;
} }
_ref = $$('.backlink.inlined', table); _ref = $$('.backlink.inlined', div);
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
inlined = _ref[_i]; inlined = _ref[_i];
table = $.x('ancestor::table', $.id(inlined.hash.slice(1))); div = $.id(inlined.hash.slice(1));
if (!--table.title) { if (!--div.dataset.forwarded) {
$.removeClass(table, 'forwarded'); $.removeClass(div.parentNode, 'forwarded');
} }
} }
if (/\bbacklink\b/.test(q.className)) { if (/\bbacklink\b/.test(q.className)) {
table = $.x('ancestor::table', $.id(id)); div = $.id("p" + id);
if (!--table.title) { if (!--div.dataset.forwarded) {
return $.removeClass(table, 'forwarded'); return $.removeClass(div.parentNode, 'forwarded');
} }
} }
}, },
parse: function(req, pathname, id, threadID, inline) { parse: function(req, pathname, id, inline) {
var doc, href, link, newInline, node, quote, _i, _len, _ref; var doc, href, link, newInline, node, quote, _i, _len, _ref;
if (!inline.parentNode) { if (!inline.parentNode) {
return; return;
@ -3194,29 +3193,36 @@
} }
doc = d.implementation.createHTMLDocument(''); doc = d.implementation.createHTMLDocument('');
doc.documentElement.innerHTML = req.response; doc.documentElement.innerHTML = req.response;
node = doc.getElementById(id); node = doc.getElementById("p" + id);
newInline = QuoteInline.table(id, node.innerHTML); newInline = QuoteInline.clone(id, node);
_ref = $$('.quotelink', newInline); _ref = $$('.quotelink', newInline);
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
quote = _ref[_i]; quote = _ref[_i];
if ((href = quote.getAttribute('href')) === quote.hash) { href = quote.getAttribute('href');
quote.pathname = pathname; if (href[0] === '/') {
} else if (!g.REPLY && href !== quote.href) { continue;
quote.href = "res/" + href;
} }
quote.href = "res/" + href;
} }
link = $('.quotejs', newInline); link = $('.postInfo > .postNum > a:first-child', newInline);
link.href = "" + pathname + "#" + id; link.href = "" + pathname + "#p" + id;
link.nextSibling.href = "" + pathname + "#q" + id; link.nextSibling.href = "" + pathname + "#q" + id;
$.addClass(newInline, 'crossquote'); $.addClass(newInline, 'crossquote');
return $.replace(inline, newInline); return $.replace(inline, newInline);
}, },
table: function(id, html) { clone: function(id, el) {
return $.el('table', { var clone, node, _i, _len, _ref;
className: 'inline', clone = $.el('div', {
id: "i" + id, className: 'postContainer inline',
innerHTML: "<tbody><tr><td class=reply>" + html + "</td></tr></tbody>" id: "i_pc" + id
}); });
$.add(clone, el.cloneNode(true));
_ref = $$('[id]', clone);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
node = _ref[_i];
node.id = "i_" + node.id;
}
return clone;
} }
}; };
@ -3240,7 +3246,7 @@
} }
}, },
mouseover: function(e) { mouseover: function(e) {
var el, id, qp, quote, replyID, threadID, _i, _len, _ref; var el, id, qp, quote, replyID, _i, _len, _ref;
if (/\binlined\b/.test(this.className)) { if (/\binlined\b/.test(this.className)) {
return; return;
} }
@ -3265,10 +3271,9 @@
} }
} else { } else {
qp.textContent = "Loading " + id + "..."; qp.textContent = "Loading " + id + "...";
threadID = this.pathname.split('/').pop(); $.cache(this.pathname, function() {
$.cache(this.pathname, (function() { return QuotePreview.parse(this, id);
return QuotePreview.parse(this, id, threadID); });
}));
UI.hover(e); UI.hover(e);
} }
$.on(this, 'mousemove', UI.hover); $.on(this, 'mousemove', UI.hover);
@ -3276,14 +3281,14 @@
}, },
mouseout: function() { mouseout: function() {
var el; var el;
UI.hoverend();
if (el = $.id(this.hash.slice(1))) { if (el = $.id(this.hash.slice(1))) {
$.removeClass(el, 'qphl'); $.removeClass(el, 'qphl');
} }
UI.hoverend();
$.off(this, 'mousemove', UI.hover); $.off(this, 'mousemove', UI.hover);
return $.off(this, 'mouseout click', QuotePreview.mouseout); return $.off(this, 'mouseout click', QuotePreview.mouseout);
}, },
parse: function(req, id, threadID) { parse: function(req, id) {
var doc, node, post, qp; var doc, node, post, qp;
if (!((qp = UI.el) && qp.textContent === ("Loading " + id + "..."))) { if (!((qp = UI.el) && qp.textContent === ("Loading " + id + "..."))) {
return; return;
@ -3405,7 +3410,7 @@
ReportButton = { ReportButton = {
init: function() { init: function() {
this.a = $.el('a', { this.a = $.el('a', {
className: 'reportbutton', className: 'report_button',
innerHTML: '[&nbsp;!&nbsp;]', innerHTML: '[&nbsp;!&nbsp;]',
href: 'javascript:;' href: 'javascript:;'
}); });

View File

@ -2417,53 +2417,53 @@ QuoteInline =
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
e.preventDefault() e.preventDefault()
id = @hash[1..] id = @hash[2..]
if /\binlined\b/.test @className if /\binlined\b/.test @className
QuoteInline.rm @, id QuoteInline.rm @, id
else else
return if $.x "ancestor::*[@id='#{id}']", @ return if $.x "ancestor::div[contains(@id,'p#{id}')]", @
QuoteInline.add @, id QuoteInline.add @, id
@classList.toggle 'inlined' @classList.toggle 'inlined'
add: (q, id) -> add: (q, id) ->
root = if q.parentNode.nodeName is 'FONT' then q.parentNode else if q.nextSibling then q.nextSibling else q root = $.x 'ancestor::*[parent::blockquote]', q
if el = $.id id if el = $.id "p#{id}"
inline = QuoteInline.table id, el.innerHTML $.removeClass el, 'qphl'
if (i = Unread.replies.indexOf el.parentNode.parentNode.parentNode) isnt -1 clonePost = QuoteInline.clone id, el
if /\bbacklink\b/.test q.className
$.after q.parentNode, clonePost
if Conf['Forward Hiding']
$.addClass el.parentNode, 'forwarded'
# Will only unhide if there's no inlined backlinks of it anymore.
++el.dataset.forwarded or el.dataset.forwarded = 1
else
$.after root, clonePost
if (i = Unread.replies.indexOf el) isnt -1
Unread.replies.splice i, 1 Unread.replies.splice i, 1
Unread.update true Unread.update true
if /\bbacklink\b/.test q.className return
$.after q.parentNode, inline
if Conf['Forward Hiding'] inline = $.el 'div',
table = $.x 'ancestor::table', el className: 'inline'
$.addClass table, 'forwarded' id: "i#{id}"
# Will only unhide if there's no inlined backlinks of it anymore. textContent: "Loading #{id}..."
++table.title or table.title = 1 $.after root, inline
return {pathname} = q
$.after root, inline $.cache pathname, -> QuoteInline.parse @, pathname, id, inline
else
inline = $.el 'td',
className: 'reply inline'
id: "i#{id}"
innerHTML: "Loading #{id}..."
$.after root, inline
{pathname} = q
threadID = pathname.split('/').pop()
$.cache pathname, (-> QuoteInline.parse @, pathname, id, threadID, inline)
rm: (q, id) -> rm: (q, id) ->
#select the corresponding table or loading td # select the corresponding inlined quote or loading quote
table = $.x "following::*[@id='i#{id}']", q div = $.x "following::div[@id='i_pc#{id}']", q
$.rm table $.rm div
return unless Conf['Forward Hiding'] return unless Conf['Forward Hiding']
for inlined in $$ '.backlink.inlined', table for inlined in $$ '.backlink.inlined', div
table = $.x 'ancestor::table', $.id inlined.hash[1..] div = $.id inlined.hash[1..]
$.removeClass table, 'forwarded' unless --table.title $.removeClass div.parentNode, 'forwarded' unless --div.dataset.forwarded
if /\bbacklink\b/.test q.className if /\bbacklink\b/.test q.className
table = $.x 'ancestor::table', $.id id div = $.id "p#{id}"
$.removeClass table, 'forwarded' unless --table.title $.removeClass div.parentNode, 'forwarded' unless --div.dataset.forwarded
parse: (req, pathname, id, threadID, inline) -> parse: (req, pathname, id, inline) ->
return unless inline.parentNode return unless inline.parentNode
if req.status isnt 200 if req.status isnt 200
@ -2473,23 +2473,27 @@ QuoteInline =
doc = d.implementation.createHTMLDocument '' doc = d.implementation.createHTMLDocument ''
doc.documentElement.innerHTML = req.response doc.documentElement.innerHTML = req.response
node = doc.getElementById id node = doc.getElementById "p#{id}"
newInline = QuoteInline.table id, node.innerHTML newInline = QuoteInline.clone id, node
for quote in $$ '.quotelink', newInline for quote in $$ '.quotelink', newInline
if (href = quote.getAttribute 'href') is quote.hash #add pathname to normal quotes href = quote.getAttribute 'href'
quote.pathname = pathname continue if href[0] is '/' # Cross-board quote
else if !g.REPLY and href isnt quote.href #fix x-thread links, not x-board ones quote.href = "res/#{href}" # Fix pathnames
quote.href = "res/#{href}" link = $ '.postInfo > .postNum > a:first-child', newInline
link = $ '.quotejs', newInline link.href = "#{pathname}#p#{id}"
link.href = "#{pathname}##{id}"
link.nextSibling.href = "#{pathname}#q#{id}" link.nextSibling.href = "#{pathname}#q#{id}"
$.addClass newInline, 'crossquote' $.addClass newInline, 'crossquote'
$.replace inline, newInline $.replace inline, newInline
table: (id, html) ->
$.el 'table', clone: (id, el) ->
className: 'inline' clone = $.el 'div',
id: "i#{id}" className: 'postContainer inline'
innerHTML: "<tbody><tr><td class=reply>#{html}</td></tr></tbody>" id: "i_pc#{id}"
$.add clone, el.cloneNode true
for node in $$ '[id]', clone
# Don't mess with other features
node.id = "i_#{node.id}"
clone
QuotePreview = QuotePreview =
init: -> init: ->
@ -2517,18 +2521,17 @@ QuotePreview =
$.addClass quote, 'forwardlink' $.addClass quote, 'forwardlink'
else else
qp.textContent = "Loading #{id}..." qp.textContent = "Loading #{id}..."
threadID = @pathname.split('/').pop() $.cache @pathname, -> QuotePreview.parse @, id
$.cache @pathname, (-> QuotePreview.parse @, id, threadID)
UI.hover e UI.hover e
$.on @, 'mousemove', UI.hover $.on @, 'mousemove', UI.hover
$.on @, 'mouseout click', QuotePreview.mouseout $.on @, 'mouseout click', QuotePreview.mouseout
mouseout: -> mouseout: ->
UI.hoverend()
if el = $.id @hash[1..] if el = $.id @hash[1..]
$.removeClass el, 'qphl' $.removeClass el, 'qphl'
UI.hoverend()
$.off @, 'mousemove', UI.hover $.off @, 'mousemove', UI.hover
$.off @, 'mouseout click', QuotePreview.mouseout $.off @, 'mouseout click', QuotePreview.mouseout
parse: (req, id, threadID) -> parse: (req, id) ->
return unless (qp = UI.el) and qp.textContent is "Loading #{id}..." return unless (qp = UI.el) and qp.textContent is "Loading #{id}..."
if req.status isnt 200 if req.status isnt 200
@ -2637,7 +2640,7 @@ Quotify =
ReportButton = ReportButton =
init: -> init: ->
@a = $.el 'a', @a = $.el 'a',
className: 'reportbutton' className: 'report_button'
innerHTML: '[&nbsp;!&nbsp;]' innerHTML: '[&nbsp;!&nbsp;]'
href: 'javascript:;' href: 'javascript:;'
Main.callbacks.push @node Main.callbacks.push @node