Difference between revisions of "MediaWiki:Common.js"
Jump to navigation
Jump to search
Onderduiker (talk | contribs) m |
Onderduiker (talk | contribs) |
||
Line 3: | Line 3: | ||
(function($) { | (function($) { | ||
− | + | function cdTimer() { | |
− | + | var timerElem = $('#CountdownTimer'); | |
− | |||
− | + | function checkTime(i) { | |
− | + | if (i < 10) { | |
− | + | i = "0" + i; | |
− | + | } | |
− | + | return i; | |
− | + | } | |
− | + | if (timerElem.length > 0) { | |
− | + | var cdoffset = Number(document.getElementById('cdoffset').innerHTML); | |
− | + | var today = new Date(); | |
− | + | var h = today.getUTCHours(); | |
− | + | var m = today.getUTCMinutes(); | |
+ | var s = today.getUTCSeconds(); | ||
− | + | var s1 = (s !== 0) ? 60 - s : s; | |
− | + | var m1 = (m !== 0) ? 60 - m : m; | |
− | + | var h1 = (24 - (h - cdoffset)) % 24; | |
− | + | // add a zero in front of numbers<10 | |
− | + | h1 = checkTime(h1); | |
− | + | m1 = checkTime(m1); | |
− | + | s1 = checkTime(s1); | |
− | + | timerElem.text(h1 + ":" + m1 + ":" + s1); | |
− | + | t = setTimeout(function() { | |
− | + | cdTimer(); | |
− | + | }, 1000); | |
− | |||
} | } | ||
+ | } | ||
− | + | function sTime() { | |
− | + | var timeElem = $('#ServerTime'); | |
− | |||
− | + | function checkTime(i) { | |
− | + | if (i < 10) { | |
− | + | i = "0" + i; | |
− | + | } | |
− | + | return i; | |
− | + | } | |
− | + | if (timeElem.length > 0) { | |
− | + | var soffset = Number(document.getElementById('soffset').innerHTML); | |
− | + | var today = new Date(); | |
− | + | var h = today.getUTCHours(); | |
− | + | var m = today.getUTCMinutes(); | |
+ | var s = today.getUTCSeconds(); | ||
− | + | var h2 = (h + soffset) % 24; | |
− | + | // add a zero in front of numbers<10 | |
− | + | h2 = checkTime(h2); | |
− | + | m2 = checkTime(m); | |
− | + | s2 = checkTime(s); | |
− | + | timeElem.text(h2 + ":" + m2 + ":" + s2); | |
− | + | t = setTimeout(function() { | |
− | + | sTime(); | |
− | + | }, 1000); | |
− | |||
} | } | ||
+ | } | ||
− | + | $(document).ready(cdTimer); | |
− | + | $(document).ready(sTime); | |
})(jQuery); | })(jQuery); |
Revision as of 11:56, 2 October 2012
/* Any JavaScript here will be loaded for all users on every page load. */ /* This code displays a clock or a countdown timer. Adapted from w3schools.com example. */ (function($) { function cdTimer() { var timerElem = $('#CountdownTimer'); function checkTime(i) { if (i < 10) { i = "0" + i; } return i; } if (timerElem.length > 0) { var cdoffset = Number(document.getElementById('cdoffset').innerHTML); var today = new Date(); var h = today.getUTCHours(); var m = today.getUTCMinutes(); var s = today.getUTCSeconds(); var s1 = (s !== 0) ? 60 - s : s; var m1 = (m !== 0) ? 60 - m : m; var h1 = (24 - (h - cdoffset)) % 24; // add a zero in front of numbers<10 h1 = checkTime(h1); m1 = checkTime(m1); s1 = checkTime(s1); timerElem.text(h1 + ":" + m1 + ":" + s1); t = setTimeout(function() { cdTimer(); }, 1000); } } function sTime() { var timeElem = $('#ServerTime'); function checkTime(i) { if (i < 10) { i = "0" + i; } return i; } if (timeElem.length > 0) { var soffset = Number(document.getElementById('soffset').innerHTML); var today = new Date(); var h = today.getUTCHours(); var m = today.getUTCMinutes(); var s = today.getUTCSeconds(); var h2 = (h + soffset) % 24; // add a zero in front of numbers<10 h2 = checkTime(h2); m2 = checkTime(m); s2 = checkTime(s); timeElem.text(h2 + ":" + m2 + ":" + s2); t = setTimeout(function() { sTime(); }, 1000); } } $(document).ready(cdTimer); $(document).ready(sTime); })(jQuery);