Difference between revisions of "MediaWiki:Common.js"

From Basin Wiki
Jump to navigation Jump to search
Line 152: Line 152:
 
             if (foodtype == 3 || Number(temparray[6]) == foodtype)
 
             if (foodtype == 3 || Number(temparray[6]) == foodtype)
 
             {
 
             {
             if (databasearray[k].trim().indexOf(drop1) >=0 && databasearray[k].trim().indexOf(drop2) >=0 && databasearray[k].trim().indexOf(drop3) >=0)
+
             if (databasearray[k].search(drop1) >=0 && databasearray[k].search(drop2) >=0 && databasearray[k].search(drop3) >=0)
 
             {
 
             {
                 result= result + "{{nourishment" + "|name =" + temparray[0].trim() + "|duration = " + temparray[1].trim() + "|property1 = " + temparray[2].trim() + "|property2 = " + temparray[3].trim() + "|property3 = " + temparray[4].trim() + "|levelreq = " + temparray[5].trim() + "}}";
+
                 result= result + '<div style="border: 1px solid black; padding: 5px; margin-top: 5px;">' + temparray[0] + '<br />' + temparray[1] + '<br />' + temparray[2] + '<br />' + temparray[3] + '<br />' + temparray[4] + '<br />' + temparray[5] + '</div>';
 
             }
 
             }
 
             }
 
             }

Revision as of 07:43, 28 March 2013

/* 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 dbfood()
{
    if(document.getElementById('intfood'))
    {
        var drop1string = document.getElementById("dropdown1").innerHTML;
        var drop1array = drop1string.split("@-@");
        var drop1list = " ";
        var drop2list = " ";

        var drop3string = document.getElementById("dropdown2").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('intfood').innerHTML = '<select id="drop1">' + drop1list + '</select><br /><br /><select id="drop2">' + drop2list + '</select><br /><br /><select id="drop3">' + drop3list + '</select><br /><br /><input class="level1" value="1"><br /><br /><input class="level2" value="80"><br /><br /><input id="food" type="checkbox" checked="checked" /><br /><br /><input id="notfood" type="checkbox" /><br /><br /><input type="button" value="Search" class="submit" style="width:100px; margin-left:70px; text-align:center;"></input>';
        
$(".submit").live("click", function () {
    var database = document.getElementById("database").innerHTML;
    var databasearray = database.split("@@");
    var level = [Number($(".level1").val()),Number($(".level2").val())];
    var drop1 = document.getElementById("drop1").options[document.getElementById("drop1").selectedIndex].value;
    var drop2 = document.getElementById("drop2").options[document.getElementById("drop2").selectedIndex].value;
    var drop3 = document.getElementById("drop3").options[document.getElementById("drop3").selectedIndex].value;
    var food;
    var notfood;
    var result = " ";
    
    for (var i=0;i<=1;i++)
        {
           if (level[i]<1)
           {
           level[i] = 1;
           }
           if (level[i]>80)
           {
           level[i] = 80;
           }
           if (level[0]>level[1])
           {
           level = level.reverse();
           }
        }
    
    if (document.getElementById("food").checked === true)
           {
           food = 1;
           }
           else
           {
           food = 0;
           }
           if (document.getElementById("notfood").checked === true)
           {
           notfood = 2;
           }
           else
           {
           notfood = 0;
           }
    var foodtype = food + notfood;

    for (var k=0;k<databasearray.length;k++)
    {
        var temparray = databasearray[k].split("@-@");
        if (Number(temparray[5]) >= level[0] && Number(temparray[5]) <= level[1])
        {
            if (foodtype == 3 || Number(temparray[6]) == foodtype)
            {
            if (databasearray[k].search(drop1) >=0 && databasearray[k].search(drop2) >=0 && databasearray[k].search(drop3) >=0)
            {
                result= result + '<div style="border: 1px solid black; padding: 5px; margin-top: 5px;">' + temparray[0] + '<br />' + temparray[1] + '<br />' + temparray[2] + '<br />' + temparray[3] + '<br />' + temparray[4] + '<br />' + temparray[5] + '</div>';
            }
            }
        }
    }
    document.getElementById('result').innerHTML = result;
});
        
    }
}
window.document.body.onload = dbfood;