expandComment: g.cache -> g.requests
This commit is contained in:
parent
2101e7cdf0
commit
4ce920bff1
31
4chan_x.js
31
4chan_x.js
@ -472,27 +472,34 @@
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
a = _ref[_i];
|
||||
_results.push($.bind(a, 'click', expandComment.cb.expand));
|
||||
_results.push($.bind(a, 'click', expandComment.expand));
|
||||
}
|
||||
return _results;
|
||||
},
|
||||
cb: {
|
||||
expand: function(e) {
|
||||
var a, href, replyID, threadID, _, _ref;
|
||||
e.preventDefault();
|
||||
expand: function(e) {
|
||||
var a, replyID, req, threadID, _, _ref;
|
||||
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.textContent = 'Loading...';
|
||||
href = a.getAttribute('href');
|
||||
_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);
|
||||
return g.requests[threadID] = $.get(this.href, (function() {
|
||||
return expandComment.parse(this, a, threadID, replyID);
|
||||
}));
|
||||
}
|
||||
},
|
||||
load: function(xhr, a, threadID, replyID) {
|
||||
parse: function(req, a, threadID, replyID) {
|
||||
var body, bq, reply, _i, _len, _ref;
|
||||
if (req.status !== 200) {
|
||||
a.textContent = "" + req.status + " " + req.statusText;
|
||||
return;
|
||||
}
|
||||
body = $.el('body', {
|
||||
innerHTML: xhr.responseText
|
||||
innerHTML: req.responseText
|
||||
});
|
||||
if (threadID === replyID) {
|
||||
bq = $('blockquote', body);
|
||||
|
||||
@ -329,22 +329,26 @@ $$ = (selector, root=d.body) ->
|
||||
expandComment =
|
||||
init: ->
|
||||
for a in $$ 'span.abbr a'
|
||||
$.bind a, 'click', expandComment.cb.expand
|
||||
|
||||
cb:
|
||||
expand: (e) ->
|
||||
e.preventDefault()
|
||||
$.bind a, 'click', expandComment.expand
|
||||
expand: (e) ->
|
||||
e.preventDefault()
|
||||
[_, threadID, replyID] = @href.match /(\d+)#(\d+)/
|
||||
@textContent = "Loading #{replyID}..."
|
||||
if req = g.requests[threadID]
|
||||
if req.readyState is 4
|
||||
expandComment.parse req, this, threadID, replyID
|
||||
else
|
||||
a = this
|
||||
a.textContent = 'Loading...'
|
||||
href = a.getAttribute 'href'
|
||||
[_, threadID, replyID] = href.match /(\d+)#(\d+)/
|
||||
g.cache[threadID] = $.get href, (->
|
||||
expandComment.load this, a, threadID, replyID)
|
||||
load: (xhr, a, threadID, replyID) ->
|
||||
body = $.el 'body',
|
||||
innerHTML: xhr.responseText
|
||||
g.requests[threadID] = $.get @href, (-> expandComment.parse this, a, threadID, replyID)
|
||||
parse: (req, a, threadID, replyID) ->
|
||||
if req.status isnt 200
|
||||
a.textContent = "#{req.status} #{req.statusText}"
|
||||
return
|
||||
|
||||
if threadID is replyID
|
||||
body = $.el 'body',
|
||||
innerHTML: req.responseText
|
||||
|
||||
if threadID is replyID #OP
|
||||
bq = $ 'blockquote', body
|
||||
else
|
||||
#css selectors don't like ids starting with numbers,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user