Permalink
Browse files

when the timeout is '1 minute', then calculate the setTimeout delay t…

…o be the number of seconds to the next minute
  • Loading branch information...
1 parent 76bb97f commit 563feec155b36e1519c87e126d873f570fe932d6 @julienw julienw committed Nov 22, 2011
Showing with 24 additions and 2 deletions.
  1. +12 −1 examples/jquery.jclock.js
  2. +12 −1 jquery.jclock.js
View
@@ -106,12 +106,23 @@
el.running = false;
}
+ /* if the frequency is "once every minute" then we have to make sure this happens
+ * when the minute changes. */
+ // got this idea from digiclock http://www.radoslavdimov.com/jquery-plugins/jquery-plugin-digiclock/
+ function getDelay(timeout) {
+ if (timeout == 60000) {
+ var now = new Date();
+ timeout = 60000 - now.getSeconds() * 1000; // number of seconds before the next minute
+ }
+ return timeout;
+ }
+
$.fn.jclock.displayTime = function(el) {
var time = $.fn.jclock.currentTime(el);
var formatted_time = $.fn.jclock.formatTime(time, el);
el.attr('currentTime', time.getTime())
el.html(formatted_time);
- el.timerID = setTimeout(function(){$.fn.jclock.displayTime(el)},el.timeout);
+ el.timerID = setTimeout(function(){$.fn.jclock.displayTime(el)}, getDelay(el.timeout));
}
$.fn.jclock.currentTime = function(el) {
View
@@ -106,12 +106,23 @@
el.running = false;
}
+ /* if the frequency is "once every minute" then we have to make sure this happens
+ * when the minute changes. */
+ // got this idea from digiclock http://www.radoslavdimov.com/jquery-plugins/jquery-plugin-digiclock/
+ function getDelay(timeout) {
+ if (timeout == 60000) {
+ var now = new Date();
+ timeout = 60000 - now.getSeconds() * 1000; // number of seconds before the next minute
+ }
+ return timeout;
+ }
+
$.fn.jclock.displayTime = function(el) {
var time = $.fn.jclock.currentTime(el);
var formatted_time = $.fn.jclock.formatTime(time, el);
el.attr('currentTime', time.getTime())
el.html(formatted_time);
- el.timerID = setTimeout(function(){$.fn.jclock.displayTime(el)},el.timeout);
+ el.timerID = setTimeout(function(){$.fn.jclock.displayTime(el)}, getDelay(el.timeout));
}
$.fn.jclock.currentTime = function(el) {

0 comments on commit 563feec

Please sign in to comment.