MediaWiki:Mobile.js

来自戏曲百科

注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
  • Opera:Ctrl-F5
/* 这里的任何JavaScript将为使用移动版网站的用户加载 */

mw.loader.using(['mediawiki.util', 'ext.gadget.site-lib', 'mediawiki.cookie'], function () {

    /* 當需要時載入對應的 scripts */
    var importScriptRL=function(page){
    	mw.loader.load(mw.config.get('wgScript')+'?title='+mw.util.wikiUrlencode(page)+'&action=raw&ctype=text/javascript&_='+Math.floor((new Date())/1000/60/60/24/7));
    };
    
    if (mw.config.get('wgAction') == "edit" || mw.config.get('wgAction') == "submit" || mw.config.get('wgCanonicalSpecialPageName') == 'Search') { // scripts specific to editing pages
      importScriptRL('MediaWiki:Mobile.js\/edit.js');
    }

	// maintenance: Some user scripts may be using the following deprecated functions on mobile.
	// These functions are no longer supported and should be updated to use mw.loader.getScript.
	// https://www.mediawiki.org/wiki/ResourceLoader/Migration_guide_(users)#Legacy_removals
	if (typeof importScript === 'undefined') {
		window.importScript = function() {
			if (mw.cookie.get('Deprecated-importScript')) return;
			mw.cookie.set('Deprecated-importScript', '1', {expires: 86400});
			mw.notify([ wgULS('您在手机版上执行的用户脚本使用了已弃用的函数 importScript,请<a href="https://w.wiki/dCe">更新成 mw.loader.load</a>。', '您在手機版上執行的使用者腳本使用了已棄用的函數 importScript,請<a href="https://w.wiki/dCe">更新成 mw.loader.load</a>。') ]);
		};
	}

	if (typeof importStylesheet === 'undefined') {
		window.importStylesheet = function () {
			if (mw.cookie.get('Deprecated-importStylesheet')) return;
			mw.cookie.set('Deprecated-importStylesheet', '1', {expires: 86400});
			mw.notify([ wgULS('您在手机版上执行的用户脚本使用了已弃用的函数 importStylesheet,请<a href="https://w.wiki/dCe">更新成 mw.loader.load</a>。', '您在手機版上執行的使用者腳本使用了已棄用的函數 importStylesheet,請<a href="https://w.wiki/dCe">更新成 mw.loader.load</a>。') ]);
		};
	}

    /**
     * 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);
});