Widget:Timer: Difference between revisions
Jump to navigation
Jump to search
Matt Pijoan (talk | contribs) No edit summary |
Matt Pijoan (talk | contribs) No edit summary |
||
(55 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<includeonly> | <includeonly> | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
var countdownTimer, countdownCurrent = 30000; | |||
$.getScript("http://wikidoc.org/includes/jquery.timer.js", function (){ | $.getScript("http://wikidoc.org/includes/jquery.timer.js", function (){ | ||
$(document).ready(function(){ | |||
countdownTimer = $.timer(function() { | |||
var min = parseInt(countdownCurrent/6000); | |||
var sec = parseInt(countdownCurrent/100)-(min*60); | |||
var micro = pad(countdownCurrent-(sec*100)-(min*6000),2); | |||
var output = "00"; if(min > 0) {output = pad(min,2);} | |||
$('.countdowntime').html(output+":"+pad(sec,2)); | |||
if(countdownCurrent == 0) { | |||
countdownTimer.stop(); | |||
alert('Example 2: Countdown timer complete!'); | |||
countdownReset(); | |||
} else { | |||
countdownCurrent-=7; | |||
if(countdownCurrent < 0) {countdownCurrent=0;} | |||
} | |||
}, 70, true); | |||
}); | |||
$('#Go').click(function() { | |||
countdownTimer.toggle(); | |||
}); | |||
function pad(number, length) { | |||
var str = '' + number; | |||
while (str.length < length) {str = '0' + str;} | |||
return str; | |||
} | |||
}); | }); | ||
</script> | </script> | ||
<span class='countdowntime'></span> | |||
<select id='duration'> | |||
<option value='20'>20</option> | |||
<option value='30'>30</option> | |||
<option value='40'>40</option> | |||
</select> | |||
<input type='button' id='Go' value='Run' /> | |||
</includeonly> | </includeonly> |