Fix longstanding bug where aborting a thread expension would just not work; fix abortion of cached

requests. Blame @aeosynth.
Also replace Xs with × while I'm at it.
This commit is contained in:
Nicolas Stepien 2012-03-05 20:54:29 +01:00
parent f1742941e6
commit 7f3620948e
2 changed files with 20 additions and 14 deletions

View File

@ -362,7 +362,7 @@
} }
} else { } else {
req = $.ajax(url, { req = $.ajax(url, {
onload: (function() { onload: function() {
var cb, _i, _len, _ref, _results; var cb, _i, _len, _ref, _results;
_ref = this.callbacks; _ref = this.callbacks;
_results = []; _results = [];
@ -371,7 +371,10 @@
_results.push(cb.call(this)); _results.push(cb.call(this));
} }
return _results; return _results;
}) },
onabort: function() {
return delete $.cache.requests[url];
}
}); });
req.callbacks = [cb]; req.callbacks = [cb];
return $.cache.requests[url] = req; return $.cache.requests[url] = req;
@ -811,13 +814,13 @@
switch (a.textContent[0]) { switch (a.textContent[0]) {
case '+': case '+':
if ((_ref = $('.op .container', thread)) != null) _ref.textContent = ''; if ((_ref = $('.op .container', thread)) != null) _ref.textContent = '';
a.textContent = a.textContent.replace('+', 'X Loading...'); a.textContent = a.textContent.replace('+', '\u00d7 Loading...');
return $.cache(pathname, (function() { return $.cache(pathname, (function() {
return expandThread.parse(this, pathname, thread, a); return expandThread.parse(this, pathname, thread, a);
})); }));
case 'X': case '\u00d7':
a.textContent = a.textContent.replace('X Loading...', '+'); a.textContent = a.textContent.replace('\u00d7 Loading...', '+');
return $.cache[pathname].abort(); return $.cache.requests[pathname].abort();
case '-': case '-':
a.textContent = a.textContent.replace('-', '+'); a.textContent = a.textContent.replace('-', '+');
num = (function() { num = (function() {
@ -855,7 +858,7 @@
$.off(a, 'click', expandThread.cb.toggle); $.off(a, 'click', expandThread.cb.toggle);
return; return;
} }
a.textContent = a.textContent.replace('X Loading...', '-'); a.textContent = a.textContent.replace('\u00d7 Loading...', '-');
body = $.el('body', { body = $.el('body', {
innerHTML: req.responseText innerHTML: req.responseText
}); });

View File

@ -297,7 +297,9 @@ $.extend $,
else else
req.callbacks.push cb req.callbacks.push cb
else else
req = $.ajax url, onload: (-> cb.call @ for cb in @callbacks) req = $.ajax url,
onload: -> cb.call @ for cb in @callbacks
onabort: -> delete $.cache.requests[url]
req.callbacks = [cb] req.callbacks = [cb]
$.cache.requests[url] = req $.cache.requests[url] = req
cb: cb:
@ -681,16 +683,17 @@ expandThread =
pathname = "/#{g.BOARD}/res/#{threadID}" pathname = "/#{g.BOARD}/res/#{threadID}"
a = $ '.omittedposts', thread a = $ '.omittedposts', thread
# \u00d7 is ×
switch a.textContent[0] switch a.textContent[0]
when '+' when '+'
$('.op .container', thread)?.textContent = '' $('.op .container', thread)?.textContent = ''
a.textContent = a.textContent.replace '+', 'X Loading...' a.textContent = a.textContent.replace '+', '\u00d7 Loading...'
$.cache pathname, (-> expandThread.parse @, pathname, thread, a) $.cache pathname, (-> expandThread.parse @, pathname, thread, a)
when 'X' when '\u00d7'
a.textContent = a.textContent.replace 'X Loading...', '+' a.textContent = a.textContent.replace '\u00d7 Loading...', '+'
#FIXME this will kill all callbacks $.cache.requests[pathname].abort()
$.cache[pathname].abort()
when '-' when '-'
a.textContent = a.textContent.replace '-', '+' a.textContent = a.textContent.replace '-', '+'
@ -712,7 +715,7 @@ expandThread =
$.off a, 'click', expandThread.cb.toggle $.off a, 'click', expandThread.cb.toggle
return return
a.textContent = a.textContent.replace 'X Loading...', '-' a.textContent = a.textContent.replace '\u00d7 Loading...', '-'
body = $.el 'body', body = $.el 'body',
innerHTML: req.responseText innerHTML: req.responseText