Vés al contingut

MediaWiki:Monobook.js/Code.js: diferència entre les revisions

De ca.ConanWiki
Mpuj (discussió | contribucions)
Afegir contingut
 
Mpuj (discussió | contribucions)
Afegir contingut
Línia 1: Línia 1:
/* Any JavaScript here will be loaded for users using the MonoBook skin */
/* Any JavaScript here will be loaded for users using the MonoBook skin */
/*<pre>
/* MONOBOOK SIDEBAR */
Avis: Això és codi JavaScript. Si hi ha algun tipus d'error de sintaxis en aquests codi el menú del sidebar deixarà de funcionar. Assegurat que no trenques res.
// Para editar los elementos del sidebar, cambiar [[MediaWiki:Monobook.js/Sidebar.js]]
Cada element de wgSidebar es el text (després del |) de l'element en [[MediaWiki:Sidebar]]
window.wgSidebar = (window.wgSidebar||{});
Els menús son llistes [ ... ]. Un string ' ... ' es un element. Un objecte { ... } es un element amb un submenú, on la clau (abans dels : ) és el propi element i el valor (després dels : ) és una llista [ ... ] amb el contingut del submenú.
importScript('MediaWiki:Monobook.js/Sidebar.js');
Par a cada element, serà tant l'enllaç com el text. Si es posa una barra | el que hi hagi abans serà l'enllaç i el de després el text.
 
/*
* MonobookSidebar v1.1: Permite definir submenús para elementos del Sidebar de MonoBook, agregando clases
* especiales al pasar con el puntero por encima para permitir el efecto en todos los navegadores.
*
* Copyright (C) 2010  Jesús Martínez Novo ([[User:Ciencia Al Poder]])
*
* This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version
*/
*/
wgSidebar['El Detectiu Conan'] = [
MonobookSidebar = {
{'El Detectiu Conan (anime)|Anime': [
re_s: / /g,
'Llista d'episodis|Llista d'episodis'
re_p: /%/g,
]},
loadedMenus: [],
{'El Detectiu Conan (manga)|Manga': [
init: function() {
'Llista de capítols|Llista de capítols'
if (!window.wgSidebar) return;
]},
for (var menu in wgSidebar) {
'Pel·lícules i especials|Pel·lícules i especials',
var item = document.getElementById(MonobookSidebar.getId(menu));
'Música|Música',
if (!item) continue;
];
var menuId = $(item).parents().get(2).id;
 
// Check it's a valid portlet item
/* Trucada al codi per inicialitzar això */
if (!menuId || menuId == '') continue;
$(MonobookSidebar.init);
// Generate menu hierarchy
 
MonobookSidebar.buildSubmenu(item, wgSidebar[menu]);
/*</pre>*/
// Set events
MonobookSidebar.setEvents(menuId);
}
},
buildSubmenu: function(el, arr) {
var ul = document.createElement('ul');
ul.className = 'sub-menu';
for (var i = 0; i < arr.length; i++) {
var li = document.createElement('li');
if (typeof arr[i] == 'string') {
var a = MonobookSidebar.linkFromText(arr[i]);
li.appendChild(a);
} else {
for (var menukey in arr[i]) {
a = MonobookSidebar.linkFromText(menukey);
li.appendChild(a);
MonobookSidebar.buildSubmenu(li, arr[i][menukey]);
}
}
ul.appendChild(li);
}
el.appendChild(ul);
el.className = 'with-sub-menu';
var em = document.createElement('em');
em.appendChild(document.createTextNode('\u203A'));
el.firstChild.appendChild(em);
},
setEvents: function(menuId) {
for (var i = 0; i < MonobookSidebar.loadedMenus; i++) {
if (MonobookSidebar.loadedMenus[i] == menuId) return;
}
$('#'+menuId).children().eq(1).children().eq(0).bind('mouseover',MonobookSidebar.mouseover).bind('mouseout',MonobookSidebar.mouseout);
MonobookSidebar.loadedMenus.push(menuId);
},
mouseover: function(e) {
var target = e.target;
while (target.tagName.toLowerCase() != 'div') {
if (target.tagName.toLowerCase() == 'a') {
target = target.parentNode;
}
if (target.tagName.toLowerCase() == 'li') {
$(target).addClass('hover');
}
target = target.parentNode;
}
},
mouseout: function(e) {
var target = e.target;
while (target.tagName.toLowerCase() != 'div') {
if (target.tagName.toLowerCase() == 'a') {
target = target.parentNode;
}
if (target.tagName.toLowerCase() == 'li') {
$(target).removeClass('hover');
}
target = target.parentNode;
}
},
linkFromText: function(txt) {
var article = '', caption = '', sepPos = txt.indexOf('|');
if (sepPos > 0) {
article = txt.substr(0, sepPos);
caption = txt.substr(sepPos+1);
} else {
article = caption = txt;
}
var a = document.createElement('a');
if (article.length > 7 && article.substr(0,7) == 'http://') {
a.setAttribute('href',article);
} else {
article = encodeURIComponent(article.replace(MonobookSidebar.re_s, '_'));
a.setAttribute('href',wgArticlePath.replace('$1',article));
}
a.appendChild(document.createTextNode(caption));
return a;
},
getId: function(name) {
return 'n-' + encodeURIComponent(name.replace(MonobookSidebar.re_s, '-')).replace(MonobookSidebar.re_p, '.');
}
};

Revisió del 16:02, 27 gen 2013

/* Any JavaScript here will be loaded for users using the MonoBook skin */
/* MONOBOOK SIDEBAR */
// Para editar los elementos del sidebar, cambiar [[MediaWiki:Monobook.js/Sidebar.js]]
window.wgSidebar = (window.wgSidebar||{});
importScript('MediaWiki:Monobook.js/Sidebar.js');

/*
* MonobookSidebar v1.1: Permite definir submenús para elementos del Sidebar de MonoBook, agregando clases
* especiales al pasar con el puntero por encima para permitir el efecto en todos los navegadores.
*
* Copyright (C) 2010  Jesús Martínez Novo ([[User:Ciencia Al Poder]])
* 
* This program is free software; you can redistribute it and/or modify
*   it under the terms of the GNU General Public License as published by
*   the Free Software Foundation; either version 2 of the License, or
*   (at your option) any later version
*/
MonobookSidebar = {
	re_s: / /g,
	re_p: /%/g,
	loadedMenus: [],
	init: function() {
		if (!window.wgSidebar) return;
		for (var menu in wgSidebar) {
			var item = document.getElementById(MonobookSidebar.getId(menu));
			if (!item) continue;
			var menuId = $(item).parents().get(2).id;
			// Check it's a valid portlet item
			if (!menuId || menuId == '') continue;
			// Generate menu hierarchy
			MonobookSidebar.buildSubmenu(item, wgSidebar[menu]);
			// Set events
			MonobookSidebar.setEvents(menuId);
		}
	},
	buildSubmenu: function(el, arr) {
		var ul = document.createElement('ul');
		ul.className = 'sub-menu';
		for (var i = 0; i < arr.length; i++) {
			var li = document.createElement('li');
			if (typeof arr[i] == 'string') {
				var a = MonobookSidebar.linkFromText(arr[i]);
				li.appendChild(a);
			} else {
				for (var menukey in arr[i]) {
					a = MonobookSidebar.linkFromText(menukey);
					li.appendChild(a);
					MonobookSidebar.buildSubmenu(li, arr[i][menukey]);
				}
			}
			ul.appendChild(li);
		}
		el.appendChild(ul);
		el.className = 'with-sub-menu';
		var em = document.createElement('em');
		em.appendChild(document.createTextNode('\u203A'));
		el.firstChild.appendChild(em);
	},
	setEvents: function(menuId) {
		for (var i = 0; i < MonobookSidebar.loadedMenus; i++) {
			if (MonobookSidebar.loadedMenus[i] == menuId) return;
		}
		$('#'+menuId).children().eq(1).children().eq(0).bind('mouseover',MonobookSidebar.mouseover).bind('mouseout',MonobookSidebar.mouseout);
		MonobookSidebar.loadedMenus.push(menuId);
	},
	mouseover: function(e) {
		var target = e.target;
		while (target.tagName.toLowerCase() != 'div') {
			if (target.tagName.toLowerCase() == 'a') {
				target = target.parentNode;
			}
			if (target.tagName.toLowerCase() == 'li') {
				$(target).addClass('hover');
			}
			target = target.parentNode;
		}
	},
	mouseout: function(e) {
		var target = e.target;
		while (target.tagName.toLowerCase() != 'div') {
			if (target.tagName.toLowerCase() == 'a') {
				target = target.parentNode;
			}
			if (target.tagName.toLowerCase() == 'li') {
				$(target).removeClass('hover');
			}
			target = target.parentNode;
		}
	},
	linkFromText: function(txt) {
		var article = '', caption = '', sepPos = txt.indexOf('|');
		if (sepPos > 0) {
			article = txt.substr(0, sepPos);
			caption = txt.substr(sepPos+1);
		} else {
			article = caption = txt;
		}
		var a = document.createElement('a');
		if (article.length > 7 && article.substr(0,7) == 'http://') {
			a.setAttribute('href',article);
		} else {
			article = encodeURIComponent(article.replace(MonobookSidebar.re_s, '_'));
			a.setAttribute('href',wgArticlePath.replace('$1',article));
		}
		a.appendChild(document.createTextNode(caption));
		return a;
	},
	getId: function(name) {
		return 'n-' + encodeURIComponent(name.replace(MonobookSidebar.re_s, '-')).replace(MonobookSidebar.re_p, '.');
	}
};