MediaWiki:Mobile.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
/* 这里的任何JavaScript将为使用移动版网站的用户加载 */
Promise.all( [
mw.loader.using( [
'mediawiki.util',
'ext.gadget.HanAssist',
'mediawiki.cookie',
'jquery.makeCollapsible',
] ),
$.ready,
] ).then( function( [ require ] ) {
const { convByVar } = require( 'ext.gadget.HanAssist' );
function addPortletLink() {
mw.log.warn(
'addPortletLink is deprecated on desktop and never implemented on mobile',
'More information on https://www.mediawiki.org/wiki/ResourceLoader/Migration_guide_(users)#addPortletLink',
);
}
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) == 'Search' ) {
// Scripts specific to editing pages
mw.loader.load( 'ext.gadget.EditCommon' );
}
// 如果从浏览模式直接进入编辑模式,页面不会刷新,该小工具不会加载,因此采用钩子加载
// 注意在同一页面上,即使该钩子多次触发,小工具也只会加载一次
mw.hook( 'mobileFrontend.editorOpened' ).add( () => {
mw.loader.load( 'ext.gadget.EditCommon' );
} );
/**
* metaBox
* Funcionament de la Plantilla:Metacaixa
* Implementat per: Usuari:Peleguer.
* Actualitzat per Joanjoc seguint les indicacions d'en Martorell
* 复制自 [[Special:Permalink/64841595|Common.js 92-150 行]]
*/
function MetaCaixaInit() {
// S'executa al carregar-se la pàgina, si hi ha metacaixes,
// s'assignen els esdeveniments als botons
// alert('MetaCaixaInit');
var i = 0; // Inicialitzem comptador de caixes
for ( i = 0; i <= 9; i++ ) {
var vMc = document.getElementById( 'mc' + i );
if ( !vMc ) { break; }
// alert('MetaCaixaInit, trobada Metacaixa mc' + i);
var j = 1, // Inicialitzem comptador de botons dins de la caixa
vPsIni = 0; // Pestanya visible inicial
for ( j = 1; j <= 9; j++ ) {
var vBt = document.getElementById( 'mc' + i + 'bt' + j );
if ( !vBt ) { break; }
// alert('MetaCaixaInit, trobat botó mc' + i + 'bt' + j);
vBt.onclick = MetaCaixaMostraPestanya; // A cada botó assignem l'esdeveniment onclick
// alert(vBt.className);
if ( vBt.className === 'mcBotoSel' ) { vPsIni = j; // Si tenim un botó seleccionat, en guardem l'index
}
}
// alert('mc=' + i + ', ps=' + j + ', psini=' + vPsIni);
if ( vPsIni === 0 ) { // Si no tenim cap botó seleccionat, n'agafem un aleatòriament
vPsIni = 1 + Math.floor( ( j - 1 ) * Math.random() );
// alert('Activant Pestanya a l\'atzar; _mc' + i + 'bt' + vPsIni + '_');
try {
document.getElementById( 'mc' + i + 'ps' + vPsIni ).style
.display = 'block';
document.getElementById( 'mc' + i + 'ps' + vPsIni ).style
.visibility = 'visible';
document.getElementById( 'mc' + i + 'bt' + vPsIni )
.className = 'mcBotoSel';
} catch ( e ) {
// TypeError: Cannot read property 'style' of null
}
}
}
}
function MetaCaixaMostraPestanya() {
// S'executa al clicar una pestanya,
// aquella es fa visible i les altres s'oculten
var vMcNom = this.id.substr( 0, 3 ), // A partir del nom del botó, deduïm el nom de la caixa
vIndex = this.id.substr( 5, 1 ), // I l'index
i = 1;
for ( i = 1; i <= 9; i++ ) { // busquem totes les pestanyes d'aquella caixa
// alert(vMcNom + 'ps' + i);
var vPsElem = document.getElementById( vMcNom + 'ps' + i );
if ( !vPsElem ) { break; }
if ( vIndex == i ) { // Si és la pestanya bona la mostrem i canviem la classe de botó
vPsElem.style.display = 'block';
vPsElem.style.visibility = 'visible';
document.getElementById( vMcNom + 'bt' + i ).className = 'mcBotoSel';
} else { // Sinó, l'ocultem i canviem la classe de botó
vPsElem.style.display = 'none';
vPsElem.style.visibility = 'hidden';
document.getElementById( vMcNom + 'bt' + i ).className = 'mcBoto';
}
}
return false; // evitem la recàrrega de la pàgina
}
MetaCaixaInit();
// T111565 workaround - 在手机版支持折叠显示
$( '.mw-collapsible' ).makeCollapsible();
// 请在本行前添加内容
} );
// 请勿在本行后添加内容