MediaWiki:Common.js:修订间差异

来自广州交通维基 - Canton Trans Wiki
跳转到导航 跳转到搜索
Zhbus留言 | 贡献
创建页面,内容为“这里的任何JavaScript将为所有用户在每次页面加载时加载。:​ 加载ToolsWIKI的DiffTool 以逐字显示更改,0缓存,具体可见https://wiki.biligame.com/tools/%E4%BC%98%E5%8C%96%E7%89%88%E6%9C%AC%E5%B7%AE%E5%BC%82-DiffTools:​ try { mw.loader.load("https://wiki.biligame.com/tools/MediaWiki:DiffTool.js?action=raw&ctype=text/javascript&rand="+Math.random(), "text/javascript");} catch(e) { console.log("Error, MediaWiki:DiffTool.js…”
 
Zhbus留言 | 贡献
无编辑摘要
第83行: 第83行:


}
}
// 102. 功能:封面画册JS代码
// 简单外部图片淡入轮播(支持多组)
document.addEventListener('DOMContentLoaded', function() {
    document.querySelectorAll('.simple-fade-carousel').forEach(carousel => {
        const slides = carousel.querySelectorAll('.slide');
        const prevBtn = carousel.querySelector('.prev');
        const nextBtn = carousel.querySelector('.next');
        let current = 0;
        let interval;
        function showSlide(index) {
            slides.forEach((s, i) => {
                s.classList.toggle('active', i === index);
            });
            current = index;
        }
        function nextSlide() {
            let next = (current + 1) % slides.length;
            showSlide(next);
        }
        // 自动播放(每5秒切换)
        function startAuto() {
            interval = setInterval(nextSlide, 5000);
        }
        function stopAuto() {
            clearInterval(interval);
        }
        // 按钮事件
        if (prevBtn) prevBtn.addEventListener('click', () => {
            stopAuto();
            let prev = (current - 1 + slides.length) % slides.length;
            showSlide(prev);
            startAuto();
        });
        if (nextBtn) nextBtn.addEventListener('click', () => {
            stopAuto();
            nextSlide();
            startAuto();
        });
        // 鼠标悬停暂停(可选)
        carousel.addEventListener('mouseenter', stopAuto);
        carousel.addEventListener('mouseleave', startAuto);
        // 启动
        showSlide(0);
        startAuto();
    });
});

2025年12月25日 (四) 22:33的版本

/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
/*加载ToolsWIKI的DiffTool 以逐字显示更改,0缓存,具体可见https://wiki.biligame.com/tools/%E4%BC%98%E5%8C%96%E7%89%88%E6%9C%AC%E5%B7%AE%E5%BC%82-DiffTools */
try { mw.loader.load("https://wiki.biligame.com/tools/MediaWiki:DiffTool.js?action=raw&ctype=text/javascript&rand="+Math.random(), "text/javascript");} catch(e) { console.log("Error, MediaWiki:DiffTool.js 加载失败");console.error(e, e.stack);}
/* 参见[[模板:ResourceLoader]]*/

//居中与右对齐,文本默认为左对齐,不用另外添加此按钮。(仅适用于源代码编辑模式)
/*居中*/
if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
    // Add a hook handler.
    mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
        // Configure a new toolbar entry on the given $textarea jQuery object.
        $textarea.wikiEditor( 'addToToolbar', {
            section: 'advanced',
            group: 'format',
            tools: {
                AlignCenter: {
                    label: '居中',
                    type: 'button',
                    oouiIcon: 'alignCenter',
                    action: {
                        type: 'encapsulate',
                        options: {
                            pre: "<center>",
                            post: "</center>"
                        }
                    }
                }
            }
        } );
    } );
}

/*右对齐*/
if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
    // Add a hook handler.
    mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
        // Configure a new toolbar entry on the given $textarea jQuery object.
        $textarea.wikiEditor( 'addToToolbar', {
            section: 'advanced',
            group: 'format',
            tools: {
                AlignCenter: {
                    label: '右对齐',
                    type: 'button',
                    oouiIcon: 'alignRight',
                    action: {
                        type: 'encapsulate',
                        options: {
                            pre: "<div align=right>",
                            post: "</div>"
                        }
                    }
                }
            }
        } );
    } );
}

// 101. 功能:快捷编辑理由。支持编辑摘要时,点击快捷选项填充编辑理由。(仅适用于源代码编辑模式)
//参考Wikipedia:MediaWiki:Common.js/edit.js
if (mw.config.get('wgAction') == "edit" || mw.config.get('wgAction') == "submit" || mw.config.get('wgCanonicalSpecialPageName') == 'Search') { // 编辑页面
  
( function( $, mw ) { $( function() {
    if ( $( '#editform input[name=wpSection]' ).val() === 'new' ) {
        if ( $( '#no-new-title' ).length ) {
            $( '#wpSummary' ).attr( 'disabled', true );
        }
        return;
    }
    $( '#wpSummaryLabel .mw-summary-preset' ).on( 'click', '.mw-summary-preset-item a', function( e ) {
        e.preventDefault();
        var $this = $( this ), summary = $( '#wpSummary' ).val();
        var $item = $this.parent( '.mw-summary-preset-item' );
        summary = summary.replace( /\s+$/g, '' );
        if ( summary != '' ) {
            summary += ' ';
        }
        summary += $item.attr( 'title' ) || $this.text();
        $this.replaceWith( $this.contents() );
        $( '#wpSummary' ).val( summary ).focus();
    } );
} ); } )( jQuery, mediaWiki );

}

// 102. 功能:封面画册JS代码

// 简单外部图片淡入轮播(支持多组)
document.addEventListener('DOMContentLoaded', function() {
    document.querySelectorAll('.simple-fade-carousel').forEach(carousel => {
        const slides = carousel.querySelectorAll('.slide');
        const prevBtn = carousel.querySelector('.prev');
        const nextBtn = carousel.querySelector('.next');
        let current = 0;
        let interval;

        function showSlide(index) {
            slides.forEach((s, i) => {
                s.classList.toggle('active', i === index);
            });
            current = index;
        }

        function nextSlide() {
            let next = (current + 1) % slides.length;
            showSlide(next);
        }

        // 自动播放(每5秒切换)
        function startAuto() {
            interval = setInterval(nextSlide, 5000);
        }

        function stopAuto() {
            clearInterval(interval);
        }

        // 按钮事件
        if (prevBtn) prevBtn.addEventListener('click', () => {
            stopAuto();
            let prev = (current - 1 + slides.length) % slides.length;
            showSlide(prev);
            startAuto();
        });

        if (nextBtn) nextBtn.addEventListener('click', () => {
            stopAuto();
            nextSlide();
            startAuto();
        });

        // 鼠标悬停暂停(可选)
        carousel.addEventListener('mouseenter', stopAuto);
        carousel.addEventListener('mouseleave', startAuto);

        // 启动
        showSlide(0);
        startAuto();
    });
});