expandComment: g.cache -> g.requests

This commit is contained in:
James Campos 2011-05-14 09:57:22 -07:00
parent 2101e7cdf0
commit 4ce920bff1
2 changed files with 37 additions and 26 deletions

View File

@ -472,27 +472,34 @@
_results = []; _results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
a = _ref[_i]; a = _ref[_i];
_results.push($.bind(a, 'click', expandComment.cb.expand)); _results.push($.bind(a, 'click', expandComment.expand));
} }
return _results; return _results;
}, },
cb: { expand: function(e) {
expand: function(e) { var a, replyID, req, threadID, _, _ref;
var a, href, replyID, threadID, _, _ref; e.preventDefault();
e.preventDefault(); _ref = this.href.match(/(\d+)#(\d+)/), _ = _ref[0], threadID = _ref[1], replyID = _ref[2];
this.textContent = "Loading " + replyID + "...";
if (req = g.requests[threadID]) {
if (req.readyState === 4) {
return expandComment.parse(req, this, threadID, replyID);
}
} else {
a = this; a = this;
a.textContent = 'Loading...'; return g.requests[threadID] = $.get(this.href, (function() {
href = a.getAttribute('href'); return expandComment.parse(this, a, threadID, replyID);
_ref = href.match(/(\d+)#(\d+)/), _ = _ref[0], threadID = _ref[1], replyID = _ref[2];
return g.cache[threadID] = $.get(href, (function() {
return expandComment.load(this, a, threadID, replyID);
})); }));
} }
}, },
load: function(xhr, a, threadID, replyID) { parse: function(req, a, threadID, replyID) {
var body, bq, reply, _i, _len, _ref; var body, bq, reply, _i, _len, _ref;
if (req.status !== 200) {
a.textContent = "" + req.status + " " + req.statusText;
return;
}
body = $.el('body', { body = $.el('body', {
innerHTML: xhr.responseText innerHTML: req.responseText
}); });
if (threadID === replyID) { if (threadID === replyID) {
bq = $('blockquote', body); bq = $('blockquote', body);

View File

@ -329,22 +329,26 @@ $$ = (selector, root=d.body) ->
expandComment = expandComment =
init: -> init: ->
for a in $$ 'span.abbr a' for a in $$ 'span.abbr a'
$.bind a, 'click', expandComment.cb.expand $.bind a, 'click', expandComment.expand
expand: (e) ->
cb: e.preventDefault()
expand: (e) -> [_, threadID, replyID] = @href.match /(\d+)#(\d+)/
e.preventDefault() @textContent = "Loading #{replyID}..."
if req = g.requests[threadID]
if req.readyState is 4
expandComment.parse req, this, threadID, replyID
else
a = this a = this
a.textContent = 'Loading...' g.requests[threadID] = $.get @href, (-> expandComment.parse this, a, threadID, replyID)
href = a.getAttribute 'href' parse: (req, a, threadID, replyID) ->
[_, threadID, replyID] = href.match /(\d+)#(\d+)/ if req.status isnt 200
g.cache[threadID] = $.get href, (-> a.textContent = "#{req.status} #{req.statusText}"
expandComment.load this, a, threadID, replyID) return
load: (xhr, a, threadID, replyID) ->
body = $.el 'body',
innerHTML: xhr.responseText
if threadID is replyID body = $.el 'body',
innerHTML: req.responseText
if threadID is replyID #OP
bq = $ 'blockquote', body bq = $ 'blockquote', body
else else
#css selectors don't like ids starting with numbers, #css selectors don't like ids starting with numbers,