MediaWiki:Common.js: differenze tra le versioni
Common.js v6: viewport <768 forza ?useformat=mobile |
Rimosso redirect JS useformat=mobile (duplicato del 302 server): faceva perdere i tap sul gate |
||
| (Una versione intermedia di un altro utente non mostrate) | |||
| Riga 1: | Riga 1: | ||
/* ============================================================ | /* ============================================================ | ||
* Common.js | * Common.js v7 — Wiki Methode Paret | ||
* ============================================================ | * ============================================================ | ||
* REGOLA UNICA: | * REGOLA UNICA: | ||
* URL /Titolo → UI italiana | * URL /Titolo → UI italiana | ||
* URL /Titolo/ru → UI russa | * URL /Titolo/ru → UI russa | ||
* | * | ||
* | * Mobile detection v7: | ||
* | * - Touch capability (funziona anche con "Versione Desktop" del browser) | ||
* | * - Viewport width <= 1200 (più tollerante: cattura anche desktop mode 1080) | ||
* - Una delle due basta | |||
* ============================================================ */ | * ============================================================ */ | ||
( function ( mw ) { | ( function ( mw ) { | ||
| Riga 16: | Riga 16: | ||
var SUPPORTED_LANGS = [ 'ru', 'en', 'fr', 'es', 'pt' ]; | var SUPPORTED_LANGS = [ 'ru', 'en', 'fr', 'es', 'pt' ]; | ||
function getCookie( name ) { | function getCookie( name ) { | ||
var m = document.cookie.match( new RegExp( '(?:^|;\\s*)' + name + '=([^;]*)' ) ); | var m = document.cookie.match( new RegExp( '(?:^|;\\s*)' + name + '=([^;]*)' ) ); | ||
| Riga 34: | Riga 33: | ||
} | } | ||
// ─── | // ─── DETECTION MOBILE ROBUSTA ────────────────────────── | ||
var ua = navigator.userAgent || ''; | var ua = navigator.userAgent || ''; | ||
var isMobileUA = /iPhone|iPad|iPod|Android|Mobile|webOS|BlackBerry|Opera Mini|IEMobile|Silk/i.test( ua ); | var isMobileUA = /iPhone|iPad|iPod|Android|Mobile|webOS|BlackBerry|Opera Mini|IEMobile|Silk/i.test( ua ); | ||
var viewportWidth = window.innerWidth || document.documentElement.clientWidth || 1024; | var viewportWidth = window.innerWidth || document.documentElement.clientWidth || 1024; | ||
var | var isSmallViewport = viewportWidth <= 1200; | ||
var isMobile = isMobileUA || | var hasTouch = ( 'ontouchstart' in window ) || | ||
( navigator.maxTouchPoints > 0 ) || | |||
( navigator.msMaxTouchPoints > 0 ); | |||
// Mobile se: UA mobile OPPURE (touch + viewport piccolino) | |||
// Il caso "Versione Desktop attivata" ha touch=true e viewport ~1080 → cattura | |||
var isMobile = isMobileUA || ( hasTouch && isSmallViewport ); | |||
if ( isMobile ) { | if ( isMobile ) { | ||
| Riga 47: | Riga 52: | ||
} | } | ||
[ 'autolang_set', 'no_auto_lang_redirect' ].forEach( function ( n ) { | [ 'autolang_set', 'no_auto_lang_redirect' ].forEach( function ( n ) { | ||
if ( getCookie( n ) !== null ) deleteCookie( n ); | if ( getCookie( n ) !== null ) deleteCookie( n ); | ||
} ); | } ); | ||
// [ISICNV 14/07/2026] Redirect useformat=mobile RIMOSSO: lo fa gia il server (302). | |||
// Il location.replace ricaricava la pagina dopo il render, facendo perdere i tap sul gate. | |||
// ─── | // ─── URL decide UI lingua ───────────────────────────── | ||
function syncUILangFromURL() { | function syncUILangFromURL() { | ||
if ( typeof mw === 'undefined' || !mw.config ) return; | if ( typeof mw === 'undefined' || !mw.config ) return; | ||
| Riga 102: | Riga 94: | ||
}( window.mediaWiki || window.mw ) ); | }( window.mediaWiki || window.mw ) ); | ||