Permalink
Browse files

Merge pull request #4 from julienw/synchronized-clock

Synchronized clock
  • Loading branch information...
dsparling committed Feb 7, 2012
2 parents 76bb97f + f3e20d7 commit 5017472099bb591ccef1a7c364c2113b7563fcfc
Showing with 49 additions and 2 deletions.
  1. +24 −0 examples/clock10.html
  2. +1 −0 examples/index.html
  3. +12 −1 examples/jquery.jclock.js
  4. +12 −1 jquery.jclock.js
View
@@ -0,0 +1,24 @@
+<html>
+<head>
+ <title>jclock - default 24-hour clock (localtime)</title>
+
+ <script type="text/javascript" src="jquery-1.3.1.min.js"></script>
+ <script type="text/javascript" src="jquery.jclock.js"></script>
+
+ <script type="text/javascript">
+ $(function($) {
+ $('.jclock').jclock({
+ timeout: 60000,
+ format: '%H:%M',
+ });
+ });
+ </script>
+
+</head>
+
+<body>
+
+<div class="jclock"></div>
+
+</body>
+</html>
View
@@ -15,6 +15,7 @@ <h2>jclock examples</h2>
<li><a href="clock7.html">multiple clocks using different time zone offsets</a></li>
<li><a href="clock8.html">styled clocks (first clock uses jquery.corner.js)</a></li>
<li><a href="clock9.html">clock using seedTime</a></li>
+<li><a href="clock10.html">clock with only minutes</a></li>
</ul>
</body>
<html>
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 5017472

Please sign in to comment.