diff options
author | Christian Pointner <equinox@helsinki.at> | 2015-07-20 23:10:09 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2015-07-20 23:10:09 (GMT) |
commit | a7ced33a13e88481d86e646278be0536a834ded3 (patch) | |
tree | 7cd4f5dda3cd550f98908ebc965a476ab43b54c0 /www | |
parent | 03e5e48d82b98f2a15dfa4515a87e405603926ae (diff) |
make clock global
Diffstat (limited to 'www')
-rw-r--r-- | www/index.html | 1 | ||||
-rw-r--r-- | www/js/shows.js | 5 | ||||
-rw-r--r-- | www/js/utils.js | 20 |
3 files changed, 19 insertions, 7 deletions
diff --git a/www/index.html b/www/index.html index e0a4338..8544b28 100644 --- a/www/index.html +++ b/www/index.html @@ -184,6 +184,7 @@ <script type="text/javascript"> auth_init(); apps_init(); + clock_init(); </script> </body> diff --git a/www/js/shows.js b/www/js/shows.js index eddb80f..13bc9be 100644 --- a/www/js/shows.js +++ b/www/js/shows.js @@ -349,15 +349,12 @@ function shows_init() { data = { LOGIN_NAME: auth_username, PASSWORD: auth_token }; $.post("/rh-bin/listdropboxes.cgi", data, shows_updateList, "xml") shows_drawClock('Do, 1.1.1970', '00:00:00', 0); - shows_clock = new Clock(shows_drawClock); - shows_clock.start(); + clock_add_callback(shows_drawClock); } function shows_cleanup() { sessionStorage.removeItem("shows_currentid"); delete shows_currentid; - shows_clock.stop(); - delete shows_clock; shows_list = []; shows_group_carts = {}; shows_log_carts = []; 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); +} |