Merge pull request #103 from MayhemYDG/master

Inlining fix
This commit is contained in:
James Campos 2011-05-18 14:21:06 -07:00
commit 822a98322f
2 changed files with 54 additions and 43 deletions

View File

@ -1674,7 +1674,7 @@
}, },
node: function(root) { node: function(root) {
var el, id, link, qid, quote, quotes, tid, _i, _len, _ref, _results; var el, id, link, qid, quote, quotes, tid, _i, _len, _ref, _results;
if (root.className === 'inline') { if (root.className) {
return; return;
} }
id = root.id || $('td[id]', root).id; id = root.id || $('td[id]', root).id;
@ -1731,53 +1731,52 @@
return _results; return _results;
}, },
toggle: function(e) { toggle: function(e) {
var el, id, inline, req, root, td, threadID; var el, id, inline, req, root, table, threadID;
e.preventDefault(); e.preventDefault();
if (!(id = this.hash.slice(1))) { if (!(id = this.hash.slice(1))) {
return; return;
} }
root = $.x('ancestor::td[1]', this); root = $.x('ancestor::td[1]', this);
if (td = $("#i" + id, root)) { if (table = $("#i" + id, root)) {
$.rm($.x('ancestor::table[1]', td)); $.rm(table);
if (this.className === 'backlink') { if (this.className === 'backlink') {
$.show($.x('ancestor::table[1]', d.getElementById(id))); $.show($.x('ancestor::table[1]', d.getElementById(id)));
} }
return; return;
} }
inline = $.el('table', {
className: 'inline',
innerHTML: "<tbody><tr><td class=reply id=i" + id + "></td></tr></tbody>"
});
td = $('td', inline);
if (el = d.getElementById(id)) { if (el = d.getElementById(id)) {
td.innerHTML = el.innerHTML; inline = quoteInline.table(id, el.innerHTML);
if (this.className === 'backlink') {
$.after($('td > br:first-of-type, td > a:last-of-type', this.parentNode), inline);
return $.hide($.x('ancestor::table[1]', el));
} else {
return $.after(this.parentNode, inline);
}
} else { } else {
td.innerHTML = "Loading " + id + "..."; inline = $.el('td', {
className: 'reply inline',
id: "i" + id,
innerHTML: "Loading " + id + "..."
});
$.after(this.parentNode, inline);
threadID = this.pathname.split('/').pop() || $.x('ancestor::div[@class="thread"]/div', this).id; threadID = this.pathname.split('/').pop() || $.x('ancestor::div[@class="thread"]/div', this).id;
if (req = g.requests[threadID]) { if (req = g.requests[threadID]) {
if (req.readyState === 4) { if (req.readyState === 4) {
quoteInline.parse(req, id, threadID, inline); return quoteInline.parse(req, id, threadID, inline);
} }
} else { } else {
g.requests[threadID] = $.get(this.href, (function() { return g.requests[threadID] = $.get(this.href, (function() {
return quoteInline.parse(this, id, threadID, inline); return quoteInline.parse(this, id, threadID, inline);
})); }));
} }
} }
if (this.className === 'backlink') {
$.after($('td > br:first-of-type, td > a:last-of-type', this.parentNode), inline);
return $.hide($.x('ancestor::table[1]', el));
} else {
return $.after(this.parentNode, inline);
}
}, },
parse: function(req, id, threadID, inline) { parse: function(req, id, threadID, inline) {
var body, clone, html, op, reply, _i, _len, _ref; var body, html, newInline, op, reply, _i, _len, _ref;
if (req.status !== 200) { if (req.status !== 200) {
inline.innerHTML = "" + req.status + " " + req.statusText; inline.innerHTML = "" + req.status + " " + req.statusText;
return; return;
} }
clone = inline.cloneNode(true);
body = $.el('body', { body = $.el('body', {
innerHTML: req.responseText innerHTML: req.responseText
}); });
@ -1794,8 +1793,16 @@
} }
} }
} }
$('td', clone).innerHTML = html; newInline = quoteInline.table(id, html);
return $.replace(inline, clone); $.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>"
});
} }
}; };
quotePreview = { quotePreview = {
@ -1914,7 +1921,7 @@
}, },
cb: { cb: {
node: function(root) { node: function(root) {
if (root.className === 'inline') { if (root.className) {
return; return;
} }
unread.replies.push(root); unread.replies.push(root);

View File

@ -1352,7 +1352,7 @@ quoteBacklink =
init: -> init: ->
g.callbacks.push quoteBacklink.node g.callbacks.push quoteBacklink.node
node: (root) -> node: (root) ->
return if root.className is 'inline' return if root.className
#better coffee-script way of doing this? #better coffee-script way of doing this?
id = root.id or $('td[id]', root).id id = root.id or $('td[id]', root).id
quotes = {} quotes = {}
@ -1388,21 +1388,25 @@ quoteInline =
e.preventDefault() e.preventDefault()
return unless id = @hash[1..] return unless id = @hash[1..]
root = $.x 'ancestor::td[1]', this root = $.x 'ancestor::td[1]', this
if td = $ "#i#{id}", root if table = $ "#i#{id}", root
$.rm $.x 'ancestor::table[1]', td $.rm table
if @className is 'backlink' if @className is 'backlink'
$.show $.x 'ancestor::table[1]', d.getElementById id $.show $.x 'ancestor::table[1]', d.getElementById id
return return
inline = $.el 'table',
className: 'inline'
innerHTML: "<tbody><tr><td class=reply id=i#{id}></td></tr></tbody>"
td = $ 'td', inline
if el = d.getElementById id if el = d.getElementById id
td.innerHTML = el.innerHTML inline = quoteInline.table id, el.innerHTML
if @className is 'backlink'
$.after $('td > br:first-of-type, td > a:last-of-type', @parentNode), inline
$.hide $.x 'ancestor::table[1]', el
else
$.after @parentNode, inline
else else
td.innerHTML = "Loading #{id}..." inline = $.el 'td',
className: 'reply inline'
id: "i#{id}"
innerHTML: "Loading #{id}..."
$.after @parentNode, inline
# or ... is for index page new posts. # or ... is for index page new posts.
# FIXME x-thread quotes
threadID = @pathname.split('/').pop() or $.x('ancestor::div[@class="thread"]/div', this).id threadID = @pathname.split('/').pop() or $.x('ancestor::div[@class="thread"]/div', this).id
if req = g.requests[threadID] if req = g.requests[threadID]
if req.readyState is 4 if req.readyState is 4
@ -1410,17 +1414,11 @@ quoteInline =
else else
#FIXME need an array of callbacks #FIXME need an array of callbacks
g.requests[threadID] = $.get @href, (-> quoteInline.parse this, id, threadID, inline) g.requests[threadID] = $.get @href, (-> quoteInline.parse this, id, threadID, inline)
if @className is 'backlink'
$.after $('td > br:first-of-type, td > a:last-of-type', @parentNode), inline
$.hide $.x 'ancestor::table[1]', el
else
$.after @parentNode, inline
parse: (req, id, threadID, inline) -> parse: (req, id, threadID, inline) ->
if req.status isnt 200 if req.status isnt 200
inline.innerHTML = "#{req.status} #{req.statusText}" inline.innerHTML = "#{req.status} #{req.statusText}"
return return
clone = inline.cloneNode true
body = $.el 'body', body = $.el 'body',
innerHTML: req.responseText innerHTML: req.responseText
if id == threadID #OP if id == threadID #OP
@ -1431,8 +1429,14 @@ quoteInline =
if reply.id == id if reply.id == id
html = reply.innerHTML html = reply.innerHTML
break break
$('td', clone).innerHTML = html newInline = quoteInline.table id, html
$.replace inline, clone $.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>"
quotePreview = quotePreview =
init: -> init: ->
@ -1513,7 +1517,7 @@ unread =
cb: cb:
node: (root) -> node: (root) ->
return if root.className is 'inline' return if root.className
unread.replies.push root unread.replies.push root
unread.updateTitle() unread.updateTitle()
Favicon.update() Favicon.update()