Template:Kyoto/small countdown

From 2014.igem.org

(Difference between revisions)
 
(19 intermediate revisions not shown)
Line 1: Line 1:
 +
<!-- http://github.com/iGEMKyoto/wiki_freeze_alert -->
 +
<div id="kyoto-alert">
 +
    <div id="kyoto-alert-display">count down</div>
 +
    <div id="kyoto-alert-popup">{{{popup|}}}</div>
 +
</div>
<html>
<html>
-
<a id="kyoto_alert" target="_blank" href="https://2013.igem.org/Team:Kyoto/TimeLimit">count down</a>
 
<style type="text/css">
<style type="text/css">
-
#kyoto_alert {
+
#kyoto-alert {
   position: fixed;
   position: fixed;
   top: 30px;
   top: 30px;
   right: 10px;
   right: 10px;
-
  background-color: #333;
 
-
  border: 4px solid #000;
 
   height: 30px;
   height: 30px;
 +
  width: 300px;
 +
  padding: 30px 10px;
 +
  display: none;
 +
  z-index: 300;
 +
 +
  /* text */
   line-height: 30px;
   line-height: 30px;
   font-size: 30px;
   font-size: 30px;
-
   color: #ddd;
+
   font-family: sans-serif;
 +
  text-align: center;
   text-decoration: none;
   text-decoration: none;
-
   padding: 30px 10px;
+
 
-
   display: none;
+
   /* color */
 +
  background-color: #aaa;
 +
   border: 4px solid #888;
 +
  color: #eee;
 +
 
 +
  /* box sizing */
 +
  box-sizing: content-box;
 +
  -webkit-box-sizing: content-box;
 +
  -moz-box-sizing: content-box;
 +
 
 +
  /* border radius */
 +
  border-radius: 20px;
 +
  -webkit-border-radius: 20px;
 +
  -moz-border-radius: 20px;
 +
 
 +
  /* select cancel */
 +
  user-select: none;
 +
  -webkit-user-select: none;
 +
  -moz-user-select: none;
 +
  -khtml-user-select: none;
 +
}
 +
#kyoto-alert:hover {
 +
    cursor: move;
 +
}
 +
#kyoto-alert-display {
 +
    width: 100%;
 +
    height: 100%;
 +
}
 +
#kyoto-alert-popup {
 +
    position: relative;
 +
    top: 35px;
 +
    color: #000;
 +
 
 +
    /* text-shadow */
 +
    -webkit-text-shadow: 0px 0px 6px #fff;
 +
    -moz-text-shadow: 0px 0px 6px #fff;
 +
    text-shadow: 0px 0px 6px #fff;
 +
 
 +
    display: none;
 +
}
 +
#kyoto-alert:hover #kyoto-alert-popup {
 +
    display: block;
}
}
</style>
</style>
 +
 +
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script>
 +
<script type="text/javascript">
<script type="text/javascript">
 +
//<![CDATA[
 +
$(function(){
 +
 +
/* October 17 wiki FREEZE at 12:00PM EDT */
 +
var year = </html>{{{year|2014}}}<html>;
 +
var month = </html>{{{month|10}}}<html>;
 +
var day = </html>{{{day|18}}}<html>;
 +
var freeze = Date.UTC(year, month-1, day, 4, 00, 0);
 +
 +
function get_current_utc() {
 +
    var date = new Date();
 +
    return Date.UTC(
 +
        date.getUTCFullYear(),
 +
        date.getUTCMonth(),
 +
        date.getUTCDate(),
 +
        date.getUTCHours(),
 +
        date.getUTCMinutes(),
 +
        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);
 +
}
 +
var timer = setInterval(function() {
var timer = setInterval(function() {
-
  var countdown = document.getElementById("kyoto_alert");
+
    var $countdown = $("#kyoto-alert");
-
  var date = new Date();
+
    var $display = $("#kyoto-alert-display");
-
  var time = Date.UTC(
+
    var current_utc = get_current_utc();
-
    date.getUTCFullYear(),
+
     var interval = (freeze - current_utc)/1000;
-
     date.getUTCMonth(),
+
     if (interval < 0) {
-
     date.getUTCDate(),
+
        $countdown.hide();
-
    date.getUTCHours(),
+
     } else if (interval < 4 * 24 * 3600) {
-
     date.getUTCMinutes(),
+
        if (interval < 1 * 3600)
-
    date.getUTCSeconds()
+
            $display.css("color", "#f00");
-
  );
+
        else if (interval < 24 * 3600)
-
  var freeze = Date.UTC(2014, 10, 18, 4, 0, 0);
+
            $display.css("color", "#ff0");
-
  time = (freeze - time)/1000;
+
 
-
  if (time < 1 * 3600) {
+
        var time = [];
-
    countdown.style.color = "#f00";
+
        var second_qr = qr(interval, 60);
-
  } else if (time < 24 * 3600) {
+
        time.push(itos(second_qr[1], 2) + 's');
-
    countdown.style.color = "#ff0";
+
        var minute_qr = qr(second_qr[0], 60);
-
  }
+
        time.push(itos(minute_qr[1], 2) + 'm');
-
  if (time < 0) {
+
        time.push(itos(minute_qr[0], 2) + 'h');
-
    countdown.style.display = "none";
+
        $display.text(time.reverse().join(' : '));
-
  } else {
+
        $countdown.show();
-
    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);
+
        var time = [];
-
      time = Math.floor(time / 60);
+
        interval = Math.floor(interval / 60);
-
      var minute = ('0' + (time % 60)).slice(-2);
+
        var minute_qr = qr(interval, 60);
-
      time = Math.floor(time / 60);
+
        time.push(itos(minute_qr[1], 2) + 'm');
-
      var hour = ('0' + (time)).slice(-2);
+
        var hour_qr = qr(minute_qr[0], 24);
-
      str = hour + " : " + minute + " : " + second;
+
        time.push(itos(hour_qr[1], 2) + 'h');
 +
        time.push(itos(hour_qr[0], 3) + 'd');
 +
        $display.text(time.reverse().join(' : '));
 +
        $countdown.show();
     }
     }
-
    countdown.innerText = str;
 
-
    countdown.style.display = "block";
 
-
  }
 
}, 200);
}, 200);
 +
 +
$("#kyoto-alert").draggable();
 +
 +
});
 +
//]]>
</script>
</script>
</html>
</html>

Latest revision as of 06:12, 10 October 2014

count down