MediaWiki:Common.js

Da Cathopedia, l'enciclopedia cattolica.
Vai alla navigazione Vai alla ricerca

Nota: Dopo aver salvato le preferenze, perché i cambi abbiano effetto, devi bypassare la cache del tuo browser. Mozilla / Firefox / Safari: tieni premuto Shift mentre clicchi Reload, o premi Ctrl-Shift-R (Cmd-Shift-R per Apple Mac); Google Chrome: premi Ctrl o Shift mentre clicchi F5; IE: premi Ctrl mentre clicchi Refresh, o premi Ctrl-F5; Konqueror:: clicca semplicemente il pulsante di Reload, o premi F5; se usi Opera devi cancellare completamente la chache nel menu Tools→Preferences.

/* Il codice JavaScript inserito qui viene caricato da ciascuna pagina, per tutti gli utenti. */

/* <pre> */

//============================================================
// Menu caratteri speciali
// ---> non so perché, ma se si inserisce qualcosa prima non funziona più...
//============================================================

/**
 * Aggiunge il menu a tendina per selezionare un sottoinsieme di caratteri speciali
 * Attenzione:        l'ordine della lista deve corrispondere a quello di MediaWiki:Edittools !
 */
function aggiungiMenuSubsetCaratteri()
{
  var specialchars = document.getElementById('specialchars');

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

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

/* select subsection of special characters */
function scegliSubsetCaratteri(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';
  }
}

addLoadEvent(aggiungiMenuSubsetCaratteri);

// END Menu caratteri speciali

// BEGIN Enable multiple onload functions

// setup onload functions this way:
// 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<aOnloadFunctions.length; _i++) {
      aOnloadFunctions[_i]();
    }
  }
}

// END Enable multiple onload functions


function addLoadEvent(func) 
{
  if (window.addEventListener) 
    window.addEventListener("load", func, false);
  else if (window.attachEvent) 
    window.attachEvent("onload", func);
}

// Serve per far funzionare il Cassetto2 con IE6.
if (window.attachEvent && !window.XMLHttpRequest)
{
    window.attachEvent(
        "onload",
        function()
        {
            var x=document.getElementById("bodyContent").getElementsByTagName("div");
            for (var i=0; i<x.length; i++) {
                    if (x[i].className != "HopFrame") continue;
                    var y=x[i].getElementsByTagName("div"); var j;
                    for (j=0; j<y.length; j++)
                            if (y[j].className == "HopContent") {x[i].hopContent = y[j]; break;}
                    if (j<y.length) {
                            x[i].onmouseover=function() { this.hopContent.style.display="block"; };
                            x[i].onmouseout=function() { this.hopContent.style.display="none"; };
                    }
            }
        }
    );
}

// BEGIN Dynamic Navigation Bars


/* Test if an element has a certain class **************************************
 *
 * Description: Uses regular expressions and caching for better performance.
 * Maintainers: User:Mike Dillon, User:R. Koot, User:SG
 */

var hasClass = (function () {
    var reCache = {};
    return function (element, className) {
        return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
    };
})();


// 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 (hasClass(NavChild, 'NavPic')) {
               NavChild.style.display = 'none';
           }
           if (hasClass(NavChild, 'NavContent')) {
               NavChild.style.display = 'none';
           }
           if (hasClass(NavChild, '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 (hasClass(NavChild, 'NavPic')) {
               NavChild.style.display = 'block';
           }
           if (hasClass(NavChild, 'NavContent')) {
               NavChild.style.display = 'block';
           }
           if (hasClass(NavChild, 'NavToggle')) {
               NavChild.firstChild.data = NavigationBarHide;
           }
       }
   }
}

// adds show/hide-button to navigation bars
function createNavigationBarToggleButton()
{
   var indexNavigationBar = 0;
   // iterate over all < div >-elements
   for(
           var i=0; 
           NavFrame = document.getElementsByTagName("div")[i]; 
           i++
       ) {
       // if found a navigation bar
       if (hasClass(NavFrame, '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 < div class="NavFrame" >
           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;

// END Dynamic Navigation Bars

	/**
	 * Utilizzata con [[template:Galleria]] per creare una galleria di immagini,
	 * cerca un HTML (creato dal template) contenente:
	 * <div class="ImageGroup"><div class="ImageGroupUnits">immagini</div></div>
	 * Idea originale da [[fr:MediaWiki:Common.js]] del 2007.
	 * @author [[it:User:Rotpunkt]]
	 */
	function updateImageGroup( currImg, $images, $countInfo, $prevLink, $nextLink ) {
		$images.hide().eq( currImg ).show();
		$countInfo.html( '(' + ( currImg + 1 ) + '/' + $images.length + ')' );
		$prevLink.toggle( currImg !== 0 );
		$nextLink.toggle( currImg !== $images.length - 1 );
	}

	function initImageGroup() {
		$( 'div.ImageGroup > div.ImageGroupUnits' ).each( function ( i, imageGroupUnits ) {
			var currImg = 0;
			var $images = $( imageGroupUnits ).children( '.center, .mw-halign-center' );
			var $countInfo = $( '<kbd>' ).css( 'font-size', '110%' );
			var $prevLink =	$( '<a>' )
				.attr( 'href', '#' ).attr( 'title', 'Immagine precedente' )
				.text( '◀' ).css( 'text-decoration', 'none' )
				.click( function ( e ) {
					e.preventDefault();
					updateImageGroup( currImg -= 1, $images, $countInfo, $prevLink, $nextLink );
				} );
			var $nextLink =	$( '<a>' )
				.attr( 'href', '#' ).attr( 'title', 'Immagine successiva' )
				.text( '▶' ).css( 'text-decoration', 'none' )
				.click( function ( e ) {
					e.preventDefault();
					updateImageGroup( currImg += 1, $images, $countInfo, $prevLink, $nextLink );
				} );
			updateImageGroup( currImg, $images, $countInfo, $prevLink, $nextLink );
			$( imageGroupUnits ).prepend( $prevLink, $countInfo, $nextLink );
		} );
	}

	$( initImageGroup );

/** Collapsible tables *********************************************************
 *
 *  Taken from http://en.wikipedia.org/wiki/MediaWiki:Common.js
 *  Description: Allows tables to be collapsed, showing only the header. See
 *               Wikipedia:NavFrame.
 *  Maintainers: User:R. Koot
 */

var autoCollapse = 2;
var collapseCaption = "▲ nascondi";
var expandCaption = "▼ espandi";

function collapseTable( tableIndex )
{
    var Button = document.getElementById( "collapseButton" + tableIndex );
    var Table = document.getElementById( "collapsibleTable" + tableIndex );

    if ( !Table || !Button ) {
        return false;
    }

    var Rows = Table.getElementsByTagName( "tr" ); 

    if ( Button.firstChild.data == collapseCaption ) {
        for ( var i = 1; i < Rows.length; i++ ) {
            Rows[i].style.display = "none";
        }
        Button.firstChild.data = expandCaption;
    } else {
        for ( var i = 1; i < Rows.length; i++ ) {
            Rows[i].style.display = Rows[0].style.display;
        }
        Button.firstChild.data = collapseCaption;
    }
}

function createCollapseButtons()
{
    var tableIndex = 0;
    var NavigationBoxes = new Object();
    var Tables = document.getElementsByTagName( "table" );

    for ( var i = 0; i < Tables.length; i++ ) {
        if ( hasClass( Tables[i], "collapsible" ) ) {
            NavigationBoxes[ tableIndex ] = Tables[i];
            Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );

            var Button     = document.createElement( "span" );
            var ButtonLink = document.createElement( "a" );
            var ButtonText = document.createTextNode( collapseCaption );

            Button.style.styleFloat = "right";
            Button.style.cssFloat = "right";
            Button.style.fontWeight = "normal";
            Button.style.textAlign = "right";
            Button.style.width = "7em";

            ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
            ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
            ButtonLink.appendChild( ButtonText );

            Button.appendChild( document.createTextNode( "[" ) );
            Button.appendChild( ButtonLink );
            Button.appendChild( document.createTextNode( "]" ) );

            var Header = Tables[i].getElementsByTagName( "tr" )[0].getElementsByTagName( "th" )[0];
            /* only add button and increment count if there is a header row to work with */
            if (Header) {
                Header.insertBefore( Button, Header.childNodes[0] );
                tableIndex++;
            }
        }
    }

    for ( var i = 0;  i < tableIndex; i++ ) {
        if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
            collapseTable( i );
        }
    }
}

$( createCollapseButtons );

//END Collapsible tables

//HIDDENCAT (mostra le categorie nascoste). Scippato ai francesi
function addClass(node, className)
{
    if (hasClass(node, className)) {
        return false;
    }
    node.className += ' '+ className;
    return true;
}

function eregReplace(search, replace, subject)
{
    return subject.replace(new RegExp(search,'g'), replace);
}

function removeClass(node, className)
{
  if (!hasClass(node, className)) {
    return false;
  }
  node.className = eregReplace('(^|\\s+)'+ className +'($|\\s+)', ' ', node.className);
  return true;
}

function isClass(element, classe)
{
    return hasClass(element, classe);
}

function hiddencat()
{
 var cl = document.getElementById('catlinks');           if(!cl) return;
 var hc = document.getElementById('mw-hidden-catlinks'); if(!hc) return;
 var nc = document.getElementById('mw-normal-catlinks');
 if(!nc)
 {
  removeClass(cl, 'catlinks-allhidden');
  addClass(cl, 'catlinks-allhidden-mostra');
  var ahc = '<div id="mw-normal-catlinks"><a href="/wiki/Categoria:Categorie" title="Categoria:Categorie">Categorie</a>&nbsp;:&#32;<span dir="ltr"><a onclick="javascript:toggleHiddenCats();" id="mw-hidden-cats-link" style="cursor:pointer; color:#002BB8;" title="Questa voce contiene categorie nascoste">[<span style="font-style:italic;">altre</span>]</a></span></div>';
  document.getElementById('catlinks').innerHTML = ahc + cl.innerHTML;
 }
 else if( isClass(hc, 'mw-hidden-cats-hidden') )
 {
  var ahc = ' | <a onclick="javascript:toggleHiddenCats();" id="mw-hidden-cats-link" style="cursor:pointer; color:#002BB8;" title="Questa voce contiene categorie nascoste">[<span style="font-style:italic;">altre</span>]</a>';
  document.getElementById('mw-normal-catlinks').innerHTML += ahc;
 }
}

function toggleHiddenCats()
{
 var hc = document.getElementById('mw-hidden-catlinks');
 if( isClass(hc, 'mw-hidden-cats-hidden') )
 {
  removeClass(hc, 'mw-hidden-cats-hidden');
  addClass(hc, 'mw-hidden-cat-user-shown');
  document.getElementById('mw-hidden-cats-link').innerHTML = '[<span style="font-style:italic;">nascondi</span>]';
 }
 else
 {
  removeClass(hc, 'mw-hidden-cat-user-shown');
  addClass(hc, 'mw-hidden-cats-hidden');
  document.getElementById('mw-hidden-cats-link').innerHTML = '[<span style="font-style:italic;">altre</span>]';
 }
}
 
$(hiddencat);

/* Layout pagina di modifica */
addLoadEvent ( function ()
{
  if (mw.config.get( 'wgAction' ) == "edit")
  {
    /* Allarga l'edittools a tutta pagina */
    document.getElementById("Standard").style.width = "100%";
  }
})

/* Avvisa quando si tenta di creare una voce con titolo non valido  ("Scrivi qui il titolo")*/
$ ( function ()
{
  if (mw.config.get( 'wgTitle' ) == "Scrivi qui il titolo" && wgAction == "edit")
  {
    dopoDi = document.getElementById("contentSub");
        if (!dopoDi) return;
    var daInserire = document.createElement('div');
    daInserire.innerHTML = "<b>Stai creando una pagina senza specificare un titolo valido per la voce. Per favore torna indietro e inserisci un titolo valido.</b>";
        daInserire.className = "toccolours itwiki_template_avviso rad";
        daInserire.style.marginBottom = "0.5em";
        daInserire.style.background = "#FC9";
        daInserire.style.borderColor = "red";
        daInserire.style.textAlign = "center";
        dopoDi.parentNode.insertBefore(daInserire, dopoDi.nextSibling);
  }
})

//============================================================
// Funzione per gestire i cookies

function SetCookie(cookieName,cookieValue,nDays)
{
        var today = new Date();
        var expire = new Date();
        if (nDays==null || nDays==0) nDays=1;
        expire.setTime(today.getTime() + 3600000*24*nDays);
        document.cookie = cookieName+"="+escape(cookieValue)
                          + ";expires="+expire.toGMTString();
}

function getCookie(c_name)
{
        var i,x,y,ARRcookies=document.cookie.split(";");
        for (i=0;i<ARRcookies.length;i++)
        {
                x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
                y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
                x=x.replace(/^\s+|\s+$/g,"");
                if (x==c_name)
                {
                        return unescape(y);
                }
        }
}

//============================================================
// Funzione per la variazione della dimensione del font

function resizeText(multiplier, boolPulsante)
{

  var coockieNameMultiplier = "CathopediaMultiplier";  
  var Correction = 10;
  var bodyContent = document.getElementById("mw-content-text");
  var cookieValueNewText;

  cookieValue = parseFloat(bodyContent.style.fontSize) * 100 / Correction;
  if (! cookieValue)
    cookieValue = parseFloat(getCookie(coockieNameMultiplier));
  if (! cookieValue)
    cookieValue = 100;

  var cookieValueNew = Math.round(cookieValue * multiplier / 100 / 5) * 5;
  if (cookieValueNew < 50)
    cookieValueNew = 50;
  if (cookieValueNew > 200)
    cookieValueNew = 200;
  if (! multiplier || ( mw.config.get( "wgNamespaceNumber" ) && mw.config.get( "wgNamespaceNumber" ) !== 4 ) )
    cookieValueNew = 100;
  bodyContent.style.fontSize = (cookieValueNew * Correction / 100) + "pt";
  cookieValueNewText = cookieValueNew.toString();

  if (boolPulsante)
    SetCookie(coockieNameMultiplier, cookieValueNewText, 1000);

  //if (cookieValue < 100)
    //cookieValue = "<span style='color: white'>0</span>" + cookieValue;

  textPerCentElement = document.getElementById("textpercent");  
  if (textPerCentElement)
    textPerCentElement.innerText = cookieValueNew + "%";

}

window.onload(resizeText(100, false));

if (document.getElementById('selettoreriti'))
{
        // funzioni per scambiare i riti romano e ambrosiano in pagina principale
        function AttivaRomano()
        {
          //~ document.getElementById('selettoreambrosiano').style.display = '';
          //~ document.getElementById('selettoreromano').style.display = 'none';
          document.getElementById('ambrosiano').style.display = 'none';
          document.getElementById('romano').style.display = '';
          document.getElementById('selettoreromano').className = 'BottoneSelettoreRitoSelezionato';
          document.getElementById('selettoreambrosiano').className = 'BottoneSelettoreRitoNonSelezionato';
          document.getElementById('selettoreambrosiano').title = 'Passa al Rito Ambrosiano';
          document.getElementById('selettoreromano').title = '';
          SetCookie('rito', '', 1000);
          document.getElementById('selettoreambrosiano').onclick = AttivaAmbrosiano;
          document.getElementById('selettoreromano').onclick = null;
        }

        function AttivaAmbrosiano()
        {
          //~ document.getElementById('selettoreambrosiano').style.display = 'none';
          //~ document.getElementById('selettoreromano').style.display = '';
          document.getElementById('ambrosiano').style.display = '';
          document.getElementById('romano').style.display = 'none';
          document.getElementById('selettoreromano').className = 'BottoneSelettoreRitoNonSelezionato';
          document.getElementById('selettoreambrosiano').className = 'BottoneSelettoreRitoSelezionato';
          document.getElementById('selettoreambrosiano').title = '';
          document.getElementById('selettoreromano').title = 'Passa al Rito Romano';
          SetCookie('rito', 'ambrosiano', 1000);
          document.getElementById('selettoreromano').onclick = AttivaRomano;
          document.getElementById('selettoreambrosiano').onclick = null;
        }


        if ( getCookie('rito') == 'ambrosiano')
                AttivaAmbrosiano();
        else
                AttivaRomano();
}

document.getElementById('textminus').onclick = function(){resizeText(90, true);}
document.getElementById('textstandard').onclick = function(){resizeText(0, true);}
document.getElementById('textplus').onclick = function(){resizeText(111, true);}


//////////////////////////////////////////////////////////
// codice per far funzionare i popup della bibbia
//////////////////////////////////////////////////////////

function occurrences(string, word)
{
   var substrings = string.split(word);
   return substrings.length - 1;
}

function prepara_popup(citazione)
{
    // funzione usata per manipolare il foglio di stile
    var sheet = (function()
    {
     // Create the <style> tag
     var style = document.createElement("style");

     // Add a media (and/or media query) here if you'd like!
     // style.setAttribute("media", "screen")
     // style.setAttribute("media", "only screen and (max-width : 1024px)")

     // WebKit hack :(
     style.appendChild(document.createTextNode(""));

     // Add the <style> element to the page
     document.head.appendChild(style);

     return style.sheet;
    })();
	
    citazione = citazione.replace(' ', '+');
    //var url = 'https://bibbia.qumran2.net/index.php?debug=1&CiteButton=Estrai&Popup=1&Cite=' + citazione;
    var url = 'https://bibbia.qumran2.net/index.php?CiteButton=Estrai&Popup=1&Cite=' + citazione;
    //var url = '/index.php?CiteButton=Estrai&Popup=1&Cite=' + citazione;
    
    //var testo= loadXMLDoc(url);
    
    var pageRequest = false //variable to hold ajax object

    if (!pageRequest && typeof XMLHttpRequest != 'undefined')
    {
       pageRequest = new XMLHttpRequest();
    }
     
    if (pageRequest)
    {
        //if pageRequest is not false
        pageRequest.open('GET', url, false); //get page synchronously

        pageRequest.onload = function (e)
        {
            if (pageRequest.readyState === 4)
            {
                if (pageRequest.status === 200)
                {
                    var testo = pageRequest.responseText;
                }
                else
                {
                    console.error(pageRequest.statusText);
                }
            }
        }

        pageRequest.onerror = function (e)
        {
            console.error(pageRequest.statusText);
        }
       
        pageRequest.send(null);
    }

    testo = pageRequest.responseText;

    var BoolSenzaNumeroCapitolo = false;
    if (occurrences(testo, 'LibroVersetti') == 1)
    {
        // togli la citazione iniziale
        var iniziopartedatogliere = testo.search('<div class=\'LibroVersetti\'>');
        var testoemendato = testo.substring(0, iniziopartedatogliere);
        testo = testo.substr(iniziopartedatogliere);
        var marcatorefine = '</div>';
        finepartedatogliere = testo.search(marcatorefine) + marcatorefine.length;
        testoemendato = testoemendato + testo.substring(finepartedatogliere);
        testo = testoemendato;
    }

    if (occurrences(testo, '<span class=\'ChapterNumber') == 1)
    {
        // la citazione abbraccia solo un capitolo, tolgo il numero di capitolo
        BoolSenzaNumeroCapitolo = true;
        iniziopartedatogliere = testo.search('<span class=\'ChapterNumber');
        testoemendato = testo.substring(0, iniziopartedatogliere);
        testo = testo.substr(iniziopartedatogliere);
        marcatorefine = '</span>';
        finepartedatogliere = testo.search(marcatorefine) + marcatorefine.length;
        testoemendato = testoemendato + testo.substring(finepartedatogliere);
        testo = testoemendato;
    }

    // guardo la lunghezza delle linee per determinare la larghezza migliore
    var posizionePrimoVersetto = testo.search('<sup>');
    var testoVersetti = testo.substr(posizionePrimoVersetto);
    var posizioneCopyright = testoVersetti.search("<div class='bq_Copyright'");
    if (posizioneCopyright == -1)
    {
      posizioneCopyright = testoVersetti.search("<div class='Copyright'");
    }
    if (posizioneCopyright == -1)
    {
       posizioneCopyright = testoVersetti.length;
    }
    testoVersetti = testoVersetti.substr(0, posizioneCopyright);

    var testosenzahtml = testoVersetti.replace(/<\/p>/gm, "\n");
    testosenzahtml = testosenzahtml.replace(/<(?:.|\n)*?>/gm, '');

    var arrayOfLines = testosenzahtml.match(/[^\r\n]+/g);
    var maxLength = 0;
    var arrayLength = arrayOfLines.length;
    var lineLength = 0;
    for (var i = 0; i < arrayLength; i++)
    {
        if (arrayOfLines[i].length > maxLength)
        {
            lineLength = arrayOfLines[i].length; 
            maxLength = lineLength;
        }
    }
    var l = testosenzahtml.length;
    var wmin = 200;
    if (testoVersetti.search('SeparatedVersicle') >= 0)
    {
        if (testoVersetti.search('EbraicLetter') >= 0)
        {
            wmin = 380;
            if (BoolSenzaNumeroCapitolo)
            {
		sheet.insertRule(".EbraicLetter      { margin-left:   0em !important; }", 0);
		sheet.insertRule(".SeparatedVersicle { margin-left: 3.5em !important; }", 0);
		sheet.insertRule(".leftContinue      { margin-left: 6.8em !important; }", 0);
		sheet.insertRule(".left              { margin-left: 6.8em !important; }", 0);
            }
        }
        else
        {
            wmin = 280;
            if (BoolSenzaNumeroCapitolo)
            {
              sheet.insertRule(".SeparatedVersicle { margin-left: 0     !important; }", 0);
              sheet.insertRule(".leftContinue      { margin-left: 3.3em !important; }", 0);
              sheet.insertRule(".left              { margin-left: 3.3em !important; }", 0);
            }
            else
            {
              sheet.insertRule(".SeparatedVersicle { margin-left: 3.7em !important; }", 0);
              sheet.insertRule(".leftContinue      { margin-left: 7.0em !important; }", 0);
              sheet.insertRule(".left              { margin-left: 7.0em !important; }", 0);
            }
        }
    }
    var wmax = window.innerWidth * 0.9;
    var lmin = 150; // lunghezza approssimata di un versetto
    var lmax = 5000; // lunghezza approssimata di un capitolo
    // determino l in maniera che passi per (lmin, wmin) e 
    
    w = (l - lmin) * (wmax - wmin) / (lmax - lmin) + wmin;
    w = Math.round(w);
    if(w < wmin) { w = wmin };
    if(w > wmax) { w = wmax };

    //AmpiezzaMax = maxLength * 3.5 + 80;
    AmpiezzaMax = Math.round(maxLength * 5.8 + 10);
    if(w > AmpiezzaMax || maxLength < 95 && w < AmpiezzaMax && AmpiezzaMax < wmax)
    {
       w = AmpiezzaMax;
    }

    return testo;
}

/*

--------------------------------------------------------------------------
Code for link-hover text boxes
By Nicolas Höning
Usage: <a onmouseover="nhpup.popup('popup text' [, {'class': 'myclass', 'width': 300}])">a link</a>
The configuration dict with CSS class and width is optional - default is class .pup and width of 200px.
You can style the popup box via CSS, targeting its ID #pup. 
You can escape " in the popup text with &quot;.
Tutorial and support at http://nicolashoening.de?twocents&nr=8
--------------------------------------------------------------------------

The MIT License (MIT)

Copyright (c) 2014 Nicolas Höning

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

nhpup = {

    pup: null,      // This is the popup box, represented by a div    
    identifier: "pup",  // Name of ID and class of the popup box
    minMargin: 15,  // Set how much minimal space there should be (in pixels)
                    // between the popup and everything else (borders, mouse)
    default_width: 200, // Will be set to width from css in document.ready
    move: false,   // Move it around with the mouse? we are only ready for that when the mouse event is set up.
                   // Besides, having this turned off initially is resource-friendly.

    /*
     Write message, show popup w/ custom width if necessary,
      make sure it disappears on mouseout
    */
    popup: function(p_msg, p_config)
    {
        // do track mouse moves and update position 
        this.move = true;
        // restore defaults
        this.pup.removeClass()
                .addClass(this.identifier)
                .width(this.default_width);

        // custom configuration
        if (typeof p_config != 'undefined') {
            if ('class' in p_config) {
                this.pup.addClass(p_config['class']);
            }
            if ('width' in p_config) {
                this.pup.width(p_config['width']);
            }
        }

        // Write content and display
        this.pup.html(p_msg).show();

        // Make sure popup goes away on mouse out and we stop the constant 
        //  positioning on mouse moves.
        // The event obj needs to be gotten from the virtual 
        //  caller, since we use onmouseover='nhpup.popup(p_msg)' 
        var t = this.getTarget(arguments.callee.caller.arguments[0]);
        $jq(t).unbind('mouseout').bind('mouseout', 
            function(e){
                nhpup.pup.hide();
                nhpup.move = false;
            }
        );
    },

    // set the target element position
    setElementPos: function(x, y)
    {
        // Call nudge to avoid edge overflow. Important tweak: x+10, because if
        //  the popup is where the mouse is, the hoverOver/hoverOut events flicker
        var x_y = this.nudge(x + 10, y);
        // remember: the popup is still hidden
        this.pup.css('top', x_y[1] + 'px')
                .css('left', x_y[0] + 'px');
    },

    /* Avoid edge overflow */
    nudge: function(x,y)
    {
        var win = $jq(window);

        // When the mouse is too far on the right, put window to the left
        var xtreme = $jq(document).scrollLeft() + win.width() - this.pup.width() - this.minMargin;
        if(x > xtreme) {
            x -= this.pup.width() + 2 * this.minMargin;
        }
        x = this.max(x, 0);

        // When the mouse is too far down, move window up
        if((y + this.pup.height()) > (win.height() +  $jq(document).scrollTop())) {
            y -= this.pup.height() + this.minMargin;
        }

        return [ x, y ];
    },

    /* custom max */
    max: function(a,b)
    {
        if (a>b) return a;
        else return b;
    },

    /*
     Get the target (element) of an event.
     Inspired by quirksmode
    */
    getTarget: function(e)
    {
        var targ;
        if (!e) var e = window.event;
        if (e.target) targ = e.target;
        else if (e.srcElement) targ = e.srcElement;
        if (targ.nodeType == 3) // defeat Safari bug
            targ = targ.parentNode;
        return targ;
    },

    onTouchDevice: function() 
    {
        var deviceAgent = navigator.userAgent.toLowerCase();
        return deviceAgent.match(/(iphone|ipod|ipad|android|blackberry|iemobile|opera m(ob|in)i|vodafone)/) !== null;
    },
    
    initialized: false,
    initialize : function(){
        if (this.initialized) return;

        window.$jq = jQuery; // this is safe in WP installations with noConflict mode (which is default)

        /* Prepare popup and define the mouseover callback */
        jQuery(document).ready(function () {
            // create default popup on the page
            $jq('body').append('<div id="' + nhpup.identifier + '" class="' + nhpup.identifier + '" style="position:absolute; display:none; z-index:200;"></div>');
            nhpup.pup = $jq('#' + nhpup.identifier);

            // set dynamic coords when the mouse moves
            $jq(document).mousemove(function (e) {
                if (!nhpup.onTouchDevice()) { // turn off constant repositioning for touch devices (no use for this anyway)
                    if (nhpup.move) {
                        nhpup.setElementPos(e.pageX, e.pageY);
                    }
                }
            });
        });

        this.initialized = true;
    }
}

if ('jQuery' in window) nhpup.initialize();

//////////////////////////////////////////////////////////
// fine codice per far funzionare i popup della bibbia
//////////////////////////////////////////////////////////

//============================================================
// Funzione di prova

jQuery( document ).ready(function() {
  //una volta caricato il DOM esegui questo codice
  console.log( "DOM ready!" );
  jQuery(window).load(function() {
    //una volta caricata l'intera pagina (immagini e i frames..) esegui questo codice
    console.log( "Page ready!" );
    //faccio scomparire l'immagine di caricamento
    jQuery(".loader").fadeOut("slow");
  });
});

/* Normalizzazione dei caratteri particolari per l'ordinamento alfabetico nelle tabelle sortable.
   In futuro potrebbe diventare default e non più necessario, vedi [[phab:T72157]] */

mw.config.set( 'tableSorterCollation', {'á':'a','à':'a','ă':'a','â':'a','ǎ':'a','å':'a','ä':'a','ã':'a','ā':'a','ȁ':'a',
'Á':'A','À':'A','Ă':'A','Â':'A','Ǎ':'A','Å':'A','Ä':'A','Ã':'A','Ā':'A','Ȁ':'A',
'ć':'c','ĉ':'c','č':'c','ç':'c',
'Ć':'C','Ĉ':'C','Č':'C','Ç':'C',
'đ':'d','ð':'d',
'Đ':'D','Ð':'D',
'é':'e','è':'e','ê':'e','ě':'e','ë':'e','ẽ':'e','ȩ':'e','ę':'e','ē':'e','ȅ':'e','ė':'e',
'É':'E','È':'E','Ê':'E','Ě':'E','Ë':'E','Ẽ':'E','Ȩ':'E','Ę':'E','Ē':'E','Ȅ':'E','Ė':'E',
'ǵ':'g','ğ':'g','ĝ':'g','ǧ':'g',
'Ǵ':'G','Ğ':'G','Ĝ':'G','Ǧ':'G',
'í':'i','ì':'i','ĭ':'i','î':'i','ǐ':'i','ï':'i','ĩ':'i','ī':'i','ȉ':'i',
'Í':'I','Ì':'I','Ĭ':'I','Î':'I','Ǐ':'I','Ï':'I','Ĩ':'I','Ī':'I','Ȉ':'I',
'ľ':'l','ł':'l',
'Ľ':'L','Ł':'L',
'ń':'n','ǹ':'n','ň':'n','ñ':'n',
'Ń':'N','Ǹ':'N','Ň':'N','Ñ':'N',
'ó':'o','ò':'o','ŏ':'o','ô':'o','ǒ':'o','ö':'o','ő':'o','õ':'o','ø':'o','ō':'o','ȍ':'o',
'Ó':'O','Ò':'O','Ŏ':'O','Ô':'O','Ǒ':'O','Ö':'O','Ő':'O','Õ':'O','Ø':'O','Ō':'O','Ȍ':'O',
'ŕ':'r','ř':'r',
'Ŕ':'R','Ř':'R',
'ś':'s','ṥ':'s','ŝ':'s','š':'s','ş':'s','ș':'s',
'Ś':'S','Ṥ':'S','Ŝ':'S','Š':'S','Ş':'S','Ș':'S',
'ţ':'t','ț':'t',
'Ţ':'T','Ț':'T',
'ú':'u','ù':'u','ŭ':'u','û':'u','ǔ':'u','ü':'u','ű':'u','ũ':'u','ū':'u','ȕ':'u',
'Ú':'U','Ù':'U','Ŭ':'U','Û':'U','Ǔ':'U','Ü':'U','Ű':'U','Ũ':'U','Ū':'U','Ȕ':'U',
'ý':'y','ỳ':'y','ÿ':'y','ỹ':'y',
'Ý':'Y','Ỳ':'Y','Ÿ':'Y','Ỹ':'Y',
'ź':'z','ž':'z',
'Ź':'Z','Ž':'Z'} );