fix #8, finish unread count rewrite

This commit is contained in:
James Campos 2011-04-17 11:57:10 -07:00
parent 8e6d9484f2
commit b40b19d2b2
2 changed files with 29 additions and 14 deletions

View File

@ -62,7 +62,9 @@
var $, $$, NAMESPACE, anonymize, autoWatch, callback, config, d, el, expandComment, expandThread, g, imageClick, imageExpand, imageExpandClick, imageHover, imageResize, imageThumb, imageToggle, imageTypeChange, imgExpansion, imgGif, imgPreloading, keybinds, localize, log, nav, navtopr, nodeInserted, options, pathname, qr, quickReport, recaptcha, redirect, replyHiding, sauce, temp, threadHiding, titlePost, tzOffset, ui, unread, updater, watcher, _config, _i, _j, _len, _len2, _ref, _ref2, _ref3; var $, $$, NAMESPACE, anonymize, autoWatch, callback, config, d, el, expandComment, expandThread, g, imageClick, imageExpand, imageExpandClick, imageHover, imageResize, imageThumb, imageToggle, imageTypeChange, imgExpansion, imgGif, imgPreloading, keybinds, localize, log, nav, navtopr, nodeInserted, options, pathname, qr, quickReport, recaptcha, redirect, replyHiding, sauce, temp, threadHiding, titlePost, tzOffset, ui, unread, updater, watcher, _config, _i, _j, _len, _len2, _ref, _ref2, _ref3;
var __slice = Array.prototype.slice; var __slice = Array.prototype.slice;
if (typeof console != "undefined" && console !== null) { if (typeof console != "undefined" && console !== null) {
log = console.log; log = function(arg) {
return console.log(arg);
};
} }
config = { config = {
main: { main: {
@ -1760,6 +1762,7 @@
}; };
unread = { unread = {
init: function() { init: function() {
unread.replies = [];
d.title = '(0) ' + d.title; d.title = '(0) ' + d.title;
$.bind(window, 'scroll', unread.cb.scroll); $.bind(window, 'scroll', unread.cb.scroll);
return g.callbacks.push(unread.cb.node); return g.callbacks.push(unread.cb.node);
@ -1767,10 +1770,14 @@
cb: { cb: {
node: function(root) { node: function(root) {
unread.replies = unread.replies.concat($$('td[id]', root)); unread.replies = unread.replies.concat($$('td[id]', root));
return unread.updateTitle(); unread.updateTitle();
return unread.updateFavicon();
}, },
scroll: function(e) { scroll: function(e) {
var bottom, height, i, reply, _len, _ref; var bottom, height, i, reply, _len, _ref;
if (unread.replies.length === 0) {
return;
}
height = d.body.clientHeight; height = d.body.clientHeight;
_ref = unread.replies; _ref = unread.replies;
for (i = 0, _len = _ref.length; i < _len; i++) { for (i = 0, _len = _ref.length; i < _len; i++) {
@ -1784,14 +1791,14 @@
return; return;
} }
unread.replies = unread.replies.slice(i); unread.replies = unread.replies.slice(i);
return unread.updateTitle(); unread.updateTitle();
if (unread.replies.length === 0) {
return unread.updateFavicon();
}
} }
}, },
updateTitle: function() { updateTitle: function() {
var l; return d.title = d.title.replace(/\d+/, unread.replies.length);
l = unread.replies.length;
d.title = d.title.replace(/\d+/, l);
return updateFavicon();
}, },
updateFavicon: function() { updateFavicon: function() {
var clone, favicon, href, l; var clone, favicon, href, l;

View File

@ -4,8 +4,10 @@
# (floating) qr no-quote button? # (floating) qr no-quote button?
# updater cache hacks # updater cache hacks
# XXX error on FUCKING CHROME # XXX chrome can't into `{log} = console`
{log} = console if console? if console?
log = (arg) ->
console.log arg
# TODO reset defaults # TODO reset defaults
config = config =
@ -620,6 +622,7 @@ keybinds =
nav = nav =
#TODO page nav #TODO page nav
#FIXME /b/
# #
init: -> init: ->
span = $.el 'span', span = $.el 'span',
@ -1364,6 +1367,7 @@ quickReport =
unread = unread =
init: -> init: ->
unread.replies = []
d.title = '(0) ' + d.title d.title = '(0) ' + d.title
$.bind window, 'scroll', unread.cb.scroll $.bind window, 'scroll', unread.cb.scroll
g.callbacks.push unread.cb.node g.callbacks.push unread.cb.node
@ -1372,21 +1376,25 @@ unread =
node: (root) -> node: (root) ->
unread.replies = unread.replies.concat $$ 'td[id]', root unread.replies = unread.replies.concat $$ 'td[id]', root
unread.updateTitle() unread.updateTitle()
unread.updateFavicon()
scroll: (e) -> scroll: (e) ->
return if unread.replies.length is 0
height = d.body.clientHeight height = d.body.clientHeight
for reply, i in unread.replies for reply, i in unread.replies
bottom = reply.getBoundingClientRect().bottom {bottom} = reply.getBoundingClientRect()
if bottom > height #post is not completely read if bottom > height #post is not completely read
break break
if i is 0 then return return if i is 0
unread.replies = unread.replies[i..] unread.replies = unread.replies[i..]
unread.updateTitle() unread.updateTitle()
if unread.replies.length is 0
unread.updateFavicon()
updateTitle: -> updateTitle: ->
l = unread.replies.length d.title = d.title.replace /\d+/, unread.replies.length
d.title = d.title.replace /\d+/, l
updateFavicon()
updateFavicon: -> updateFavicon: ->
l = unread.replies.length l = unread.replies.length