Skip to content

Commit

Permalink
adding auto-update
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbe committed Aug 11, 2012
1 parent feb51a2 commit b19de83
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions 2/static/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ function timeSince(date) {

var StatesForm = (function() {
var state;
var start_interval = interval = 60 * 1000;

function update_numbers() {
var c = $('form a.btn-success').size();
var uc = 50 - c;
Expand Down Expand Up @@ -141,8 +143,22 @@ var StatesForm = (function() {
State.add(id);
}
update_numbers();
interval = start_interval;
return false;
});
},
update_loop: function() {
State.load();
State.iterate(function(name, date) {
switch_on($('#' + name), date);
});
var oldest = State.oldest();
if (oldest) {
$('#times-ago').text(timeSince(oldest));
}
interval += 60 * 1000; // add 1 minute
interval = Math.min(interval, 60 * 60 * 1000);
setTimeout(StatesForm.update_loop, interval);
}

}
Expand Down Expand Up @@ -199,4 +215,5 @@ $(function() {
// Hide the address bar!
window.scrollTo(0, 1);
}, 0);
setTimeout(StatesForm.update_loop, 60 * 1000);
});

0 comments on commit b19de83

Please sign in to comment.