Usuario:Ciencia Al Poder/monobook.js

De Wikilibros, la colección de libros de texto de contenido libre.

Nota: Después de publicar, quizás necesite actualizar la caché de su navegador para ver los cambios.

  • Firefox/Safari: Mantenga presionada la tecla Shift mientras pulsa el botón Actualizar, o presiona Ctrl+F5 o Ctrl+R (⌘+R en Mac)
  • Google Chrome: presione Ctrl+Shift+R (⌘+Shift+R en Mac)
  • Internet Explorer/Edge: mantenga presionada Ctrl mientras pulsa Actualizar, o presione Ctrl+F5
  • Opera: Presiona Ctrl+F5.
addPlusToBeerParlour=function(){};

/**
 * Cambia la presentación del título en subpáginas
 * @author : DavidL, Tavernier (rewrite), Ciencia_Al_Poder (rewrite 2)
 */
function setupTitle() {
	if (  (wgAction != 'view') 
		|| wgNamespaceNumber  //only on main space (0)
		|| document.getElementById('contentSub2') //while the page is deleted, avoiding to catch the "N revisions deleted"
		|| !document.getElementById('content') || !document.getElementById('contentSub') ) // Salimos si no es Monobook o no hay subpáginas
			return; 

	// Obtenemos título
	var title, h1s = document.getElementById('content').getElementsByTagName('h1');
	for (var i=0; i < h1s.length; i++){
		if ((' '+h1s[i].className+' ').indexOf(' firstHeading ') != -1)
			title = h1s[i];
	}
	if (!title) return;

	var hasInnerText = (title.innerText != undefined);

	var subpages, ssub = document.getElementById('contentSub').getElementsByTagName('span');
	for (var i=0; i < ssub.length; i++){
		if ((' '+ssub[i].className+' ').indexOf(' subpages ') != -1)
			subpages = ssub[i];
	}
	
	if (!subpages) return;

	var links = subpages.getElementsByTagName("a");

	if (title.firstChild.nodeType != 3) // no es texto
		return;

	//Eliminamos antiguo y guardamos como TextNode
	var saveTitle = title.removeChild(title.firstChild),
		curTitle = title,
		subpagename = wgTitle;

	// Movemos (en lugar de crear) los enlaces
	while (links.length > 0){
		var s = document.createElement('span'),
			it = hasInnerText ? links[0].innerText : links[0].textContent;
		s.className = 'subpagepart' + (subpagename==wgTitle ? '-first' : '');
		subpagename = subpagename.replace(it+'/', '');
		curTitle.appendChild(s);
		s.appendChild(links[0]);
		curTitle = s;
	}

	// Agregamos la última parte, sin enlace
	var st = document.createElement('span');
	st.className = 'subpagepart';
	curTitle.appendChild(st);
	st.appendChild(document.createTextNode(subpagename));

	// Donde estaban los links colocamos el título
	subpages.innerHTML = '';
	subpages.appendChild(saveTitle);

}

if ( typeof ( g_setuptitle ) == "undefined" )
	addOnloadHook(setupTitle);