Cache updater's interval, for integers.

This commit is contained in:
Nicolas Stepien 2011-07-22 02:53:19 +02:00
parent eb09c5f057
commit 8357c51c3b
2 changed files with 24 additions and 17 deletions

View File

@ -1561,9 +1561,9 @@
}; };
updater = { updater = {
init: function() { init: function() {
var autoUpT, checked, conf, dialog, html, input, interva, interval, name, title, updNow, verbose, _i, _len, _ref; var autoUpT, checked, conf, dialog, html, input, interva, name, title, updNow, verbose, _i, _len, _ref;
interval = $.config('Interval'); updater.interval = $.config('Interval');
html = "<div class=move><span id=count></span> <span id=timer>-" + interval + "</span></div>"; html = "<div class=move><span id=count></span> <span id=timer>-" + updater.interval + "</span></div>";
conf = config.updater.checkbox; conf = config.updater.checkbox;
for (name in conf) { for (name in conf) {
title = conf[name][1]; title = conf[name][1];
@ -1571,7 +1571,7 @@
html += "<div><label title='" + title + "'>" + name + "<input name='" + name + "' type=checkbox " + checked + "></label></div>"; html += "<div><label title='" + title + "'>" + name + "<input name='" + name + "' type=checkbox " + checked + "></label></div>";
} }
checked = $.config('Auto Update') ? 'checked' : ''; checked = $.config('Auto Update') ? 'checked' : '';
html += " <div><label title='Controls whether *this* thread auotmatically updates or not'>Auto Update This<input name='Auto Update This' type=checkbox " + checked + "></label></div> <div><label>Interval (s)<input name=Interval value=" + interval + " type=text></label></div> <div><input value='Update Now' type=button></div>"; html += " <div><label title='Controls whether *this* thread auotmatically updates or not'>Auto Update This<input name='Auto Update This' type=checkbox " + checked + "></label></div> <div><label>Interval (s)<input name=Interval value=" + updater.interval + " type=text></label></div> <div><input value='Update Now' type=button></div>";
dialog = ui.dialog('updater', { dialog = ui.dialog('updater', {
bottom: '0', bottom: '0',
right: '0' right: '0'
@ -1587,7 +1587,7 @@
updNow = $('input[type=button]', dialog); updNow = $('input[type=button]', dialog);
$.bind(verbose, 'click', updater.cb.verbose); $.bind(verbose, 'click', updater.cb.verbose);
$.bind(autoUpT, 'click', updater.cb.autoUpdate); $.bind(autoUpT, 'click', updater.cb.autoUpdate);
$.bind(interva, 'change', $.cb.value); $.bind(interva, 'change', updater.cb.interval);
$.bind(updNow, 'click', updater.updateNow); $.bind(updNow, 'click', updater.updateNow);
updater.count = $('#count', dialog); updater.count = $('#count', dialog);
updater.timer = $('#timer', dialog); updater.timer = $('#timer', dialog);
@ -1596,7 +1596,7 @@
return updater.cb.autoUpdate.call(autoUpT); return updater.cb.autoUpdate.call(autoUpT);
}, },
cb: { cb: {
verbose: function(e) { verbose: function() {
if (this.checked) { if (this.checked) {
updater.count.textContent = '+0'; updater.count.textContent = '+0';
return $.show(updater.timer); return $.show(updater.timer);
@ -1608,14 +1608,18 @@
return $.hide(updater.timer); return $.hide(updater.timer);
} }
}, },
autoUpdate: function(e) { autoUpdate: function() {
if (this.checked) { if (this.checked) {
return updater.intervalID = window.setInterval(updater.timeout, 1000); return updater.intervalID = window.setInterval(updater.timeout, 1000);
} else { } else {
return window.clearInterval(updater.intervalID); return window.clearInterval(updater.intervalID);
} }
}, },
update: function(e) { interval: function() {
updater.interval = this.value = this.value.match(/\d+/)[0];
return $.cb.value.call(this);
},
update: function() {
var arr, body, br, id, input, replies, reply, _i, _len, _ref, _ref2; var arr, body, br, id, input, replies, reply, _i, _len, _ref, _ref2;
if (this.status === 404) { if (this.status === 404) {
updater.timer.textContent = ''; updater.timer.textContent = '';
@ -1643,7 +1647,7 @@
while ((reply = replies.pop()) && (reply.id > id)) { while ((reply = replies.pop()) && (reply.id > id)) {
arr.push(reply.parentNode.parentNode.parentNode); arr.push(reply.parentNode.parentNode.parentNode);
} }
updater.timer.textContent = '-' + $.config('Interval'); updater.timer.textContent = '-' + updater.interval;
if ($.config('Verbose')) { if ($.config('Verbose')) {
updater.count.textContent = '+' + arr.length; updater.count.textContent = '+' + arr.length;
if (arr.length === 0) { if (arr.length === 0) {

View File

@ -1266,8 +1266,8 @@ threadHiding =
updater = updater =
init: -> init: ->
interval = $.config 'Interval' updater.interval = $.config 'Interval'
html = "<div class=move><span id=count></span> <span id=timer>-#{interval}</span></div>" html = "<div class=move><span id=count></span> <span id=timer>-#{updater.interval}</span></div>"
conf = config.updater.checkbox conf = config.updater.checkbox
for name of conf for name of conf
title = conf[name][1] title = conf[name][1]
@ -1277,7 +1277,7 @@ updater =
checked = if $.config 'Auto Update' then 'checked' else '' checked = if $.config 'Auto Update' then 'checked' else ''
html += " html += "
<div><label title='Controls whether *this* thread auotmatically updates or not'>Auto Update This<input name='Auto Update This' type=checkbox #{checked}></label></div> <div><label title='Controls whether *this* thread auotmatically updates or not'>Auto Update This<input name='Auto Update This' type=checkbox #{checked}></label></div>
<div><label>Interval (s)<input name=Interval value=#{interval} type=text></label></div> <div><label>Interval (s)<input name=Interval value=#{updater.interval} type=text></label></div>
<div><input value='Update Now' type=button></div>" <div><input value='Update Now' type=button></div>"
dialog = ui.dialog 'updater', bottom: '0', right: '0', html dialog = ui.dialog 'updater', bottom: '0', right: '0', html
@ -1291,7 +1291,7 @@ updater =
updNow = $ 'input[type=button]', dialog updNow = $ 'input[type=button]', dialog
$.bind verbose, 'click', updater.cb.verbose $.bind verbose, 'click', updater.cb.verbose
$.bind autoUpT, 'click', updater.cb.autoUpdate $.bind autoUpT, 'click', updater.cb.autoUpdate
$.bind interva, 'change', $.cb.value $.bind interva, 'change', updater.cb.interval
$.bind updNow, 'click', updater.updateNow $.bind updNow, 'click', updater.updateNow
updater.count = $ '#count', dialog updater.count = $ '#count', dialog
@ -1303,7 +1303,7 @@ updater =
updater.cb.autoUpdate.call autoUpT updater.cb.autoUpdate.call autoUpT
cb: cb:
verbose: (e) -> verbose: ->
if @checked if @checked
updater.count.textContent = '+0' updater.count.textContent = '+0'
$.show updater.timer $.show updater.timer
@ -1312,12 +1312,15 @@ updater =
className: '' className: ''
textContent: 'Thread Updater' textContent: 'Thread Updater'
$.hide updater.timer $.hide updater.timer
autoUpdate: (e) -> autoUpdate: ->
if @checked if @checked
updater.intervalID = window.setInterval updater.timeout, 1000 updater.intervalID = window.setInterval updater.timeout, 1000
else else
window.clearInterval updater.intervalID window.clearInterval updater.intervalID
update: (e) -> interval: ->
updater.interval = @value = @value.match(/\d+/)[0]
$.cb.value.call @
update: ->
if @status is 404 if @status is 404
updater.timer.textContent = '' updater.timer.textContent = ''
updater.count.textContent = 404 updater.count.textContent = 404
@ -1341,7 +1344,7 @@ updater =
while (reply = replies.pop()) and (reply.id > id) while (reply = replies.pop()) and (reply.id > id)
arr.push reply.parentNode.parentNode.parentNode #table arr.push reply.parentNode.parentNode.parentNode #table
updater.timer.textContent = '-' + $.config 'Interval' updater.timer.textContent = '-' + updater.interval
if $.config 'Verbose' if $.config 'Verbose'
updater.count.textContent = '+' + arr.length updater.count.textContent = '+' + arr.length
if arr.length is 0 if arr.length is 0