Merge pull request #58 from MayhemYDG/master
Better watcher list update
This commit is contained in:
commit
1a5b1e1e0d
43
4chan_x.js
43
4chan_x.js
@ -1464,7 +1464,7 @@
|
|||||||
};
|
};
|
||||||
watcher = {
|
watcher = {
|
||||||
init: function() {
|
init: function() {
|
||||||
var board, dialog, favicon, html, id, input, inputs, props, src, watched, watchedBoard, _i, _len, _ref, _results;
|
var dialog, favicon, html, id, input, inputs, src, watched, watchedBoard, _i, _len, _results;
|
||||||
html = '<div class=move>Thread Watcher</div>';
|
html = '<div class=move>Thread Watcher</div>';
|
||||||
dialog = ui.dialog('watcher', {
|
dialog = ui.dialog('watcher', {
|
||||||
top: '50px',
|
top: '50px',
|
||||||
@ -1472,13 +1472,7 @@
|
|||||||
}, html);
|
}, html);
|
||||||
$.append(d.body, dialog);
|
$.append(d.body, dialog);
|
||||||
watched = $.getValue('watched', {});
|
watched = $.getValue('watched', {});
|
||||||
for (board in watched) {
|
watcher.refresh(watched);
|
||||||
_ref = watched[board];
|
|
||||||
for (id in _ref) {
|
|
||||||
props = _ref[id];
|
|
||||||
watcher.addLink(props, dialog);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
watchedBoard = watched[g.BOARD] || {};
|
watchedBoard = watched[g.BOARD] || {};
|
||||||
inputs = $$('form > input[value=delete], div.thread > input[value=delete]');
|
inputs = $$('form > input[value=delete], div.thread > input[value=delete]');
|
||||||
_results = [];
|
_results = [];
|
||||||
@ -1499,9 +1493,30 @@
|
|||||||
}
|
}
|
||||||
return _results;
|
return _results;
|
||||||
},
|
},
|
||||||
|
refresh: function(watched) {
|
||||||
|
var board, div, id, props, _i, _len, _ref, _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;
|
||||||
|
})());
|
||||||
|
}
|
||||||
|
return _results;
|
||||||
|
},
|
||||||
addLink: function(props, dialog) {
|
addLink: function(props, dialog) {
|
||||||
var div, link, x;
|
var div, link, x;
|
||||||
dialog || (dialog = $('#watcher'));
|
|
||||||
div = $.el('div');
|
div = $.el('div');
|
||||||
x = $.el('a', {
|
x = $.el('a', {
|
||||||
textContent: 'X'
|
textContent: 'X'
|
||||||
@ -1532,17 +1547,15 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
unwatch: function(board, id) {
|
unwatch: function(board, id) {
|
||||||
var div, favicon, href, input, watched;
|
var favicon, input, watched;
|
||||||
href = "/" + board + "/res/" + id;
|
|
||||||
div = $("#watcher a[href=\"" + href + "\"]").parentNode;
|
|
||||||
$.remove(div);
|
|
||||||
if (input = $("input[name=\"" + id + "\"]")) {
|
if (input = $("input[name=\"" + id + "\"]")) {
|
||||||
favicon = input.previousSibling;
|
favicon = input.previousSibling;
|
||||||
favicon.src = Favicon.empty;
|
favicon.src = Favicon.empty;
|
||||||
}
|
}
|
||||||
watched = $.getValue('watched', {});
|
watched = $.getValue('watched', {});
|
||||||
delete watched[board][id];
|
delete watched[board][id];
|
||||||
return $.setValue('watched', watched);
|
$.setValue('watched', watched);
|
||||||
|
return watcher.refresh(watched);
|
||||||
},
|
},
|
||||||
watch: function(thread) {
|
watch: function(thread) {
|
||||||
var favicon, id, props, tc, watched, _name;
|
var favicon, id, props, tc, watched, _name;
|
||||||
@ -1561,7 +1574,7 @@
|
|||||||
watched[_name = g.BOARD] || (watched[_name] = {});
|
watched[_name = g.BOARD] || (watched[_name] = {});
|
||||||
watched[g.BOARD][id] = props;
|
watched[g.BOARD][id] = props;
|
||||||
$.setValue('watched', watched);
|
$.setValue('watched', watched);
|
||||||
return watcher.addLink(props);
|
return watcher.refresh(watched);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
anonymize = {
|
anonymize = {
|
||||||
|
|||||||
@ -1169,9 +1169,7 @@ watcher =
|
|||||||
|
|
||||||
#populate watcher
|
#populate watcher
|
||||||
watched = $.getValue 'watched', {}
|
watched = $.getValue 'watched', {}
|
||||||
for board of watched
|
watcher.refresh watched
|
||||||
for id, props of watched[board]
|
|
||||||
watcher.addLink props, dialog
|
|
||||||
|
|
||||||
#add watch buttons
|
#add watch buttons
|
||||||
watchedBoard = watched[g.BOARD] or {}
|
watchedBoard = watched[g.BOARD] or {}
|
||||||
@ -1188,8 +1186,14 @@ watcher =
|
|||||||
$.bind favicon, 'click', watcher.cb.toggle
|
$.bind favicon, 'click', watcher.cb.toggle
|
||||||
$.before input, favicon
|
$.before input, favicon
|
||||||
|
|
||||||
|
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'
|
||||||
|
|
||||||
addLink: (props, dialog) ->
|
addLink: (props, dialog) ->
|
||||||
dialog or= $ '#watcher'
|
|
||||||
div = $.el 'div'
|
div = $.el 'div'
|
||||||
x = $.el 'a',
|
x = $.el 'a',
|
||||||
textContent: 'X'
|
textContent: 'X'
|
||||||
@ -1216,10 +1220,6 @@ watcher =
|
|||||||
watcher.unwatch g.BOARD, id
|
watcher.unwatch g.BOARD, id
|
||||||
|
|
||||||
unwatch: (board, id) ->
|
unwatch: (board, id) ->
|
||||||
href = "/#{board}/res/#{id}"
|
|
||||||
div = $("#watcher a[href=\"#{href}\"]").parentNode
|
|
||||||
$.remove div
|
|
||||||
|
|
||||||
if input = $ "input[name=\"#{id}\"]"
|
if input = $ "input[name=\"#{id}\"]"
|
||||||
favicon = input.previousSibling
|
favicon = input.previousSibling
|
||||||
favicon.src = Favicon.empty
|
favicon.src = Favicon.empty
|
||||||
@ -1228,6 +1228,8 @@ watcher =
|
|||||||
delete watched[board][id]
|
delete watched[board][id]
|
||||||
$.setValue 'watched', watched
|
$.setValue 'watched', watched
|
||||||
|
|
||||||
|
watcher.refresh watched
|
||||||
|
|
||||||
watch: (thread) ->
|
watch: (thread) ->
|
||||||
favicon = $ 'img.favicon', thread
|
favicon = $ 'img.favicon', thread
|
||||||
|
|
||||||
@ -1246,7 +1248,7 @@ watcher =
|
|||||||
watched[g.BOARD][id] = props
|
watched[g.BOARD][id] = props
|
||||||
$.setValue 'watched', watched
|
$.setValue 'watched', watched
|
||||||
|
|
||||||
watcher.addLink props
|
watcher.refresh watched
|
||||||
|
|
||||||
anonymize =
|
anonymize =
|
||||||
init: ->
|
init: ->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user