diff options
Diffstat (limited to 'www/js/utils.js')
-rw-r--r-- | www/js/utils.js | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/www/js/utils.js b/www/js/utils.js index 3123c9c..eeebadd 100644 --- a/www/js/utils.js +++ b/www/js/utils.js @@ -96,8 +96,8 @@ function get_rd_week(msEpoch) { return week; } -function Clock(draw_callback) { - this.draw_callback = draw_callback; +function Clock() { + this.draw_callbacks = $.Callbacks('unique'); this.last_message = { t1: 0, t2: 0, t3: 0, t4: 0, tz_offset: 3600 }; this.clock_offset = 0; @@ -115,7 +115,11 @@ function Clock(draw_callback) { time_str += (rdtime.getUTCMinutes() > 9 ? ':' : ':0') + rdtime.getUTCMinutes(); time_str += (rdtime.getUTCSeconds() > 9 ? ':' : ':0') + rdtime.getUTCSeconds(); - this.draw_callback(date_str, time_str, get_rd_week(rdtime_ms)); + this.draw_callbacks.fireWith(window, [date_str, time_str, get_rd_week(rdtime_ms)]); + } + + this.addCallback = function(cb) { + this.draw_callbacks.add(cb); } this.ntp_update = function(event) { @@ -176,3 +180,13 @@ function Clock(draw_callback) { this.sock.close(); } } + +var clock = new Clock(); + +function clock_init() { + clock.start(); +} + +function clock_add_callback(cb) { + clock.addCallback(cb); +} |