Utente:Codicorumus/ReferenceTooltip-Popups workaround plus load.js
Questa pagina definisce alcuni parametri di aspetto e comportamento generale di tutte le pagine. Per personalizzarli vedi Aiuto:Stile utente.
Nota: dopo aver salvato è necessario pulire la cache del proprio browser per vedere i cambiamenti (per le pagine globali è comunque necessario attendere qualche minuto). Per Mozilla / Firefox / Safari: fare clic su Ricarica tenendo premuto il tasto delle maiuscole, oppure premere Ctrl-F5 o Ctrl-R (Command-R su Mac); per Chrome: premere Ctrl-Shift-R (Command-Shift-R su un Mac); per Konqueror: premere il pulsante Ricarica o il tasto F5; per Opera può essere necessario svuotare completamente la cache dal menù Strumenti → Preferenze; per Internet Explorer: mantenere premuto il tasto Ctrl mentre si preme il pulsante Aggiorna o premere Ctrl-F5.
/**
* -------------------------------------------------
* ReferenceTooltip-Popups workaround plus load.js
* -------------------------------------------------
*
* //it.wikipedia.org/wiki/Utente:Codicorumus/ReferenceTooltip-Popups_workaround_plus_load.js
*
* This script provides a workaround
* that allows Lupin/popups.js and ReferenceTooltip.js to run alongside
* without :
* - "double popups" on ReferenceTooltip.js loaded first
* - "ReferenceTooltip.js failing" on popups.js loaded first
* instead, with this script :
* - when ReferenceTooltip.js does popup, popups.js doesn't
* - when ReferenceTooltip.js is disabled, popups.js does popup again
*
*
* Supported languages: en, it, pl, ru
* de : until now (13 march 2013) messages in de.wikivoyage version are still in English
* when it will be translated, de-language will become also available
*
*
* Loading order doesn't matter.
*
* But, if you can, disable other ReferenceTooltip.js loadings
* this script does anyway a load-or-reload
* of a Gadget-ReferenceTooltips.js version based on wgUserLanguage value
*
* Also, the workaround can be integrated in ReferenceTooltip.js
* for a how-to, see in
* //it.wikipedia.org/wiki/Utente:Codicorumus/ReferenceTooltip-Popups_workaround.js
* ( that version is also much shorter and faster,
* but has more stringent prerequisites )
*
*
* If anything goes wrong or you would suggest improvements
* if available, write in
* //it.wikipedia.org/wiki/Discussioni_utente:Codicorumus/ReferenceTooltip-Popups_workaround
* otherwise in
* //it.wikipedia.org/wiki/Discussioni_utente:Codicorumus
*
*/
( function( $, mw ) {
var
userLanguage = mw.config.get( 'wgUserLanguage' ),
pgHidingNeeded = userLanguage !== 'it',
validNamespaces = [
'',
'Project',
'Help'
];
function listRegex( list, find, replace ) {
if ( find )
list.forEach( function( item, index, array ) {
array[ index ] = array[ index ]
.replace( find, replace );
} );
return new RegExp(
'^('
+ list.join( '|' )
+ ')$'
);
}
// tries to avoid popups from en:w:User:Lupin/popups.js
// for reference links handled by ReferenceTooltip.js
// by overriding window.mouseOverWikiLink2( a, evt ) defined in .../popups.js
function tryPopupSkipping( numTries, repeatDelay ) {
if ( // prudential test against popups.js loaded, initialized and compatible
typeof mouseOverWikiLink2 === 'function'
&& mouseOverWikiLink2.length === 2
&& typeof mouseOverWikiLink2Overrided === 'undefined'
&& (
! pgHidingNeeded
||
( // needed to allow temporary hiding of window.pg
typeof popupsReady === 'function'
&& popupsReady()
)
)
)
{
window.mouseOverWikiLink2Overrided = mouseOverWikiLink2;
// function's override
window.mouseOverWikiLink2 = function override( a, evt ) {
var isRefLink_and_RTisOn;
try {
isRefLink_and_RTisOn = (
/^#cite_note-/.test( a.getAttribute( 'href' ) )
&&
( ! $.cookie( 'RTsettings' ) // no cookie yet, so ReferenceTooltips is on
|| $.cookie( 'RTsettings' )[0] === '1' // ReferenceTooltips is on, cookie says
)
);
}
catch ( error ) {
isRefLink_and_RTisOn = false;
}
if ( isRefLink_and_RTisOn )
// skips Lupin's popup on ref-links handled by ReferenceTooltips
return null;
else
// does Lupin's popup
return mouseOverWikiLink2Overrided( a, evt );
};
reloadReferenceTooltip();
}
else if ( -- numTries )
// waiting .../popups.js
setTimeout(
function() {
tryPopupSkipping( numTries, repeatDelay );
},
repeatDelay
);
}
function reloadReferenceTooltip() {
var
server = mw.config.get( 'wgServer' ),
pgTemp = null; // used in setTimeout's callback -- if pgHidingNeeded === true
function importScriptByLang( lang ) {
var
wikiUrl = {
de: '//de.wikivoyage.org/w/index.php?title=',
en: '//en.wikipedia.org/w/index.php?title=',
it: '//it.wikipedia.org/w/index.php?title=',
pl: '//pl.wikipedia.org/w/index.php?title=',
ru: '//ru.wikipedia.org/w/index.php?title='
},
scriptPages = {
de: 'MediaWiki:Gadget-ReferenceTooltips.js', // not yet translated from English : 11 march 2013
en: 'MediaWiki:Gadget-ReferenceTooltips.js',
it: 'MediaWiki:Gadget-ReferenceTooltips.js',
pl: 'MediaWiki:Gadget-ReferenceTooltips.js',
ru: 'MediaWiki:Gadget-referenceTooltips.js'
};
if (
! ( lang in scriptPages )
)
lang = 'en';
mw.loader.load(
wikiUrl[ lang ]
+ scriptPages[ lang ]
+ '&action=raw&ctype=text/javascript'
);
}
function hideDuplicatedEnableCmd() {
var enableCmdRegex = listRegex( [
/* en */ 'Enable Reference Tooltips',
/* it */ 'Abilita i tooltip',
/* pl */ 'Włącz podgląd przypisów',
/* ru */ 'Включить всплывающие подсказки'
] );
$( 'ul#footer-places li' )
.filter( function() {
return enableCmdRegex.test( this.textContent );
} )
.hide()
.last().show();
// last one is created by the ReferenceTooltips.js loaded by this script
}
function hereCssMayLack() {
var projectsRegex = listRegex( [
'//it.wikipedia.org',
'//it.wikiquote.org',
'//it.wikivoyage.org'
],
/\./g, '\\.'
);
return ! (
projectsRegex.test( server )
);
}
if ( server === '//it.wikipedia.org' )
// no need to load-or-reload ReferenceTooltips.js
// here ReferenceTooltip.js is loaded by Common.js
// and its execution is no more inhibited by Lupin/popups.js detection
return;
if ( pgHidingNeeded ) {
pgTemp = window.pg;
window.pg = false;
}
importScriptByLang( userLanguage );
/*
* as I can see, so far en.wikipedia CSS works well everywhere
* //de.wikivoyage.org/wiki/MediaWiki:Gadget-ReferenceTooltips.css
* //pl.wikipedia.org/wiki/MediaWiki:Gadget-ReferenceTooltips.css
* //ru.wikipedia.org/wiki/MediaWiki:Gadget-referenceTooltips.css
*/
if ( importStylesheetURI && hereCssMayLack() )
importStylesheetURI(
'//en.wikipedia.org/w/index.php?title='
+ 'MediaWiki:Gadget-ReferenceTooltips.css'
+ '&action=raw&ctype=text/css'
);
if ( pgHidingNeeded )
setTimeout(
function() {
// restore window.pg
window.pg = pgTemp;
// hide extra re-enable anchor, due to ReferenceTooltip.js reload
// because I can't figure out how to set apart --via js-- reload-needing case from not-needing
// ( except for versions of the script free of "window.pg" test )
// where possible, best option is to load optional ReferenceTooltip.js only via this script
hideDuplicatedEnableCmd();
},
500
);
}
if (
listRegex( validNamespaces )
.test(
mw.config.get( 'wgCanonicalNamespace' )
)
)
tryPopupSkipping( 10, 500 );
}(
// lacking one of these, script fails immediately
jQuery, mediaWiki
) );