MediaWiki:Monobook.js

Dâ Wikipedia, la nciclupidìa lìbbira.

Nota: doppu aviri sarvatu, hai a puliri la cache di lu tò browser pi vìdiri li canciamenti: Mozilla: clicca supra reload (oppure ctrl-r), IE / Opera: ctrl-f5, Safari: cmd-r, Konqueror ctrl-r.

/* <pre> */



/** "Technical restrictions" title fix *****************************************
*
*  Description:
*  Maintainers: [[User:Interiot]], [[User:Mets501]]
*  copiato da [[:en:MediaWiki:Common.js]]
*ricopiato da itwiki
*/
 
// For pages that have something like Template:Lowercase, replace the title, but only if it is cut-and-pasteable as a valid wikilink.
//	(for instance [[iPod]]'s title is updated.  <nowiki>But [[C#]] is not an equivalent wikilink, so [[C Sharp]] doesn't have its main title changed)</nowiki>
//
// The function looks for a banner like this: <nowiki>
// <div id="RealTitleBanner">    <!-- div that gets hidden -->
//   <span id="RealTitle">title</span>
// </div>
// </nowiki>An element with id=DisableRealTitle disables the function.
var disableRealTitle = 0;		// users can disable this by making this true from their monobook.js
$(function() {
	try {
		var realTitleBanner = document.getElementById("RealTitleBanner");
		if (realTitleBanner && !document.getElementById("DisableRealTitle") && !disableRealTitle) {
			var realTitle = document.getElementById("RealTitle");
			if (realTitle) {
				var realTitleHTML = realTitle.innerHTML;
				realTitleText = pickUpText(realTitle);
 
				var isPasteable = 0;
				//var containsHTML = /</.test(realTitleHTML);	// contains ANY HTML
				var containsTooMuchHTML = /</.test( realTitleHTML.replace(/<\/?(sub|sup|small|big|a)>/gi, "") ); // contains HTML that will be ignored when cut-n-pasted as a wikilink
					// in più, aggiunto ''a'' per mantenere funzionanti alcuni usi del vecchio Titolo errato - non è detto però che sia sempre voluto
				// questo codice era in en.wiki, e se ho ben capito serviva per controllare che il nome nuovo fosse abbastanza simile all'originale, ma non è quello che vogliamo su it.wiki
				// // calculate whether the title is pasteable
				// var verifyTitle = realTitleText.replace(/^ +/, "");		// trim left spaces
				// verifyTitle = verifyTitle[0].toUpperCase() + verifyTitle.substring(1, verifyTitle.length);	// uppercase first character
 
				// questo codice era in en.wiki, e aggiunge il prefisso del namespace se non presente, ma su it.wiki ci si aspetta che ciò non avvenga
				// // if the namespace prefix is there, remove it on our verification copy.  If it isn't there, add it to the original realValue copy.
				// if (wgNamespaceNumber != 0) {
				// 	if (wgCanonicalNamespace == verifyTitle.substr(0, wgCanonicalNamespace.length).replace(/ /g, "_") && verifyTitle.charAt(wgCanonicalNamespace.length) == ":") {
				// 		verifyTitle = verifyTitle.substr(wgCanonicalNamespace.length + 1);
				// 	} else {
				// 		realTitleText = wgCanonicalNamespace.replace(/_/g, " ") + ":" + realTitleText;
				// 		realTitleHTML = wgCanonicalNamespace.replace(/_/g, " ") + ":" + realTitleHTML;
				// 	}
				// }
 
				// come sopra, faceva controlli sul titolo
				// // verify whether wgTitle matches
				// verifyTitle = verifyTitle.replace(/^ +/, "").replace(/ +$/, "");		// trim left and right spaces
				// verifyTitle = verifyTitle.replace(/_/g, " ");		// underscores to spaces
				// verifyTitle = verifyTitle[0].toUpperCase() + verifyTitle.substring(1, verifyTitle.length);	// uppercase first character
				// isPasteable = (verifyTitle == wgTitle);
 
				var h1 = document.getElementsByTagName("h1")[0];
				if (h1) {     // tolto il controllo isPasteable
					h1.innerHTML = containsTooMuchHTML ? realTitleText : realTitleHTML;
					// if (!containsTooMuchHTML) // ancora, adattamento per it.wiki che dovrebbe andare anche per scn
						realTitleBanner.style.display = "none";
				}
				document.title = realTitleText + " - Wikipedia";
			}
		}
	} catch (e) {
		/* Something went wrong. */
	}
});


// similar to innerHTML, but only returns the text portions of the insides, excludes HTML
function pickUpText(aParentElement) {
var str = "";
 
function pickUpTextInternal(aElement) {
var child = aElement.firstChild;
while (child) {
if (child.nodeType == 1)		// ELEMENT_NODE 
pickUpTextInternal(child);
else if (child.nodeType == 3)	// TEXT_NODE
str += child.nodeValue;
 
child = child.nextSibling;
}
}
 
pickUpTextInternal(aParentElement);
 
return str;
}



/*
Correzione della posizione del link [cancia] delle sezioni.
 
Copyright 2006, Marc Mongenet
 
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.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
 
See http://www.gnu.org/licenses/gpl.html
 
The function looks for <span class="editsection">, and move them
at the end of their parent and display them inline in small font.
var oldEditsectionLinks=true disables the function.
*/
 
setModifySectionStyle = function()
{
try {
if (!(typeof oldEditsectionLinks == 'undefined' || oldEditsectionLinks == false)) return;
var spans = document.getElementsByTagName("span");
for (var s = 0; s < spans.length; ++s) {
var span = spans[s];
if (span.className == "editsection") {
span.style.fontSize = "x-small";
span.style.fontWeight = "normal";
span.style.cssFloat = span.style.styleFloat = "none";
span.parentNode.appendChild(document.createTextNode(" "));
span.parentNode.appendChild(span);
}
}
} catch (e) { /* something went wrong */ }
}
$(setModifySectionStyle);
 


//Add an "invert" button in Undeletion page (source: http://en.wikipedia.org/wiki/User:Cryptic/toggleundelete.js)

function toggle_undelete()
{
var f = document.getElementById("undelete");
if (f)
{
var inputs = f.getElementsByTagName("input");
var i;
for (i = 0; i < inputs.length; ++i)
if (inputs[i].type == "checkbox")
inputs[i].checked = !inputs[i].checked;
}
}

function setup_toggle_undelete()
{
if (document.title.indexOf("Talìa e ricùpira li pàggini cancillati") == 0)
{
var f = document.getElementById("undelete");
if (f)
{
var h2 = f.getElementsByTagName("h2")[0];
if (h2)
{
var button = document.createElement('input');
button.type = "button";
button.value = "Nverti silizzioni";
button.setAttribute('onClick', 'toggle_undelete()');
f.insertBefore(button, h2);
}
}
}
}

$(setup_toggle_undelete);





/*</pre>*/