2011-06-13 01:06:17 +02:00
|
|
|
/**
|
|
|
|
* @provides javelin-behavior-countdown-timer
|
|
|
|
* @requires javelin-behavior
|
|
|
|
* javelin-dom
|
|
|
|
*/
|
|
|
|
|
|
|
|
JX.behavior('countdown-timer', function(config) {
|
|
|
|
|
2012-08-15 04:19:23 +02:00
|
|
|
var container = JX.$(config.container);
|
2011-06-13 01:06:17 +02:00
|
|
|
calculateTimeLeft();
|
|
|
|
|
2012-08-15 04:19:23 +02:00
|
|
|
function setComponent(which, content) {
|
|
|
|
var component = JX.DOM.find(container, '*', 'phabricator-timer-' + which);
|
|
|
|
JX.DOM.setContent(component, content);
|
|
|
|
}
|
|
|
|
|
2011-06-13 01:06:17 +02:00
|
|
|
function calculateTimeLeft() {
|
|
|
|
var days = 0;
|
|
|
|
var hours = 0;
|
|
|
|
var minutes = 0;
|
|
|
|
var seconds = 0;
|
2013-07-23 15:16:19 +02:00
|
|
|
var partial = 0;
|
2011-06-13 01:06:17 +02:00
|
|
|
|
2013-07-23 15:16:19 +02:00
|
|
|
var current_timestamp = +new Date();
|
|
|
|
|
|
|
|
var delta = (config.timestamp * 1000) - current_timestamp;
|
2011-06-13 01:06:17 +02:00
|
|
|
|
2012-08-15 04:19:23 +02:00
|
|
|
if (delta > 0) {
|
2013-07-23 15:16:19 +02:00
|
|
|
days = Math.floor(delta / 86400000);
|
|
|
|
delta -= days * 86400000;
|
|
|
|
|
|
|
|
hours = Math.floor(delta / 3600000);
|
|
|
|
delta -= hours * 3600000;
|
2011-06-13 01:06:17 +02:00
|
|
|
|
2013-07-23 15:16:19 +02:00
|
|
|
minutes = Math.floor(delta / 60000);
|
|
|
|
delta -= minutes * 60000;
|
2011-06-13 01:06:17 +02:00
|
|
|
|
2013-07-23 15:16:19 +02:00
|
|
|
seconds = Math.floor(delta / 1000);
|
|
|
|
delta -= seconds * 1000;
|
2011-06-13 01:06:17 +02:00
|
|
|
|
2013-07-23 15:16:19 +02:00
|
|
|
partial = Math.floor(delta / 100) || '0';
|
2011-06-13 01:06:17 +02:00
|
|
|
|
2013-07-23 15:16:19 +02:00
|
|
|
setTimeout(calculateTimeLeft, 100);
|
2012-08-15 04:19:23 +02:00
|
|
|
}
|
2011-06-13 01:06:17 +02:00
|
|
|
|
2012-08-15 04:19:23 +02:00
|
|
|
setComponent('days', days);
|
|
|
|
setComponent('hours', hours);
|
|
|
|
setComponent('minutes', minutes);
|
2013-07-23 15:16:19 +02:00
|
|
|
setComponent('seconds', [seconds, JX.$N('small', {}, ['.', partial])]);
|
2011-06-13 01:06:17 +02:00
|
|
|
}
|
2013-07-23 15:16:19 +02:00
|
|
|
|
2011-06-13 01:06:17 +02:00
|
|
|
});
|