This should fix the updater.

This commit is contained in:
Nicolas Stepien 2012-05-01 19:16:21 +02:00
parent 7f6782778f
commit ce1086ac60
2 changed files with 31 additions and 29 deletions

View File

@ -2455,7 +2455,7 @@
dialog = UI.dialog('updater', 'bottom: 0; right: 0;', html); dialog = UI.dialog('updater', 'bottom: 0; right: 0;', html);
this.count = $('#count', dialog); this.count = $('#count', dialog);
this.timer = $('#timer', dialog); this.timer = $('#timer', dialog);
this.br = $('br[clear]'); this.thread = $('.thread');
_ref = $$('input', dialog); _ref = $$('input', dialog);
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
input = _ref[_i]; input = _ref[_i];
@ -2514,7 +2514,7 @@
}; };
}, },
update: function() { update: function() {
var doc, id, newPosts, nodes, reply, scroll, _i, _len, _ref; var count, doc, id, lastPost, nodes, reply, scroll, _i, _len, _ref;
if (this.status === 404) { if (this.status === 404) {
Updater.timer.textContent = ''; Updater.timer.textContent = '';
Updater.count.textContent = 404; Updater.count.textContent = 404;
@ -2531,7 +2531,7 @@
return; return;
} }
Updater.retryCoef = 10; Updater.retryCoef = 10;
Updater.timer.textContent = '-' + Conf['Interval']; Updater.timer.textContent = "-" + Conf['Interval'];
/* /*
Status Code 304: Not modified Status Code 304: Not modified
By sending the `If-Modified-Since` header we get a proper status code, and no response. By sending the `If-Modified-Since` header we get a proper status code, and no response.
@ -2549,25 +2549,26 @@
Updater.lastModified = this.getResponseHeader('Last-Modified'); Updater.lastModified = this.getResponseHeader('Last-Modified');
doc = d.implementation.createHTMLDocument(''); doc = d.implementation.createHTMLDocument('');
doc.documentElement.innerHTML = this.response; doc.documentElement.innerHTML = this.response;
id = $('input', Updater.br.previousElementSibling).name; lastPost = Updater.thread.lastElementChild;
id = lastPost.id.slice(2);
nodes = []; nodes = [];
_ref = $$('.reply', doc).reverse(); _ref = $$('.replyContainer', doc).reverse();
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
reply = _ref[_i]; reply = _ref[_i];
if (reply.id <= id) { if (reply.id.slice(2) <= id) {
break; break;
} }
nodes.push(reply.parentNode.parentNode.parentNode); nodes.push(reply);
} }
newPosts = nodes.length; count = nodes.length;
scroll = Conf['Scrolling'] && Updater.scrollBG() && newPosts && Updater.br.previousElementSibling.getBoundingClientRect().bottom - d.body.clientHeight < 25; scroll = Conf['Scrolling'] && Updater.scrollBG() && count && lastPost.getBoundingClientRect().bottom - d.body.clientHeight < 25;
if (Conf['Verbose']) { if (Conf['Verbose']) {
Updater.count.textContent = "+" + newPosts; Updater.count.textContent = "+" + count;
Updater.count.className = newPosts ? 'new' : null; Updater.count.className = count ? 'new' : null;
} }
$.before(Updater.br, nodes.reverse()); $.add(Updater.thread, nodes.reverse());
if (scroll) { if (scroll) {
return Updater.br.previousSibling.scrollIntoView(); return nodes[0].scrollIntoView();
} }
} }
}, },

View File

@ -1944,9 +1944,9 @@ Updater =
dialog = UI.dialog 'updater', 'bottom: 0; right: 0;', html dialog = UI.dialog 'updater', 'bottom: 0; right: 0;', html
@count = $ '#count', dialog @count = $ '#count', dialog
@timer = $ '#timer', dialog @timer = $ '#timer', dialog
@br = $ 'br[clear]' @thread = $ '.thread'
for input in $$ 'input', dialog for input in $$ 'input', dialog
if input.type is 'checkbox' if input.type is 'checkbox'
@ -2010,7 +2010,7 @@ Updater =
return return
Updater.retryCoef = 10 Updater.retryCoef = 10
Updater.timer.textContent = '-' + Conf['Interval'] Updater.timer.textContent = "-#{Conf['Interval']}"
### ###
Status Code 304: Not modified Status Code 304: Not modified
@ -2021,29 +2021,30 @@ Updater =
if @status is 304 if @status is 304
if Conf['Verbose'] if Conf['Verbose']
Updater.count.textContent = '+0' Updater.count.textContent = '+0'
Updater.count.className = null Updater.count.className = null
return return
Updater.lastModified = @getResponseHeader 'Last-Modified' Updater.lastModified = @getResponseHeader 'Last-Modified'
doc = d.implementation.createHTMLDocument '' doc = d.implementation.createHTMLDocument ''
doc.documentElement.innerHTML = @response doc.documentElement.innerHTML = @response
id = $('input', Updater.br.previousElementSibling).name lastPost = Updater.thread.lastElementChild
id = lastPost.id[2..]
nodes = [] nodes = []
for reply in $$('.reply', doc).reverse() for reply in $$('.replyContainer', doc).reverse()
break if reply.id <= id #make sure to not insert older posts break if reply.id[2..] <= id #make sure to not insert older posts
nodes.push reply.parentNode.parentNode.parentNode #table nodes.push reply
newPosts = nodes.length count = nodes.length
scroll = Conf['Scrolling'] && Updater.scrollBG() && newPosts && scroll = Conf['Scrolling'] && Updater.scrollBG() && count &&
Updater.br.previousElementSibling.getBoundingClientRect().bottom - d.body.clientHeight < 25 lastPost.getBoundingClientRect().bottom - d.body.clientHeight < 25
if Conf['Verbose'] if Conf['Verbose']
Updater.count.textContent = "+#{newPosts}" Updater.count.textContent = "+#{count}"
Updater.count.className = if newPosts then 'new' else null Updater.count.className = if count then 'new' else null
$.before Updater.br, nodes.reverse() $.add Updater.thread, nodes.reverse()
if scroll if scroll
Updater.br.previousSibling.scrollIntoView() nodes[0].scrollIntoView()
timeout: -> timeout: ->
Updater.timeoutID = setTimeout Updater.timeout, 1000 Updater.timeoutID = setTimeout Updater.timeout, 1000