MediaWiki:Gadget-IProject.js
Poznámka: Aby sa zmeny prejavili, po uložení musíte vymazať vyrovnávaciu pamäť vášho prehliadača. Mozilla / Firefox / Safari: držte stlačený Shift a kliknite na Reload alebo stlačte buď Ctrl-F5 alebo Ctrl-R (Command-R na Macintosh); Konqueror:: kliknite na tlačidlo Reload alebo stlačte F5; Opera vymazať vyrovnávaciu pamäť prehliadača v ponuke Tools→Preferences; Internet Explorer: držte Ctrl a kliknite na Refresh alebo stlačte 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é projekty';
}
// 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.hasChildNodes()) {
ipDivNode.removeChild(ipDivNode.childNodes[0]);
}
// 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));