From a7ced33a13e88481d86e646278be0536a834ded3 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Tue, 21 Jul 2015 01:10:09 +0200 Subject: make clock global 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 @@ 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); +} -- cgit v0.10.2