24 timer_widget :
function( Element , Options )
26 this._element = Element;
27 this.timeout = Options.timeout;
28 this.timeout_callback = Options.timeout_callback;
35 ultimix.timer_widget.prototype._prepending_zero =
function( Value )
39 return(
'0' + Value );
47 ultimix.timer_widget.prototype.init =
function()
50 this.set_timer( this.timeout );
51 this.timeout_callback_was_launched =
false;
53 this.start_time = Math.floor( (
new Date() ).getTime() / 1000 );
54 window.setInterval(
function(){ obj.on_tick( obj ) } , 1000 );
57 ultimix.timer_widget.prototype.set_timer =
function( Time )
59 Hours = Math.floor( Time / ( 60 * 60 ) );
60 Minutes = Math.floor( Time / 60 - Hours * 60 );
61 Seconds = Math.floor( Time - Hours * 60 * 60 - Minutes * 60 );
62 jQuery( this._element ).empty();
63 jQuery( this._element ).append(
64 '<span class="hours">' + this._prepending_zero( Hours ) +
'</span>:<span class="minutes">' +
65 this._prepending_zero( Minutes ) +
'</span>:<span class="seconds">' + this._prepending_zero( Seconds ) +
70 ultimix.timer_widget.prototype.on_tick =
function( obj )
72 Diff = Math.floor( (
new Date() ).getTime() / 1000 ) - obj.start_time;
73 if( obj.timeout - Diff > 0 )
75 obj.set_timer( obj.timeout - Diff );
80 if( obj.timeout_callback_was_launched ==
false )
82 if( obj.timeout_callback )
84 obj.timeout_callback();
86 obj.timeout_callback_was_launched =
true;
91 jQuery.fn.timer_widget =
function( Options )
96 timeout_callback :
false