Difference between revisions of "MediaWiki:Common.js"

From Basin Wiki
Jump to navigation Jump to search
Line 1: Line 1:
 
/* Any JavaScript here will be loaded for all users on every page load. */
 
/* 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. */
 
/* This code displays a clock or a countdown timer. Adapted from w3schools.com example. */
jQuery( document ).ready( function( $ ) {
+
(function($) {
  
function cdTimer() {
+
        function cdTimer() {
        var timerElem = $('#CountdownTimer');
+
                var timerElem = $('#CountdownTimer');
        var cdoffset = document.getElementById('cdoffset').innerHTML;
+
                var cdoffset = document.getElementById('cdoffset').innerHTML;
  
        function checkTime(i) {
+
                function checkTime(i) {
                if (i < 10) {
+
                        if (i < 10) {
                        i = "0" + i;
+
                                i = "0" + i;
                }
+
                        }
                return i;
+
                        return i;
        }
+
                }
  
        if (timerElem.length > 0) {
+
                if (timerElem.length > 0) {
                var today = new Date();
+
                        var today = new Date();
                var h = today.getUTCHours();
+
                        var h = today.getUTCHours();
                var m = today.getUTCMinutes();
+
                        var m = today.getUTCMinutes();
                var s = today.getUTCSeconds();
+
                        var s = today.getUTCSeconds();
  
                var s1 = (s !==0) ? 60 - s : s;
+
                        var s1 = (s !== 0) ? 60 - s : s;
                var m1 = (m !==0) ? 60 - m : m;
+
                        var m1 = (m !== 0) ? 60 - m : m;
                var h1 = (24 - (h - cdoffset)) % 24;
+
                        var h1 = (24 - (h - cdoffset)) % 24;
  
                // add a zero in front of numbers<10
+
                        // add a zero in front of numbers<10
                m1 = checkTime(m1);
+
                        m1 = checkTime(m1);
                s1 = checkTime(s1);
+
                        s1 = checkTime(s1);
                timerElem.text(h1 + ":" + m1 + ":" + s1);
+
                        timerElem.text(h1 + ":" + m1 + ":" + s1);
                t = setTimeout('cdTimer()', 1000);
+
                        t = setTimeout(function() {
        }
+
                                cdTimer();
}
+
                        }, 1000);
  
function sTime() {
+
                }
                var timeElem = $('#ServerTime');
+
        }
                var soffset = document.getElementById('soffset').innerHTML;
 
  
                function checkTime(i) {
+
        function sTime() {
                                if (i < 10) {
+
                var timeElem = $('#ServerTime');
                                                i = "0" + i;
+
                var soffset = document.getElementById('soffset').innerHTML;
                                }
 
                                return i;
 
                }
 
  
                if (timeElem.length > 0) {
+
                function checkTime(i) {
                                var today = new Date();
+
                        if (i < 10) {
                                var h = today.getUTCHours();
+
                                i = "0" + i;
                                var m = today.getUTCMinutes();
+
                        }
                                var s = today.getUTCSeconds();
+
                        return i;
 +
                }
  
                                var h2 = (h + soffset) % 24;
+
                if (timeElem.length > 0) {
 +
                        var today = new Date();
 +
                        var h = today.getUTCHours();
 +
                        var m = today.getUTCMinutes();
 +
                        var s = today.getUTCSeconds();
  
                                // add a zero in front of numbers<10
+
                        var h2 = (h + soffset) % 24;
                                h2 = checkTime(h2);
 
                                m2 = checkTime(m);
 
                                s2 = checkTime(s);
 
                                timeElem.text(h2 + ":" + m2 + ":" + s2);
 
                                t = setTimeout('sTime()', 1000);
 
                }
 
}
 
  
});
+
                        // 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);

Revision as of 17:58, 30 September 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');
                var cdoffset = document.getElementById('cdoffset').innerHTML;

                function checkTime(i) {
                        if (i < 10) {
                                i = "0" + i;
                        }
                        return i;
                }

                if (timerElem.length > 0) {
                        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
                        m1 = checkTime(m1);
                        s1 = checkTime(s1);
                        timerElem.text(h1 + ":" + m1 + ":" + s1);
                        t = setTimeout(function() {
                                cdTimer();
                        }, 1000);

                }
        }

        function sTime() {
                var timeElem = $('#ServerTime');
                var soffset = document.getElementById('soffset').innerHTML;

                function checkTime(i) {
                        if (i < 10) {
                                i = "0" + i;
                        }
                        return i;
                }

                if (timeElem.length > 0) {
                        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);