/ Published in: JavaScript
URL: http://jsfromhell.com/classes/countdown
Supplies countdown with pause and events. Created: 2006.06.23
Expand |
Embed | Plain Text
/* ************************************** * CountDown Class v1.0 * * Autor: Carlos R. L. Rodrigues * ************************************** */ CountDown = function(){ this.date = !(this.finished = this.paused = false); } CountDown.prototype.start = function(n, e, t, r){ var o = this; r ? o.onResume && o.onResume(o.n) : (o.n = o.date ? new Date(n).getTime() : n, o.e = o.date ? new Date(e).getTime() : e, o.t = t, o.finished = false, o.onStart && o.onStart(o.n)); o.d = e < n ? 1 : -1, o.paused = false, o.i = setInterval(function(){ o.d * (o.n -= o.d * (o.date ? 1e3 : 1)) <= o.e * o.d && (o.finished = !o.stop()) && !clearInterval(o.i) || o.onUpdate && o.onUpdate(o.n); }, (o.t || 1) * 1e3); } CountDown.prototype.pause = function(t){ var o = this; clearTimeout(o.x), o.paused ? o.start(o.n, o.e, o.t, 1) : (o.paused = !clearInterval(o.i), o.onPause && o.onPause(o.n), t && (o.x = setTimeout(function(){ o.start(o.n, o.e, o.t, 1); }, t * 1e3))); } CountDown.prototype.stop = function(){ var o = this; clearInterval(o.i), clearTimeout(o.x), o.onStop && o.onStop(o.n), o.n = 0; }
You need to login to post a comment.
