MediaWiki:Common.js

From Basin Wiki
Revision as of 08:43, 27 March 2013 by Antitrust (talk | contribs)
Jump to navigation Jump to search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/* 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);


function test()
{
    if(document.getElementById('test'))
    {
        var drop1string = document.getElementById("test1").innerHTML;
        var drop1array = drop1string.split("@-@");
        var drop1list = " ";
        var drop2list = " ";

        var drop3string = document.getElementById("test2").innerHTML;
        var drop3array = drop3string.split("@-@");
        var drop3list = " ";
        
        for (var m=0;m<drop1array.length;m++)
        {
            var x = drop1array[m].split("@@");
            drop1list = drop1list + '<option value="' + x[0] + '">' + x[1] + '</option>';
            drop2list = drop1list;
        }

        for (var n=0;n<drop3array.length;n++)
        {
            var y = drop3array[n].split("@@");
            drop3list = drop3list + '<option value="' + y[0] + '">' + y[1] + '</option>';
        }

        document.getElementById('test').innerHTML = '<select id="id1">' + drop1list + '</select><br /><br /><select id="id2">' + drop2list + '</select><br /><br /><select id="id3">' + drop3list + '</select><br /><br /><input class="level1" value="1"><br /><br /><input class="level2" value="80"><br /><br /><input id="check1" type="checkbox" checked="checked" /><br /><br /><input id="check2" type="checkbox" />';
    }
}
window.document.body.onload = test;