expandThread: g.cache -> g.requests

This commit is contained in:
James Campos 2011-05-14 10:11:52 -07:00
parent 4ce920bff1
commit 749732accc
2 changed files with 27 additions and 37 deletions

View File

@ -537,32 +537,22 @@
var thread; var thread;
thread = this.parentNode; thread = this.parentNode;
return expandThread.toggle(thread); return expandThread.toggle(thread);
},
load: function(xhr, thread, a) {
var html, id;
if (xhr.status === 404) {
a.textContent.replace('X Loading...', '404');
return $.unbind(a, 'click', expandThread.cb.toggle);
} else {
html = xhr.responseText;
id = thread.firstChild.id;
g.cache[id] = html;
return expandThread.expand(html, thread, a);
}
} }
}, },
toggle: function(thread) { toggle: function(thread) {
var a, html, id, num, prev, table, _results; var a, num, prev, req, table, threadID, _results;
id = thread.firstChild.id; threadID = thread.firstChild.id;
a = $('a.omittedposts', thread); a = $('a.omittedposts', thread);
switch (a.textContent[0]) { switch (a.textContent[0]) {
case '+': case '+':
a.textContent = a.textContent.replace('+', 'X Loading...'); a.textContent = a.textContent.replace('+', 'X Loading...');
if (html = g.cache[id]) { if (req = g.requests[threadID]) {
return expandThread.expand(html, thread, a); if (req.readyState === 4) {
return expandThread.parse(req, thread, a);
}
} else { } else {
return g.requests[id] = $.get("res/" + id, (function() { return g.requests[threadID] = $.get("res/" + threadID, (function() {
return expandThread.cb.load(this, thread, a); return expandThread.parse(this, thread, a);
})); }));
} }
break; break;
@ -580,15 +570,20 @@
return _results; return _results;
} }
}, },
expand: function(html, thread, a) { parse: function(req, thread, a) {
var body, br, next, table, tables, _i, _len, _results; var body, br, next, table, tables, _i, _len, _results;
if (req.status !== 200) {
a.textContent = "" + req.status + " " + req.statusText;
$.unbind(a, 'click', expandThread.cb.toggle);
return;
}
a.textContent = a.textContent.replace('X Loading...', '-'); a.textContent = a.textContent.replace('X Loading...', '-');
while ((next = a.nextSibling) && !next.clear) { while ((next = a.nextSibling) && !next.clear) {
$.rm(next); $.rm(next);
} }
br = next; br = next;
body = $.el('body', { body = $.el('body', {
innerHTML: html innerHTML: req.responseText
}); });
tables = $$('form[name=delform] table', body); tables = $$('form[name=delform] table', body);
tables.pop(); tables.pop();

View File

@ -373,28 +373,18 @@ expandThread =
thread = @parentNode thread = @parentNode
expandThread.toggle thread expandThread.toggle thread
load: (xhr, thread, a) ->
if xhr.status is 404
a.textContent.replace 'X Loading...', '404'
$.unbind a, 'click', expandThread.cb.toggle
else
html = xhr.responseText
id = thread.firstChild.id
g.cache[id] = html
expandThread.expand html, thread, a
toggle: (thread) -> toggle: (thread) ->
id = thread.firstChild.id threadID = thread.firstChild.id
a = $ 'a.omittedposts', thread a = $ 'a.omittedposts', thread
switch a.textContent[0] switch a.textContent[0]
when '+' when '+'
a.textContent = a.textContent.replace '+', 'X Loading...' a.textContent = a.textContent.replace '+', 'X Loading...'
if html = g.cache[id] if req = g.requests[threadID]
expandThread.expand html, thread, a if req.readyState is 4
expandThread.parse req, thread, a
else else
g.requests[id] = g.requests[threadID] = $.get "res/#{threadID}", (-> expandThread.parse this, thread, a)
$.get "res/#{id}", (-> expandThread.cb.load this, thread, a)
when 'X' when 'X'
a.textContent = a.textContent.replace 'X Loading...', '+' a.textContent = a.textContent.replace 'X Loading...', '+'
@ -408,7 +398,12 @@ expandThread =
while (prev = table.previousSibling) and (prev.nodeName is 'TABLE') while (prev = table.previousSibling) and (prev.nodeName is 'TABLE')
$.rm prev $.rm prev
expand: (html, thread, a) -> parse: (req, thread, a) ->
if req.status isnt 200
a.textContent = "#{req.status} #{req.statusText}"
$.unbind a, 'click', expandThread.cb.toggle
return
a.textContent = a.textContent.replace 'X Loading...', '-' a.textContent = a.textContent.replace 'X Loading...', '-'
# eat everything, then replace with fresh full posts # eat everything, then replace with fresh full posts
@ -417,7 +412,7 @@ expandThread =
br = next br = next
body = $.el 'body', body = $.el 'body',
innerHTML: html innerHTML: req.responseText
tables = $$ 'form[name=delform] table', body tables = $$ 'form[name=delform] table', body
tables.pop() tables.pop()