MediaWiki:Common.js

/*   multiple onload functions // aOnloadFunctions[aOnloadFunctions.length] = function_name; // without brackets!

if (!window.aOnloadFunctions) { var aOnloadFunctions = new Array; }

window.onload = function { if (window.aOnloadFunctions) { for (var _i=0; _i '); } function getElementsByClass(cls, tag, doc) {   allElements = doc.getElementsByTagName(tag); var i = 0; arr = new Array; for(i = 0; i<allElements.length; i++) { if(allElements[i].className == cls) arr.push(allElements[i]); }   return arr; } inc('MediaWiki:FasiAvanzamento.js'); /*   Script per nascondere il titolo e i link alle pagine madri. Da Utente:Pietrodn.

function killTitle { if(document.getElementById('NoTitle')) { var fh = getElementsByClassName('firstHeading')[0]; var sp = getElementsByClassName('subpages')[0]; var ss = document.getElementById('siteSub'); fh.style.display = ss.style.display = 'none'; if(sp) sp.style.display = 'none'; } }

function getElementsByClassName(classname) { lst = document.getElementsByTagName('*'); newlst = new Array; i = 0; for (i=0; i < lst.length; i++) { if(lst[i].className == classname) newlst.push(lst[i]); } return newlst; }

addLoadEvent(killTitle);

/*  onglets /* Carica le icone SAL accanto a testo e modifica discussione in fonte */ function onglets {  //first tab var a = document.getElementById("ca-nstab-main"); if(a){ a = a.firstChild; var s = a.innerHTML; if( document.getElementById("Autore") ) {                 a.innerHTML = s.substring(0,i)+"Autore"+s.substring(i+5,s.length-1); }         q = document.getElementById("textquality") if( q ) { var image = ""; if( q.className == "00%") { image = " "; } if( q.className == "25%") { image = " "; } if( q.className == "50%") { image = " "; } if( q.className == "75%") { image = " "; } if( q.className == "100%") { image = " "; } if( q.className == "101%") { image = " "; } if( q.className == "Edizioni Wikisource") { image = " "; } a.innerHTML = s+image; }      }      if( document.getElementById("infoedit") ) {            var b = document.getElementById("ca-talk"); if(b){ var s = b.innerHTML; var i = s.lastIndexOf('Discussione'); b.innerHTML = s.substring(0,i)+"Fonte"+s.substring(i+11,s.length-1); }        } } addOnloadHook(onglets);

/*   PageQuality

function pageQuality { for(        var i=0;          spanElem = document.getElementsByTagName("span")[i];          i++      ) { if (spanElem.className == "pagequality") { t = spanElem.title; var new_img = document.createElement("img"); new_img.setAttribute("src", "/wiki/Special:Filepath/"+t.substring(0,t.length-1)+'%25.png'); new_img.setAttribute("title", "/wiki/Special:Filepath/"+t.substring(0,t.length-1)+'%25.png');

if(wgPageName.substring(0,7) == "Pagina:") { a = document.getElementById("ca-nstab-main"); if(a) a.firstChild.appendChild(new_img); }           else { s1 = spanElem.parentNode.previousSibling; opttext = s1.firstChild.firstChild; img = opttext.firstChild.nextSibling.nextSibling.nextSibling; next = img.nextSibling; opttext.removeChild(img); opttext.insertBefore(new_img,next); }     }   } }

addOnloadHook(pageQuality);

/*  interwikiExtra /* Carica i collegamenti alle versioni straniere ed alternative*/ function interwikiExtra {  // iterate over all -elements for(var i=0; a = document.getElementsByTagName("span")[i]; i++) { // if found a linkInfo span if(a.className == "interwiki-info") { // iterate over all -elements var count=0; for(var j=0; b = document.getElementsByTagName("li")[j]; j++) { if(b.className == "interwiki-" + a.id) { b.innerHTML = b.innerHTML + " "+a.title; if(a.title == "(vo)") { b.title = "Testo originale"; } }        else if(b.className == "interwiki-" + a.id.substr(0,a.id.length-1)) { count = count+1; if(a.id.charAt(a.id.length-1) == count) { b.innerHTML = b.innerHTML + " "+a.title; }           }         }      }      if(a.className == "AltraVersione") { p = a.title.indexOf("|"); pvers = document.getElementById("p-version"); if (pvers == null) { c = document.getElementById("column-one"); c.innerHTML = c.innerHTML + "" + " Altre versioni " + "" + "" + "" + " ";            pvers = document.getElementById("p-version"); }          e = pvers.getElementsByTagName("ul")[0]; e.innerHTML = e.innerHTML + "" + a.title.substr(p+1,a.title.length-1)+ " " +"</li>" }  } }

addOnloadHook(interwikiExtra);

/*   BilingualLink /* Permette il confronto tra pagine di lingue diverse */ function BilingualLink {   if( wgNamespaceNumber != 0) return; var doc_url = document.URL; var url = ''; // iterate over all <li>-elements for(var j=0; b = document.getElementsByTagName("li")[j]; j++) { if(b.className.substring(0,10) == "interwiki-" ) { var lang = b.className.substring(10,b.className.length); if( doc_url.indexOf('?title=') != -1 ) { var qm = doc_url.indexOf('&match='); if( qm != -1 ) url = doc_url.substring(0,qm)+"&match="+lang; else url = doc_url+"&match="+lang; } else { var qm = doc_url.indexOf('?'); if( qm != -1 ) url = doc_url.substring(0,qm)+"?match="+lang; else url = doc_url+"?match="+lang; }              b.innerHTML = b.innerHTML+" &hArr;</a>"; }        } }

addOnloadHook(BilingualLink);

/*   Options d'affichage Voir Modèle:Option. Auteur:ThomasV //Cookies function SetCookie(name,value) { document.cookie = name + "=" + escape(value); } function GetCookie(name) { var i =0; while (i < document.cookie.length) { if (document.cookie.substr(i,name.length) == name) { var valend = document.cookie.indexOf(";",i+name.length+1); if (valend == -1) { valend = document.cookie.length; }                       return unescape(document.cookie.substring(i+name.length+1,valend)); }               i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } } function OptionText { var indexNavigationBar = 0; // iterate over all -elements until class "OptionText" is found for(          var i=0;            SpanElem = document.getElementsByTagName("span")[i];            i++       ) { // if found an option span if (SpanElem.className == "OptionText") { //SpanElem.style.display = 'none'; OptionTitle = SpanElem.title; OptionStyle = SpanElem.firstChild.getAttribute('style'); //check if option was already encountered... if(!document.getElementById(OptionTitle)){ //read cookie var DisplayOptionDefault = true; CookieDisplayOption = GetCookie ("Display"+OptionTitle) if (CookieDisplayOption ) { if (CookieDisplayOption == "false") DisplayOptionDefault = false; } var PageDisplay = document.createElement("li"); PageDisplay.setAttribute('id', OptionTitle); var PageDisplayLink = document.createElement("a"); OptionText = document.createTextNode("Désactiver "+OptionTitle); PageDisplayLink.appendChild(OptionText); PageDisplayLink.setAttribute('href','javascript:displayOptionText("'+OptionTitle+'","' + OptionStyle +'", '+DisplayOptionDefault+');'); PageDisplay.appendChild(PageDisplayLink); var optlist = document.getElementById("optlist"); if(!optlist) { var displayOptions = document.createElement("div"); displayOptions.style.marginTop = "0.7em"; displayOptions.innerHTML = ' opzioni di visualizzazione<\/h5> </ul><\/div>'; document.getElementById("p-tb").appendChild(displayOptions); optlist = document.getElementById("optlist"); }           optlist.appendChild(PageDisplay); displayOptionText(OptionTitle,OptionStyle,DisplayOptionDefault); }      }   } } function displayOptionText(optiontitle, optionstyle, bool) { SetCookie ("Display"+optiontitle,bool); var PageDisplayLink = document.getElementById(optiontitle).firstChild;; // iterate over all -elements for(          var i=0;            SpanElem = document.getElementsByTagName("span")[i];            i++       ) { // if found an option text if ((SpanElem.className == "OptionText") && (SpanElem.title == optiontitle)) { if(bool==true ) { SpanElem.setAttribute('style',optionstyle); PageDisplayLink.firstChild.data = (optiontitle); PageDisplayLink.setAttribute('href', 'javascript:displayOptionText("'+optiontitle+'","'+optionstyle+'", false);'); }         if(bool==false) { SpanElem.setAttribute('style','null'); PageDisplayLink.firstChild.data = (optiontitle); PageDisplayLink.setAttribute('href', 'javascript:displayOptionText("'+optiontitle+'","'+optionstyle+'", true);'); }             }   } } addOnloadHook(OptionText); function loadImage(ImageSrc,id){ var d = document.getElementById(id); //if(d.firstChild){d.removeChild(d.firstChild);} d.firstChild.setAttribute('href', 'javascript:hideImage("'+ImageSrc+'", "'+id+'");'); d.firstChild.setAttribute('title', 'cacher'); d.firstChild.innerHTML='[-]'; var newimg = document.createElement("img"); //newimg.setAttribute("src", "/wiki/Special:Filepath/"+ImageSrc.substring(6)); newimg.setAttribute("src", "/w/thumb.php?f="+ImageSrc.substring(6)+"&w=650"); newimg.setAttribute("alt", "image not found : "+ImageSrc.substring(6)); newimg.setAttribute("id", "img2"); d.appendChild(newimg); } function hideImage(ImageSrc,id){ var d = document.getElementById(id); d.firstChild.setAttribute('href', 'javascript:loadImage("'+ImageSrc+'", "'+id+'");'); d.firstChild.setAttribute('title', 'montrer'); d.firstChild.innerHTML='[+]'; d.removeChild(d.lastChild); } function onclickImages { // iterate over all -elements for(          var i=0;            spanElem = document.getElementsByTagName("span")[i];            i++       ) { if (spanElem.className == "onclickImage") { spanElem.setAttribute('id', 'onclick'+i); title = spanElem.firstChild.getAttribute('title'); spanElem.firstChild.setAttribute('href', 'javascript:loadImage("'+title+'", "onclick'+i+'");'); spanElem.firstChild.innerHTML='[+]'; spanElem.firstChild.setAttribute('title', 'montrer'); }  } } addOnloadHook(onclickImages);

/*   linkUploadToCommons /* Genera il collegamento diretto alla pagina di upload di Commons nel menu di sinistra */ function linkUploadToCommons {   if (document.getElementById("carrega-para-commons")) return; var li_carrega = document.getElementById("t-upload"); if (!li_carrega) return; var afegit = li_carrega.nextSibling; var ul_eines = li_carrega.parentNode; var li = document.createElement("li"); li.id = "carrega-para-commons"; li.innerHTML = 'Carica su Commons</a>'; if (afegit) ul_eines.insertBefore(li, afegit); else ul_eines.appendChild(li); }

addOnloadHook(linkUploadToCommons);

/*    NavigationBar /* Gestisce i menu a scomparsa */ // set up the words in your language var NavigationBarHide = '▲ Nascondi'; var NavigationBarShow = '▼ Espandi';

// set up max count of Navigation Bars on page, // if there are more, all will be hidden // NavigationBarShowDefault = 0; // all bars will be hidden // NavigationBarShowDefault = 1; // on pages with more than 1 bar all bars will be hidden var NavigationBarShowDefault = 0;

// shows and hides content and picture (if available) of navigation bars // Parameters: //    indexNavigationBar: the index of navigation bar to be toggled function toggleNavigationBar(indexNavigationBar) {  var NavToggle = document.getElementById("NavToggle" + indexNavigationBar); var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);

if (!NavFrame || !NavToggle) { return false; }

// if shown now if (NavToggle.firstChild.data == NavigationBarHide) { for (              var NavChild = NavFrame.firstChild;               NavChild != null;               NavChild = NavChild.nextSibling           ) { if (NavChild.className == 'NavPic') { NavChild.style.display = 'none'; }          if (NavChild.className == 'NavContent') { NavChild.style.display = 'none'; }          if (NavChild.className == 'NavToggle') { NavChild.firstChild.data = NavigationBarShow; }      }

// if hidden now } else if (NavToggle.firstChild.data == NavigationBarShow) { for (              var NavChild = NavFrame.firstChild;               NavChild != null;               NavChild = NavChild.nextSibling           ) { if (NavChild.className == 'NavPic') { NavChild.style.display = 'block'; }          if (NavChild.className == 'NavContent') { NavChild.style.display = 'block'; }          if (NavChild.className == 'NavToggle') { NavChild.firstChild.data = NavigationBarHide; }      }   } }

// adds show/hide-button to navigation bars function createNavigationBarToggleButton {  var indexNavigationBar = 0; // iterate over all -elements for(          var i=0;            NavFrame = document.getElementsByTagName("div")[i];            i++       ) { // if found a navigation bar if (NavFrame.className == "NavFrame") {

indexNavigationBar++; var NavToggle = document.createElement("a"); NavToggle.className = 'NavToggle'; NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar); NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');

var NavToggleText = document.createTextNode(NavigationBarHide); NavToggle.appendChild(NavToggleText);

// add NavToggle-Button as first div-element // in           NavFrame.insertBefore(               NavToggle,               NavFrame.firstChild           ); NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar); }  }   // if more Navigation Bars found than Default: hide all if (NavigationBarShowDefault < indexNavigationBar) { for(              var i=1;                i<=indexNavigationBar;                i++       ) { toggleNavigationBar(i); }  }

}

aOnloadFunctions[aOnloadFunctions.length] = createNavigationBarToggleButton;

/*   Edittools /* Genera i menu a tendine nella sezione di modifica delle pagine. L'ordine della lista deve corrispondere a quello di MediaWiki:Edittools ! */ function addCharSubsetMenu { var specialchars = document.getElementById('specialchars');

if (specialchars) { var menu = "<select style=\"display:inline\" onChange=\"chooseCharSubset(selectedIndex)\">"; menu += " Simboli "; menu += " Latino esteso "; menu += " Greco antico "; menu += " Greco moderno "; menu += " Cirillico "; menu += " Arabo "; menu += " Ebraico e yiddish "; menu += " Armeno "; menu += " Geroglifico "; menu += " Vietnamita "; menu += " IPA "; menu += " Matematica "; menu += " "; specialchars.innerHTML = menu + specialchars.innerHTML;

/* default subset - try to use a cookie some day */ chooseCharSubset(0); } }

/* select subsection of special characters */ function chooseCharSubset(s) { var l = document.getElementById('specialchars').getElementsByTagName('p'); for (var i = 0; i < l.length ; i++) { l[i].style.display = i == s ? 'inline' : 'none'; l[i].style.visibility = i == s ? 'visible' : 'hidden'; } }

addOnloadHook(addCharSubsetMenu);

/* Gestisce i collegamenti interprogetto */ document.write('<style type="text/css">#interProject {display: none; speak: none;} #p-tb .pBody {padding-right: 0;}<\/style>'); function iProject { if (document.getElementById("interProject")) { var iProject = document.getElementById("interProject").innerHTML; var interProject = document.createElement("div"); interProject.style.marginTop = "0.7em"; interProject.innerHTML = ' altri progetti<\/h5> '+iProject+'<\/div>'; document.getElementById("p-tb").appendChild(interProject); } } hookEvent("load", iProject);