summaryrefslogtreecommitdiff
path: root/www/js/utils.js
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-07-20 23:10:09 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-07-20 23:10:09 (GMT)
commita7ced33a13e88481d86e646278be0536a834ded3 (patch)
tree7cd4f5dda3cd550f98908ebc965a476ab43b54c0 /www/js/utils.js
parent03e5e48d82b98f2a15dfa4515a87e405603926ae (diff)
make clock global
Diffstat (limited to 'www/js/utils.js')
-rw-r--r--www/js/utils.js20
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);
+}