MediaWiki:Gadget-IProject.js

Opmerking: nadat u de wijzigingen hebt gepubliceerd is het wellicht nodig uw browsercache te legen.

  • Firefox / Safari: houd Shift ingedrukt terwijl u op Vernieuwen klikt of druk op Ctrl-F5 of Ctrl-R (⌘-Shift-R op een Mac)
  • Google Chrome: druk op Ctrl-Shift-R (⌘-Shift-R op een Mac)
  • Internet Explorer / Edge: houd Ctrl ingedrukt terwijl u op Vernieuwen klikt of druk op Ctrl-F5
  • Opera: druk op Ctrl-F5.
/**
 * iProject (InterProjectLinks)
 * Description: Adds links to other WMF projects in the sidebar
 *   ([[:bugzilla:708]]). Works for all skins with a sidebar.
 *
 * @author Erwin
 * @author Krinkle
 * @version 2 (2012-08-25)
 *
 * Originally written by Magnus Manske. Version forked from [[:es:MediaWiki:Common.js]] and [[:de:wikt:Mediawiki:monobook.js]]
 */
/*jslint browser: true */
/*global mediaWiki, jQuery */
(function (mw, $) {
    "use strict";
    function initInterProject() {
        var ipNode, ipLinks, prevNode, ipHeadNode, ipDivNode, ipUlNode,
            i, len, li;

        // Find templates with interproject links. These templates should have a div
        // with class 'interProject' that only contains a link to the other project.
        ipLinks = $('div.interProject').toArray();

        // Don't make a heading in the sidebar if there are no items to put inside
        if (ipLinks.length) {

            // Determine below what sidebar box the new interproject links should be displayed.

            // First, try 'Print/export'. It should always be available when viewing a content page.
            prevNode = document.getElementById('p-coll-print_export');

            // Second, try 'Toolbox'. It should always be available, so also when previewing a content page.
            if (!prevNode) {
                prevNode = document.getElementById('p-tb');
            }

            // Else, give up.
            if (!prevNode) {
                return false;
            }

            // Clone previous node, including child nodes.
            ipNode = prevNode.cloneNode(true);
            ipNode.id = 'p-project';

            // Set header of new toolbox
            ipHeadNode = ipNode.getElementsByTagName('h3');
            if (ipHeadNode[0]) {
                ipHeadNode[0].innerHTML = 'In andere projecten';
            }

            // The links are included in the first and only div of the toolbox
            ipDivNode = ipNode.getElementsByTagName('div');
            if (ipDivNode[0]) {
                ipDivNode = ipDivNode[0];
            } else {
                return false;
            }

            // Remove current children, i.e. current ul element.
            while (ipDivNode.firstChild) {
                ipDivNode.removeChild(ipDivNode.firstChild);
            }

            // Create new list with links
            ipUlNode = document.createElement('ul');
            for (i = 0, len = ipLinks.length; i < len; i += 1) {
                li = document.createElement('li');
                li.innerHTML = ipLinks[i].innerHTML;
                ipUlNode.appendChild(li);
            }
            ipDivNode.appendChild(ipUlNode);

            // Insert new node
            prevNode.parentNode.insertBefore(ipNode, prevNode.nextSibling);
        }
    }

    $(document).ready(function ($) {
        // Ignore skins with langlinks in top bar and/or no side bar
        if ($.inArray(mw.config.get('skin'), ['cologneblue', 'nostalgia', 'standard']) === -1) {
            initInterProject();
        }
    });

}(mediaWiki, jQuery));