Better watch icon update. Ready for automatic refresh?

This commit is contained in:
Nicolas Stepien 2011-05-05 16:44:00 +02:00
parent 1a5b1e1e0d
commit f8fe6bd137
2 changed files with 35 additions and 64 deletions

View File

@ -1464,54 +1464,46 @@
};
watcher = {
init: function() {
var dialog, favicon, html, id, input, inputs, src, watched, watchedBoard, _i, _len, _results;
var dialog, favicon, html, input, inputs, watched, _i, _len;
html = '<div class=move>Thread Watcher</div>';
dialog = ui.dialog('watcher', {
top: '50px',
left: '0px'
}, html);
$.append(d.body, dialog);
watched = $.getValue('watched', {});
watcher.refresh(watched);
watchedBoard = watched[g.BOARD] || {};
inputs = $$('form > input[value=delete], div.thread > input[value=delete]');
_results = [];
for (_i = 0, _len = inputs.length; _i < _len; _i++) {
input = inputs[_i];
id = input.name;
if (id in watchedBoard) {
src = Favicon["default"];
} else {
src = Favicon.empty;
}
favicon = $.el('img', {
src: src,
className: 'favicon'
});
$.bind(favicon, 'click', watcher.cb.toggle);
_results.push($.before(input, favicon));
$.before(input, favicon);
}
return _results;
watched = $.getValue('watched', {});
return watcher.refresh(watched);
},
refresh: function(watched) {
var board, div, id, props, _i, _len, _ref, _results;
var board, div, favicon, id, props, watchedBoard, _i, _j, _len, _len2, _ref, _ref2, _ref3, _results;
_ref = $$('#watcher > div:not(.move)');
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
div = _ref[_i];
$.remove(div);
}
_results = [];
for (board in watched) {
_results.push((function() {
var _ref2, _results2;
_ref2 = watched[board];
_results2 = [];
for (id in _ref2) {
props = _ref2[id];
_results2.push(watcher.addLink(props, $('#watcher')));
}
return _results2;
})());
_ref2 = watched[board];
for (id in _ref2) {
props = _ref2[id];
watcher.addLink(props, $('#watcher'));
}
}
watchedBoard = watched[g.BOARD] || {};
_ref3 = $$('img.favicon');
_results = [];
for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) {
favicon = _ref3[_j];
id = favicon.nextSibling.name;
_results.push(id in watchedBoard ? favicon.src = Favicon["default"] : favicon.src = Favicon.empty);
}
return _results;
},
@ -1541,30 +1533,20 @@
favicon = $('img.favicon', thread);
id = favicon.nextSibling.name;
if (favicon.src === Favicon.empty) {
return watcher.watch(thread);
return watcher.watch(thread, id);
} else {
return watcher.unwatch(g.BOARD, id);
}
},
unwatch: function(board, id) {
var favicon, input, watched;
if (input = $("input[name=\"" + id + "\"]")) {
favicon = input.previousSibling;
favicon.src = Favicon.empty;
}
var watched;
watched = $.getValue('watched', {});
delete watched[board][id];
$.setValue('watched', watched);
return watcher.refresh(watched);
},
watch: function(thread) {
var favicon, id, props, tc, watched, _name;
favicon = $('img.favicon', thread);
if (favicon.src === Favicon["default"]) {
return;
}
favicon.src = Favicon["default"];
id = favicon.nextSibling.name;
watch: function(thread, id) {
var props, tc, watched, _name;
tc = $('span.filetitle', thread).textContent || $('blockquote', thread).textContent;
props = {
textContent: "/" + g.BOARD + "/ - " + tc.slice(0, 25),

View File

@ -1167,31 +1167,31 @@ watcher =
dialog = ui.dialog 'watcher', top: '50px', left: '0px', html
$.append d.body, dialog
#populate watcher
watched = $.getValue 'watched', {}
watcher.refresh watched
#add watch buttons
watchedBoard = watched[g.BOARD] or {}
inputs = $$ 'form > input[value=delete], div.thread > input[value=delete]'
for input in inputs
id = input.name
if id of watchedBoard
src = Favicon.default
else
src = Favicon.empty
favicon = $.el 'img',
src: src
className: 'favicon'
$.bind favicon, 'click', watcher.cb.toggle
$.before input, favicon
#populate watcher, display watch buttons
watched = $.getValue 'watched', {}
watcher.refresh watched
refresh: (watched) ->
for div in $$ '#watcher > div:not(.move)'
$.remove div
for board of watched
for id, props of watched[board]
watcher.addLink props, $ '#watcher'
watchedBoard = watched[g.BOARD] or {}
for favicon in $$ 'img.favicon'
id = favicon.nextSibling.name
if id of watchedBoard
favicon.src = Favicon.default
else
favicon.src = Favicon.empty
addLink: (props, dialog) ->
div = $.el 'div'
@ -1215,29 +1215,18 @@ watcher =
favicon = $ 'img.favicon', thread
id = favicon.nextSibling.name
if favicon.src == Favicon.empty
watcher.watch thread
watcher.watch thread, id
else # favicon.src == Favicon.default
watcher.unwatch g.BOARD, id
unwatch: (board, id) ->
if input = $ "input[name=\"#{id}\"]"
favicon = input.previousSibling
favicon.src = Favicon.empty
watched = $.getValue 'watched', {}
delete watched[board][id]
$.setValue 'watched', watched
watcher.refresh watched
watch: (thread) ->
favicon = $ 'img.favicon', thread
#this happens if we try to auto-watch an already watched thread.
return if favicon.src is Favicon.default
favicon.src = Favicon.default
id = favicon.nextSibling.name
watch: (thread, id) ->
tc = $('span.filetitle', thread).textContent or $('blockquote', thread).textContent
props =
textContent: "/#{g.BOARD}/ - #{tc[...25]}"