Template:Kyoto/small countdown
From 2014.igem.org
(Difference between revisions)
Line 18: | Line 18: | ||
</style> | </style> | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
- | $(function() { | + | $(function(){ |
+ | |||
/* October 17 wiki FREEZE at 11:59PM EDT */ | /* October 17 wiki FREEZE at 11:59PM EDT */ | ||
var freeze = Date.UTC(2014, 9, 17, 3, 59, 0); | var freeze = Date.UTC(2014, 9, 17, 3, 59, 0); | ||
Line 32: | Line 33: | ||
date.getUTCSeconds() | date.getUTCSeconds() | ||
); | ); | ||
+ | } | ||
+ | |||
+ | /* | ||
+ | * return array of the quoteient and remainder | ||
+ | */ | ||
+ | function qr(dividend, divisor) { | ||
+ | return [Math.floor(dividend/divisor), | ||
+ | dividend%divisor]; | ||
+ | } | ||
+ | |||
+ | function repeat_str(str, n) { | ||
+ | var retval = ''; | ||
+ | for (var i = 0; i < n; i++) { | ||
+ | retval += str; | ||
+ | } | ||
+ | return retval; | ||
+ | } | ||
+ | |||
+ | /* | ||
+ | * transfer Integer to String | ||
+ | */ | ||
+ | function itos(number, figures) { | ||
+ | return [repeat_str('0', figures-1),number] | ||
+ | .join('').slice(-figures); | ||
} | } | ||
Line 46: | Line 71: | ||
countdown.style.color = "#ff0"; | countdown.style.color = "#ff0"; | ||
- | var | + | var time = []; |
- | + | var second_qr = qr(interval, 60); | |
- | + | time.push(itos(second_qr[1], 2) + 's'); | |
- | + | var minute_qr = qr(second_qr[0], 60); | |
- | + | time.push(itos(minute_qr[1], 2) + 'm'); | |
- | + | time.push(itos(minute_qr[0], 2) + 'h'); | |
- | countdown.innerText = | + | countdown.innerText = time.reverse().join(' : '); |
countdown.style.display = "block"; | countdown.style.display = "block"; | ||
} else { | } else { | ||
+ | var time = []; | ||
interval = Math.floor(interval / 60); | interval = Math.floor(interval / 60); | ||
- | var | + | var minute_qr = qr(interval, 60); |
- | + | time.push(itos(minute_qr[1], 2) + 'm'); | |
- | + | var hour_qr = qr(minute_qr[0], 24); | |
- | + | time.push(itos(hour_qr[1], 2) + 'h'); | |
- | + | time.push(itos(hour_qr[0], 3) + 'd'); | |
- | + | countdown.innerText = time.reverse().join(' : '); | |
- | countdown.innerText = | + | |
countdown.style.display = "block"; | countdown.style.display = "block"; | ||
} | } |
Revision as of 16:16, 23 May 2014
count down