LLWiki正在建设中,欢迎加入我们

“MediaWiki:Mobile.js”的版本间差异

来自LLWiki
跳转到导航 跳转到搜索
标签移动版网页编辑 移动版编辑
第1行: 第1行:
/* 这里的任何JavaScript将为使用移动版网站的用户加载 */
//<nowiki>
//<nowiki>
// 经测试不可使用ES6语法
// 由ResourceLoader直接调用,不可使用ES6语法
/**
// 出於安全考慮,請盡可能使用jQuery代替htmlString
* @Description: 手机版全局JS
* @Author: 如无特殊说明,均为[[User:Bhsd]]
*/
"use strict";
"use strict";
/*global mw, $, wgULS*/
/*global wgULS*/
mw.messages.set( wgULS({
'mobile-rc': "最近更改", 'mobile-village': "互助客栈", 'mobile-policy': "方针与指引", 'mobile-help': "帮助",
'mobile-whatlinkshere': "链入页面", 'mobile-rclinked': "相关更改"
}, {
'mobile-rc': "近期變更", 'mobile-village': "互助客棧", 'mobile-policy': "方針與指引", 'mobile-help': "幫助",
'mobile-whatlinkshere': "連結至此的頁面", 'mobile-rclinked': "相關變更"
}) );
mw.hook( 'wikipage.content' ).add(function( $content ) {
mw.hook( 'wikipage.content' ).add(function( $content ) {
// 用户贡献页面不可创建
$content.find( '.mw-usertoollinks-contribs.new' ).off( 'click' );

const collapsibleContent = $content.find( '.mw-collapsible:not(.mw-made-collapsible)' ),
const collapsibleContent = $content.find( '.mw-collapsible:not(.mw-made-collapsible)' ),
sortableContent = $content.find( 'table.sortable' );
sortableContent = $content.find( 'table.sortable' );
// 折叠
/**
* @Function: 折叠
/* 引自[[moegirl:mediawiki:mobile.js]] */
* @Source: [[moegirl:Mediawiki:Mobile.js]]
*/
if (collapsibleContent.length) {
if (collapsibleContent.length) {
console.log('Hook: wikipage.content,开始执行折叠');
console.log('Hook: wikipage.content,开始执行折叠');
第56行: 第70行:


mw.loader.using( ['mediawiki.util', 'ext.gadget.site-lib'] ).then(function() {
mw.loader.using( ['mediawiki.util', 'ext.gadget.site-lib'] ).then(function() {
const script = mw.config.get( 'wgScript' ),
const pagename = mw.pagenamee(),
pagename = mw.util.wikiUrlencode( mw.config.get( 'wgPageName' ) ),
pageid = mw.config.get( 'wgArticleId' ),
pageid = mw.config.get( 'wgArticleId' ),
items = [
nav = $('<ul>').append( $('<li>').append( $('<a>', {href: script + '/Special:最近更改',
html: '<i class="fa fa-random"></i><span>' + wgULS("最近更改", "近期變更") + '</span>'
{href: '/zh/Special:最近更改', icon: 'random', msg: 'mobile-rc'},
}) ) ).append( $('<li>').append( $('<a>', {href: script + '/LLWiki:沙盒',
{href: '/zh/LLWiki:沙盒', icon: 'inbox', text: '沙盒'},
{href: '/zh/LLWiki:互助客栈', icon: 'heart', msg: 'mobile-village'},
html: '<i class="fa fa-inbox"></i><span>沙盒</span>'
{href: '/zh/LLWiki:方針與指引', icon: 'tasks', msg: 'mobile-policy'},
}) ) ).append( $('<li>').append( $('<a>', {href: script + '/LLWiki:互助客栈',
{href: '/zh/Help:幫助總覽', icon: 'question-circle', msg: 'mobile-help'}
html: '<i class="fa fa-heart"></i><span>' + wgULS("互助客栈", "互助客棧") + '</span>'
],
}) ) ).append( $('<li>').append( $('<a>', {href: script + '/LLWiki:方針與指引',
nav = mw.addMobileLinks( items.concat( pageid > 0 ? [
html: '<i class="fa fa-tasks"></i><span>' + wgULS("方针与指引", "方針與指引") + '</span>'
{href: '/zh/Special:链入页面/' + pagename, icon: 'quote-right', msg: 'mobile-whatlinkshere'},
}) ) ).append( $('<li>').append( $('<a>', {href: script + '/Help:幫助總覽',
{href: '/zh/Special:链出更改/' + pagename, icon: 'share-alt', msg: 'mobile-rclinked'}
html: '<i class="fa fa-question-circle"></i><span>' + wgULS("帮助", "幫助") + '</span>'
}) ) );
]: null ));
if (pageid > 0) {
nav.append( $('<li>').append( $('<a>', {href: script + '/Special:链入页面/' + pagename,
html: '<i class="fa fa-quote-right"></i><span>' + wgULS("链入页面", "連結至此的頁面") + '</span>'
}) ) ).append( $('<li>').append( $('<a>', {href: script + '/Special:链出更改/' + pagename,
html: '<i class="fa fa-share-alt"></i><span>' + wgULS("相关更改", "相關變更") + '</span>'
}) ) );
}
mw.hook( 'mobile.menu' ).add(function($menu) {
mw.hook( 'mobile.menu' ).add(function($menu) {
console.log('Hook: mobile.menu,开始添加移动版菜单项');
console.log('Hook: mobile.menu,开始添加移动版菜单项');
$menu.children( 'ul' ).first().after(nav);
$menu.children( 'ul' ).first().after( $('<ul>', {html: nav}) );
});
});
});
});

2021年1月25日 (一) 00:28的版本

//<nowiki>
// 由ResourceLoader直接调用,不可使用ES6语法
/**
 * @Description: 手机版全局JS
 * @Author: 如无特殊说明,均为[[User:Bhsd]]
 */
"use strict";
/*global wgULS*/
mw.messages.set( wgULS({
    'mobile-rc': "最近更改", 'mobile-village': "互助客栈", 'mobile-policy': "方针与指引", 'mobile-help': "帮助",
    'mobile-whatlinkshere': "链入页面", 'mobile-rclinked': "相关更改"
}, {
    'mobile-rc': "近期變更", 'mobile-village': "互助客棧", 'mobile-policy': "方針與指引", 'mobile-help': "幫助",
    'mobile-whatlinkshere': "連結至此的頁面", 'mobile-rclinked': "相關變更"
}) );
mw.hook( 'wikipage.content' ).add(function( $content ) {
    // 用户贡献页面不可创建
    $content.find( '.mw-usertoollinks-contribs.new' ).off( 'click' );

    const collapsibleContent = $content.find( '.mw-collapsible:not(.mw-made-collapsible)' ),
        sortableContent = $content.find( 'table.sortable' );
    /**
     * @Function: 折叠
     * @Source: [[moegirl:Mediawiki:Mobile.js]]
     */
    if (collapsibleContent.length) {
        console.log('Hook: wikipage.content,开始执行折叠');
        mw.loader.using( 'jquery.makeCollapsible' ).then(function() { collapsibleContent.makeCollapsible(); });
    }
    // 表格排序
    if (sortableContent.length) {
        console.log('Hook: wikipage.content,开始执行表格排序');
        mw.loader.using( 'jquery.tablesorter' ).then(function() { sortableContent.tablesorter(); });
    }
});

$(function() {
    // 快速编辑工具
    if (['edit', 'submit'].includes( mw.config.get('wgAction') )) {
        $( '.mw-editTools' ).insertBefore( '#wpTextbox1' );
    }
});

if (mw.config.get( 'wgCanonicalSpecialPageName' ) == "Recentchanges") {
    // 修改filter
    mw.hook( 'structuredChangeFilters.ui.initialized' ).add(function() {
        console.log('Hook: structuredChangeFilters.ui.initialized,开始修改filter');
        mw.loader.using( ['mediawiki.Uri', 'ext.gadget.site-lib'] ).then(function() {
            const uri = new mw.Uri(),
                invert = uri.query.invert || 0,
                node = $( '.mw-rcfilters-ui-itemMenuOptionWidget-view-namespaces' ).first().clone()
                .insertAfter( $( '.mw-rcfilters-ui-filterMenuSectionOptionWidget' ).first() )
                .attr('id', 'ooui-invert').removeClass( 'oo-ui-element-hidden' )
                .on('click', function() { window.location.href = uri.extend({ invert: 1 - invert }); });
            node.find( 'span.oo-ui-labelElement-label' ).text( wgULS("排除选项", "排除所選") );
            node.find( 'input' ).prop('checked', invert > 0)
                .next().addClass( 'oo-ui-image-invert' );
        });
    });
}

console.log( 'setInterval: 等待移动版菜单加载完毕' );
const timerStart = mw.now(),
    timer = setInterval(function() {
    if ($('.menu ul').length === 0) { return; }
    clearInterval(timer);
    mw.hook( 'mobile.menu' ).fire( $('.menu') );
    console.log('End setInterval: 移动版菜单加载完毕,用时 ' + (mw.now() - timerStart) + ' ms');
}, 200);

mw.loader.using( ['mediawiki.util', 'ext.gadget.site-lib'] ).then(function() {
    const pagename = mw.pagenamee(),
        pageid = mw.config.get( 'wgArticleId' ),
        items = [
        {href: '/zh/Special:最近更改', icon: 'random', msg: 'mobile-rc'},
        {href: '/zh/LLWiki:沙盒', icon: 'inbox', text: '沙盒'},
        {href: '/zh/LLWiki:互助客栈', icon: 'heart', msg: 'mobile-village'},
        {href: '/zh/LLWiki:方針與指引', icon: 'tasks', msg: 'mobile-policy'},
        {href: '/zh/Help:幫助總覽', icon: 'question-circle', msg: 'mobile-help'}
    ],
        nav = mw.addMobileLinks( items.concat( pageid > 0 ? [
        {href: '/zh/Special:链入页面/' + pagename, icon: 'quote-right', msg: 'mobile-whatlinkshere'},
        {href: '/zh/Special:链出更改/' + pagename, icon: 'share-alt', msg: 'mobile-rclinked'}
    ]: null ));
    mw.hook( 'mobile.menu' ).add(function($menu) {
        console.log('Hook: mobile.menu,开始添加移动版菜单项');
        $menu.children( 'ul' ).first().after( $('<ul>', {html: nav}) );
    });
});
//</nowiki>
// [[category:作为模块的小工具]] [[category:不可关闭的小工具]] [[category:手机版小工具]]
// {{DEFAULTSORT:*}}