MediaWiki:Common.js: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
m tolgo funzione duplicata
 
(253 versioni intermedie di 28 utenti non mostrate)
Riga 1:
/**
/* Il codice JavaScript inserito qui viene caricato da ciascuna pagina, per tutti gli utenti. */
* Mantenere il codice di MediaWiki:Common.js il più breve possibile, in quanto è caricato
 
* da ciascuna pagina, per tutti gli utenti che navigano sulla versione desktop.
/* Serve per "sabotare" www.wikipedia.it e tutti gli altri siti che ci includono in frame. "Salta fuori" dai frame.
* Creare piuttosto accessori abilitati di default (gli accessori sono infatti moduli
Va alla pagina del toolserver il cui contenuto è preso dalla pagina [[Utente:Pietrodn/www.wikipedia.it]], modificabile solo dagli admin.
* ottimizzati del ResourceLoader con la possibilità di aggiungere dipendenze, ecc.).
Poi reindirizza a http://it.wikipedia.org */
if (wgTitle == "Pagina principale" && top !=self) top.___location.replace('http://toolserver.org/~pietrodn/wikipedia_redirect.php');
 
//DEPRECATO
function addLoadEvent(func)
{
if (window.addEventListener)
window.addEventListener("load", func, false);
else if (window.attachEvent)
window.attachEvent("onload", func);
}
 
/*** RICERCA ***/
/**
*******************************************************
*
* Descrizione: Cambia Speciale:Ricerca per usare un menu' a
* tendina, con come default il motore interno di MediaWiki
*
* Creato e gestito da: [[:en:User:Gracenotes]]
* Importato in it.wiki da: [[Utente:Jalo]]
*/
if (wgPageName == "Speciale:Ricerca") {
var searchEngines = [];
addOnloadHook(SpecialSearchEnhanced);
}
function SpecialSearchEnhanced() {
var createOption = function(site, action, mainQ, addQ, addV) {
var opt = document.createElement('option');
opt.appendChild(document.createTextNode(site));
searchEngines[searchEngines.length] = [action, mainQ, addQ, addV];
return opt;
}
if (document.forms['powersearch'])
var searchForm = document.forms['powersearch'];
if (document.forms['search'])
var searchForm = document.forms['search'];
 
if (searchForm.lsearchbox) {
var searchBox = searchForm.lsearchbox;
} else {
var searchBox = searchForm.search;
}
 
var selectBox = document.createElement('select');
selectBox.id = 'searchEngine';
searchForm.onsubmit = function() {
var optSelected = searchEngines[document.getElementById('searchEngine').selectedIndex];
searchForm.action = optSelected[0];
searchBox.name = optSelected[1];
searchForm.title.value = optSelected[3];
searchForm.title.name = optSelected[2];
}
selectBox.appendChild(createOption('MediaWiki', wgScriptPath + '/index.php', 'search', 'title', 'Speciale:Ricerca'));
selectBox.appendChild(createOption('Google', 'http://www.google.com/search', 'q', 'sitesearch', 'it.wikipedia.org'));
selectBox.appendChild(createOption('Yahoo', 'http://search.yahoo.com/search', 'p', 'vs', 'it.wikipedia.org'));
selectBox.appendChild(createOption('Windows Live', 'http://search.live.com/results.aspx', 'q', 'q1', 'site:http://it.wikipedia.org'));
selectBox.appendChild(createOption('Wikiwix', 'http://it.wikiwix.com/', 'action', 'lang', 'it'));
selectBox.appendChild(createOption('Exalead', 'http://www.exalead.com/wikipedia/results', 'q', 'language', 'it'));
 
searchBox.style.marginLeft = '0px';
// 'searchText' is the firt search text. 'powerSearchText' is the second, used only if the first is not existent (e.g.: not yet done any search)
buttonSearch=document.getElementById('searchText');
if (buttonSearch)
buttonSearch.parentNode.insertBefore(selectBox, buttonSearch.nextSibling);
else
{
buttonSearch=document.getElementById('powerSearchText');
buttonSearch.parentNode.insertBefore(selectBox, buttonSearch.nextSibling);
}
}
 
// 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
*/
/* global mediaWiki, jQuery */
 
var hasClass = ( function ( mw, $ ) {
'use strict';
var reCache = {};
return function (element, className) {
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
};
})();
 
// ============================
// Caricamento script
// ============================
 
/**
// set up the words in your language
* Ricerca in Wikidata
var NavigationBarHide = '▲ nascondi';
*/
var NavigationBarShow = '▼ espandi';
if (
mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' ||
( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgCanonicalSpecialPageName' ) === false )
) {
mw.loader.load( '//en.wikipedia.org/w/index.php?title=MediaWiki:Wdsearch.js&action=raw&ctype=text/javascript' );
}
 
// ============================
// set up max count of Navigation Bars on page,
// Modifica HTML pagine
// 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;
 
/**
* Aggiunge un combobox a [[MediaWiki:Edittools]] per selezionare un gruppo di caratteri speciali.
*/
function comboboxEdittools() {
var $specialChars = $( '#specialchars' );
if ( $specialChars.length ) {
var $select = $( '<select>' ).change( function () {
$specialChars.find( 'p' ).hide();
$specialChars.find( 'option:selected' ).data().show();
} );
$specialChars.find( 'p' ).each( function () {
$( '<option>' ).html( $( this ).attr( 'id' ).replace( /_/g, ' ' ) )
.data( $( this ) ).appendTo( $select );
} );
$specialChars.prepend( $select );
$select.change();
}
}
 
$( comboboxEdittools );
// 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) {
// Supporto ai template
return false;
// ============================
}
 
/**
// if shown now
* Utilizzata con [[template:Galleria]] per creare una galleria di immagini,
if (NavToggle.firstChild.data == NavigationBarHide) {
* cerca un HTML (creato dal template) contenente:
for (
* <div class="ImageGroup"><div class="ImageGroupUnits">immagini</div></div>
var NavChild = NavFrame.firstChild;
* Idea originale da [[fr:MediaWiki:Common.js]] del 2007.
NavChild != null;
* @author [[it:User:Rotpunkt]]
NavChild = NavChild.nextSibling
*/
) {
function updateImageGroup( currImg, $images, $countInfo, $prevLink, $nextLink ) {
if (hasClass(NavChild, 'NavPic')) {
$images.hide().eq( currImg ).show();
NavChild.style.display = 'none';
$countInfo.html( '(' + ( currImg + 1 ) + '/' + $images.length + ')' );
}
$prevLink.toggle( currImg !== 0 );
if (hasClass(NavChild, 'NavContent')) {
$nextLink.toggle( currImg !== $images.length - 1 );
NavChild.style.display = 'none';
}
}
if (hasClass(NavChild, 'NavToggle')) {
NavChild.firstChild.data = NavigationBarShow;
}
}
 
function initImageGroup() {
// if hidden now
$( 'div.ImageGroup > div.ImageGroupUnits' ).each( function ( i, imageGroupUnits ) {
} else if (NavToggle.firstChild.data == NavigationBarShow) {
var currImg = 0;
for (
var $images = $( imageGroupUnits ).children( '.center, .mw-halign-center' );
var NavChild = NavFrame.firstChild;
var $countInfo = $( '<kbd>' ).css( 'font-size', '110%' );
NavChild != null;
var $prevLink = $( '<a>' )
NavChild = NavChild.nextSibling
.attr( 'href', '#' ).attr( 'title', 'Immagine precedente' )
) {
.text( '◀' ).css( 'text-decoration', 'none' )
if (hasClass(NavChild, 'NavPic')) {
.click( function ( e ) {
NavChild.style.display = 'block';
e.preventDefault();
}
updateImageGroup( currImg -= 1, $images, $countInfo, $prevLink, $nextLink );
if (hasClass(NavChild, 'NavContent')) {
} );
NavChild.style.display = 'block';
var $nextLink = $( '<a>' )
}
.attr( 'href', '#' ).attr( 'title', 'Immagine successiva' )
if (hasClass(NavChild, 'NavToggle')) {
.text( '▶' ).css( 'text-decoration', 'none' )
NavChild.firstChild.data = NavigationBarHide;
.click( function ( e ) {
}
e.preventDefault();
}
updateImageGroup( currImg += 1, $images, $countInfo, $prevLink, $nextLink );
}
} );
}
updateImageGroup( currImg, $images, $countInfo, $prevLink, $nextLink );
$( imageGroupUnits ).prepend( $prevLink, $countInfo, $nextLink );
} );
}
 
$( initImageGroup );
// 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++;
* Utilizzata con [[Template:Navbox]]: se presente più di un navbox con
var NavToggle = document.createElement("a");
* classe mw-collapsible, quelli con autocollapse si chiudono da soli.
NavToggle.className = 'NavToggle';
*/
NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
function checkAutocollapse( $content ) {
NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
var $navbox = $content.filter( '.navbox' );
if ( $navbox.length > 1 ) {
$navbox.filter( '.autocollapse' ).find( '.mw-collapsible-toggle' ).click();
}
}
 
mw.hook( 'wikipage.collapsibleContent' ).add( checkAutocollapse );
var NavToggleText = document.createTextNode(NavigationBarHide);
}( mediaWiki, jQuery ) );
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);
}
}
 
}
 
jQuery(document).ready(createNavigationBarToggleButton);
 
// END Dynamic Navigation Bars
 
 
/** 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 );
}
}
}
 
addOnloadHook( 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 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( hasClass(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( hasClass(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>]';
}
}
addOnloadHook(hiddencat);
 
/* Layout pagina di modifica */
addLoadEvent ( function ()
{
if (wgAction == "edit")
{
/* Allarga l'edittools a tutta pagina */
document.getElementById("Standard").style.width = "100%";
}
})
 
/* Aggiunge il testo delle note come tooltip delle note stesse */
addOnloadHook ( function ()
{
sups = document.getElementsByTagName("sup");
for (i=0; i<sups.length; i++)
{
note_id = sups[i].childNodes[0].href;
if (note_id && (note_id.indexOf("#") != -1))
{
note_id = document.getElementById(note_id.substr(note_id.indexOf("#")+1));
if (note_id)
if (document.all)
{
sups[i].title = note_id.innerText;
sups[i].childNodes[0].title = note_id.innerText;
}
else
{
sups[i].title = note_id.textContent;
}
}
}
})
 
/* Avvisa quando si tenta di creare una voce con titolo non valido ("Scrivi qui il titolo")*/
addOnloadHook ( function ()
{
if (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);
}
})
 
 
/** Mobile Redirect Helper ************************************************
*
* Redirects to the mobile-optimized gateway at it.m.wikipedia.org
* for viewers on iPhone, iPod Touch, Palm Pre, and Android devices.
*
* You can turn off the redirect by setting the cookie "stopMobileRedirect=true"
*
* This code cannot be imported, because the JS only loads after all other files
* and this was causing major issues for users with mobile devices. Must be loaded
* *before* the images and etc of the page on all mobile devices.
*
* Maintainer: [[User:Brion VIBBER]], [[User:hcatlin]]
*/
if (/(Android|iPhone|iPod|webOS|NetFront|Opera Mini|SEMC-Browser|PlayStation Portable|Nintendo Wii)/.test(navigator.userAgent)) {
var wgMainPageName = 'Pagina_principale';
var stopMobileRedirectCookieExists = function() {
return (document.cookie.indexOf("stopMobileRedirect=true") >= 0);
}
var mobileSiteLink = function() {
if (wgCanonicalNamespace == 'Special' && wgCanonicalSpecialPageName == 'Search') {
var pageLink = '?search=' + encodeURIComponent(document.getElementById('searchText').value);
} else if (wgPageName == wgMainPageName) {
var pageLink = '::Home'; // Special case
} else {
var pageLink = encodeURIComponent(wgPageName).replace('%2F','/').replace('%3A',':');
}
return 'http://' + wgContentLanguage + '.m.wikipedia.org/wiki/' + pageLink + "?wasRedirected=true"
 
}
if (!stopMobileRedirectCookieExists()) {
document.___location = mobileSiteLink();
}
}
 
/** extract a URL parameter from the current URL **********
* From [[en:User:Lupin/autoedit.js]] and [[en:MediaWiki:Common.js]]
*
* paramName : the name of the parameter to extract
*/
function getURLParamValue( paramName, url)
{
if (typeof (url) == 'undefined' || url === null) url = document.___location.href;
var cmdRe=RegExp( '[&?]' + paramName + '=([^&#]*)' ); // Stop at hash
var m=cmdRe.exec(url);
if (m && m.length > 1) return decodeURIComponent(m[1]);
return null;
}
/** &withJS= URL parameter *******
* Allow to try custom scripts from MediaWiki space
* without editing [[Special:Mypage/monobook.js]]
*/
var extraJS = getURLParamValue("withJS");
if ( extraJS && extraJS.match("^MediaWiki:[^&<>=%]*\.js$") ) {
importScript(extraJS);
}
 
// Per bugfix: #23175
window.ta = [];
 
 
/** Workaround temporaneo *************
* Workaround per il vecchio codice che usa document.write(): a partire da MediaWiki 1.17 non è più possibile usarlo.
* Questo codice sostituisce le funzioni document.write() e document.writeln() con funzioni personalizzate.
* Quando possibile, traduce in una chiamata a importScriptURI(); in tutti gli altri casi, ritorna senza far nulla.
* E' codice poco robusto e che va rimosso al più presto, dopo aver aggiornato i vecchi codici.
*/
if (wgVersion >= "1.17"){
try{
document.write = document.writeln = function(str){
var start, end;
try{
if (str.indexOf("<script") != -1){
start = str.indexOf("src");
start = str.indexOf("\"", start+1) + 1;
end = str.indexOf("\"", start);
importScriptURI(str.substring(start, end));
} else {
//Ignora la chiamata
}
} catch (e) { /* Ignora */ }
};
} catch (e) { /* Ignora */ }
}