MediaWiki:Common.js: Difference between revisions

From WikiBound, your community-driven EarthBound/Mother wiki
Jump to navigationJump to search
no edit summary
No edit summary
No edit summary
Line 344: Line 344:
importStylesheetURI("http://zeldawiki.org/User:Matt/RC_Colors.css" + "&ctype=text/css&action=raw");
importStylesheetURI("http://zeldawiki.org/User:Matt/RC_Colors.css" + "&ctype=text/css&action=raw");
//
//
== Interproject links ==
<pre>*/
/* gotten from http://en.wiktionary.org/wiki/MediaWiki:Common.js on 10/16/2010
#########
### 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++;
                }
        }
        if (j == 0)
            return;
       
        // 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);
       
        // Create the list of project links
        var pllist = newNode('ul');
        for (var i=0; i<elements.length; i++) {
                pllist.appendChild(newNode('li', elements[i]));
        }
        var projectBox = newNode('div', {'class': 'portlet portal', id: 'p-projects'},
            newNode('h5', 'On other wiki's'),
            newNode('div', {'class': 'pBody body'}, pllist)
        );
        var insert = document.getElementById('p-tb');
        if (!insert)
            return;
        if (insert.nextSibling)
            insert.parentNode.insertBefore(projectBox, insert.nextSibling);
        else
            insert.parentNode.appendChild(projectBox);
}
addOnloadHook(Projectlinks);

Navigation menu