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 second = ('0' + (interval % 60)).slice(-2) + 's';
+
         var time = [];
-
         interval = Math.floor(interval / 60);
+
        var second_qr = qr(interval, 60);
-
         var minute = ('0' + (interval % 60)).slice(-2) + 'm';
+
        time.push(itos(second_qr[1], 2) + 's');
-
         interval = Math.floor(interval / 60);
+
         var minute_qr = qr(second_qr[0], 60);
-
        var hour = ('0' + (interval)).slice(-2) + 'h';
+
         time.push(itos(minute_qr[1], 2) + 'm');
-
        var str = hour + " : " + minute + " : " + second;
+
         time.push(itos(minute_qr[0], 2) + 'h');
-
         countdown.innerText = str;
+
         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 minute = ('0' + (interval % 60)).slice(-2) + 'm';
+
         var minute_qr = qr(interval, 60);
-
         interval = Math.floor(interval / 60);
+
        time.push(itos(minute_qr[1], 2) + 'm');
-
         var hour = ('0' + (interval)).slice(-2) + 'h';
+
         var hour_qr = qr(minute_qr[0], 24);
-
         interval = Math.floor(interval / 24);
+
         time.push(itos(hour_qr[1], 2) + 'h');
-
        var date = ('00' + (interval)).slice(-3) + 'd';
+
         time.push(itos(hour_qr[0], 3) + 'd');
-
        var str = date + " : " + hour + " : " + minute;
+
         countdown.innerText = time.reverse().join(' : ');
-
         countdown.innerText = str;
+
         countdown.style.display = "block";
         countdown.style.display = "block";
     }
     }

Revision as of 16:16, 23 May 2014

count down