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

View File

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