MediaWiki:Common.js:修订间差异

虾仁​(留言 | 贡献)
Fix content model wikitext→javascript: ResourceLoader must package Common.js into site module (navigation was not loading)
虾仁​(留言 | 贡献)
资源页更新
第1行: 第1行:
/* 虾仁维基 - 自定义侧边栏导航 v2.1 */
/* 虾仁维基 - 自定义侧边栏导航 v3.0 */
/* 优化:古风主题统一、健壮初始化、精致样式 */
/* 优化:古风主题统一、健壮初始化、精致样式、移动端(Minerva)适配 */
/* 最后更新: 2026-07-30 */
/* 最后更新: 2026-07-30 */


第16行: 第16行:
             return;
             return;
         }
         }
        var skin = mw.config.get('skin');
        var isMobile = (skin === 'minerva' || skin === 'minerva-vec');
         mw.loader.using('mediawiki.api').then(function () {
         mw.loader.using('mediawiki.api').then(function () {
             waitForPanel(function ($panel) {
             if (isMobile) {
                buildNav($panel);
                waitForMobileDrawer(function ($host) {
            });
                    buildNav($host, true);
                });
            } else {
                waitForPanel(function ($panel) {
                    buildNav($panel, false);
                });
            }
         }).catch(function (e) {
         }).catch(function (e) {
             console.error('[虾仁导航] 依赖加载失败,降级构建', e);
             console.error('[虾仁导航] 依赖加载失败,降级构建', e);
             waitForPanel(function ($panel) {
             if (isMobile) {
                buildNav($panel);
                waitForMobileDrawer(function ($host) {
            });
                    buildNav($host, true);
                });
            } else {
                waitForPanel(function ($panel) {
                    buildNav($panel, false);
                });
            }
         });
         });
     }
     }
第41行: 第55行:
     }
     }


     function buildNav($panel) {
    function waitForMobileDrawer(cb) {
        var tries = 0;
        function tryFind() {
            var $host = $('#mw-mf-page-left .navigation-drawer');
            if (!$host.length) $host = $('.navigation-drawer');
            if (!$host.length) $host = $('#mw-mf-page-left');
            if ($host.length) return cb($host);
            if (++tries > 60) return;
            setTimeout(tryFind, 100);
        }
        tryFind();
    }
 
     function buildNav($panel, isMobile) {
         var html = '';
         var html = '';


第96行: 第123行:
         html += '<div class="xn-single"><a href="' + url('共创入口') + '">共创入口</a></div>';
         html += '<div class="xn-single"><a href="' + url('共创入口') + '">共创入口</a></div>';


         $panel.html(html);
         if (isMobile) {
            var $box = $('<section class="xn-mobile"></section>');
            $box.html(html);
            $panel.prepend($box);
        } else {
            $panel.html(html);
        }
         restoreCollapse();
         restoreCollapse();
         bindEvents();
         bindEvents();
第229行: 第262行:
     function highlightCurrent() {
     function highlightCurrent() {
         var currentTitle = mw.config.get('wgPageName');
         var currentTitle = mw.config.get('wgPageName');
         $('#mw-panel .xn-link a').each(function () {
         $('.xn-link a').each(function () {
             var href = $(this).attr('href');
             var href = $(this).attr('href');
             if (!href) return;
             if (!href) return;