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() {
 +
/* October 17 wiki FREEZE at 11:59PM EDT */
 +
var freeze = Date.UTC(2014, 9, 17, 3, 59, 0);
 +
 +
function get_current_utc() {
 +
    var date = new Date();
 +
    return Date.UTC(
 +
        date.getUTCFullYear(),
 +
        date.getUTCMonth(),
 +
        date.getUTCDate(),
 +
        date.getUTCHours(),
 +
        date.getUTCMinutes(),
 +
        date.getUTCSeconds()
 +
    );
 +
}
 +
var timer = setInterval(function() {
var timer = setInterval(function() {
-
  var countdown = document.getElementById("kyoto_alert");
+
    var countdown = document.getElementById("kyoto_alert");
-
  var date = new Date();
+
    var current_utc = get_current_utc();
-
  var time = Date.UTC(
+
     var interval = (freeze - current_utc)/1000;
-
     date.getUTCFullYear(),
+
    if (interval < 0) {
-
    date.getUTCMonth(),
+
        countdown.style.display = "none";
-
    date.getUTCDate(),
+
    } else if (interval < 4 * 24 * 3600) {
-
    date.getUTCHours(),
+
        if (interval < 1 * 3600)
-
    date.getUTCMinutes(),
+
            countdown.style.color = "#f00";
-
    date.getUTCSeconds()
+
        else if (interval < 24 * 3600)
-
  );
+
            countdown.style.color = "#ff0";
-
  var freeze = Date.UTC(2014, 10, 18, 4, 0, 0);
+
 
-
  time = (freeze - time)/1000;
+
        var second = ('0' + (interval % 60)).slice(-2) + 's';
-
  if (time < 1 * 3600) {
+
        interval = Math.floor(interval / 60);
-
    countdown.style.color = "#f00";
+
        var minute = ('0' + (interval % 60)).slice(-2) + 'm';
-
  } else if (time < 24 * 3600) {
+
        interval = Math.floor(interval / 60);
-
    countdown.style.color = "#ff0";
+
        var hour = ('0' + (interval)).slice(-2) + 'h';
-
  }
+
        var str = hour + " : " + minute + " : " + second;
-
  if (time < 0) {
+
        countdown.innerText = str;
-
    countdown.style.display = "none";
+
        countdown.style.display = "block";
-
  } else {
+
-
    var str;
+
-
    if (time > 4 * 24 * 3600) {
+
-
      var odd = (time%60)%2;
+
-
      time = Math.floor(time / 60);
+
-
      var minute = ('0' + (time % 60)).slice(-2);
+
-
      time = Math.floor(time / 60);
+
-
      var hour = ('0' + (time)).slice(-2);
+
-
      time = Math.floor(time / 24);
+
-
      day = ('0' + (time)).slice(-2);
+
-
      str = day + " : " + hour + " : " + minute;
+
     } else {
     } else {
-
      var second = ('0' + (time % 60)).slice(-2);
+
        interval = Math.floor(interval / 60);
-
      time = Math.floor(time / 60);
+
        var minute = ('0' + (interval % 60)).slice(-2) + 'm';
-
      var minute = ('0' + (time % 60)).slice(-2);
+
        interval = Math.floor(interval / 60);
-
      time = Math.floor(time / 60);
+
        var hour = ('0' + (interval)).slice(-2) + 'h';
-
      var hour = ('0' + (time)).slice(-2);
+
        interval = Math.floor(interval / 24);
-
      str = hour + " : " + minute + " : " + second;
+
        var date = ('00' + (interval)).slice(-3) + 'd';
 +
        var str = date + " : " + hour + " : " + minute;
 +
        countdown.innerText = str;
 +
        countdown.style.display = "block";
     }
     }
-
    countdown.innerText = str;
 
-
    countdown.style.display = "block";
 
-
  }
 
}, 200);
}, 200);
 +
 +
});
</script>
</script>
</html>
</html>

Revision as of 11:43, 23 May 2014

count down