Pumunta sa nilalaman

MediaWiki:Monobook.js

Mula Wiktionary

Tandaan: Pagkatapos magtala, dapat linisin mo ang cache ng iyong browser upang makita ang mga pagbabago: Mozilla: i-klik ang reload (o ctrl-r), IE / Opera: ctrl-f5, Safari: cmd-r, Konqueror ctrl-r.

/*
#########
### ProjectLinks
###  by [[user:Pathoschild]] (idea from an older, uncredited script)
###    * generates a sidebar list of links to other projects from {{projectlinks}}
#########
*/
function Projectlinks() {
        var elements = new Array();
        var spans = document.getElementsByTagName('span');
        
        // filter for projectlinks
        for (var i=0, j=0; i<spans.length; i++) {
                if (spans[i].className == 'interProject') {
                        elements[j] = spans[i].getElementsByTagName('a')[0];
                        j++;
                }
        }
        
        // sort alphabetically
        function sortbylabel(a,b) {
                // get labels
                a = a.innerHTML.replace(/^.*<a[^>]*>(.*)<\/a>.*$/i,'$1');
                b = b.innerHTML.replace(/^.*<a[^>]*>(.*)<\/a>.*$/i,'$1');

                // return sort order
                if (a < b) return -1;
                if (a > b) return 1;
                return 0;
        }
        elements.sort(sortbylabel);
        
        if (j) {
                // create navbox
                var plheader = document.createElement('h5');
                plheader.appendChild(document.createTextNode('In other projects'));
                var plbox = document.createElement('div');
                plbox.setAttribute('class','pBody');
                plbox.setAttribute('style','margin-top:0.7em;');
                var pllist = document.createElement('ul');

                // append
                for (var i=0; i<elements.length; i++) {
                        var plitem = document.createElement('li');
                        plitem.appendChild(elements[i]);
                        pllist.appendChild(plitem);
                }
                plbox.appendChild(plheader);
                plbox.appendChild(pllist);
                document.getElementById("p-tb").appendChild(plbox);
        }
}

$( document ).ready( Projectlinks );