Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
HTML5: Added countdown timer. Still needs to English text substituted…
… with language references.

git-svn-id: https://xerteonlinetoolkits.googlecode.com/svn/trunk@582 912cdd6b-5c7d-d5a7-a2ba-d0f0cdb91641
  • Loading branch information
JohnSmith-LT committed Dec 8, 2012
1 parent da9afb4 commit c589978
Showing 1 changed file with 42 additions and 0 deletions.
Expand Up @@ -690,6 +690,7 @@ function x_setUpPage() {
$x_menuBtn.button("enable");
}
x_addNarration();
x_addCountdownTimer();
}

$("#x_headerBlock h2").html(pageTitle);
Expand Down Expand Up @@ -742,6 +743,47 @@ function x_addNarration() {
}
}

function x_addCountdownTimer() {

var x_countdownTicker = function () {
x_countdownTimer--;
if (x_countdownTimer > 0) {
$("#x_footerBlock #x_pageTimer").html("Time remaining: " + x_formatCountdownTimer());
}
else {
window.clearInterval(x_timer);
$("#x_footerBlock #x_pageTimer").html("Time up!");
}
};

var x_formatCountdownTimer = function () {
var dd = function (x) { return (x<10 ? "0"+x : x); }

var hours = Math.floor(x_countdownTimer / 3600);
var minutes = Math.floor(x_countdownTimer / 60);
var seconds = x_countdownTimer % 60;

if (hours > 0) {
return hours + ":" + dd(minutes) + ":" + dd(seconds);
}
else if (minutes > 0) {
return dd(minutes) + ":" + dd(seconds);
}
else {
return seconds + " seconds";
}
};

var x_countdownTimer;

if (x_currentPageXML.getAttribute("timer") != null && x_currentPageXML.getAttribute("timer") != "") {
$("#x_footerBlock div:first").before('<div id="x_pageTimer"></div>');
x_countdownTimer = parseInt(x_currentPageXML.getAttribute("timer"));
$("#x_footerBlock #x_pageTimer").html("Time remaining: " + x_formatCountdownTimer());
x_timer = window.setInterval(x_countdownTicker, 1000);
}
}

// function returns correct phrase from language file or uses fallback if no matches / no language file
function x_getLangInfo(node, attribute, fallBack) {
var string = fallBack;
Expand Down

0 comments on commit c589978

Please sign in to comment.