打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

MediaWiki:Common.js:修订间差异

MediaWiki界面页面
弃权者留言 | 贡献
创建页面,内容为“$(function() { var $tooltip = $('<div id="custom-notetip-popup"></div>').appendTo('body'); mw.hook('wikipage.content').add(function($content) { mw.loader.using('jquery.makeCollapsible').then(function() { $content.find('.mw-collapsible').makeCollapsible(); }); $content.find('.Tabs:not(.tabs-initialized)').each(function() { var $tabsContainer = $(this); var $tabItems = $tabsContainer.find('> .T…”
 
弃权者留言 | 贡献
无编辑摘要
第1行: 第1行:
$(function() {
$(function() {
     var $tooltip = $('<div id="custom-notetip-popup"></div>').appendTo('body');
     var $tooltip = $('#custom-notetip-popup');
    if (!$tooltip.length) {
        $tooltip = $('<div id="custom-notetip-popup"></div>').appendTo('body');
    }


     mw.hook('wikipage.content').add(function($content) {
     mw.hook('wikipage.content').add(function($content) {
        $content.find('.mw-custom-notetip').on('mouseenter', function() {
            var $this = $(this);
            var text = $this.attr('data-notetip');
            if (!text) return;
            var rect = this.getBoundingClientRect();
            $tooltip.text(text).show();
            var tipHeight = $tooltip.outerHeight();
            var tipWidth = $tooltip.outerWidth();
           
            var top = window.scrollY + rect.top - tipHeight - 10;
            var left = window.scrollX + rect.left + (rect.width / 2) - (tipWidth / 2);
            if (rect.top - tipHeight < 20) {
                top = window.scrollY + rect.bottom + 10;
            }
            var winWidth = $(window).width();
            if (left < 10) left = 10;
            if (left + tipWidth > winWidth - 10) left = winWidth - tipWidth - 10;
            $tooltip.css({ 'top': top + 'px', 'left': left + 'px', 'display': 'block' });
        }).on('mouseleave', function() {
            $tooltip.hide();
        });
         mw.loader.using('jquery.makeCollapsible').then(function() {
         mw.loader.using('jquery.makeCollapsible').then(function() {
             $content.find('.mw-collapsible').makeCollapsible();
             $content.find('.mw-collapsible').makeCollapsible();
第11行: 第41行:
             var $tabItems = $tabsContainer.find('> .Tab');
             var $tabItems = $tabsContainer.find('> .Tab');
             if (!$tabItems.length) return;
             if (!$tabItems.length) return;
             var $labelWrapper = $('<div class="TabLabel"></div>');
             var $labelWrapper = $('<div class="TabLabel"></div>');
             var $contentWrapper = $('<div class="TabContent"></div>');
             var $contentWrapper = $('<div class="TabContent"></div>');
             $tabItems.each(function(i) {
             $tabItems.each(function(i) {
                 var $item = $(this);
                 var $item = $(this);
                 var $label = $item.find('> .TabLabelText');
                 var $label = $item.find('> .TabLabelText');
                 var $contentBox = $item.find('> .TabContentText');
                 var $contentBox = $item.find('> .TabContentText');
                 if (i === 0) {
                 if (i === 0) {
                     $label.addClass('selected');
                     $label.addClass('selected');
                     $contentBox.addClass('selected');
                     $contentBox.addClass('selected');
                 }
                 }
                 $label.on('click', function() {
                 $label.on('click', function() {
                     $labelWrapper.find('.TabLabelText').removeClass('selected');
                     $labelWrapper.find('.TabLabelText').removeClass('selected');
第31行: 第57行:
                     $contentBox.addClass('selected');
                     $contentBox.addClass('selected');
                 });
                 });
                 $labelWrapper.append($label);
                 $labelWrapper.append($label);
                 $contentWrapper.append($contentBox);
                 $contentWrapper.append($contentBox);
             });
             });
             $tabsContainer.empty().append($labelWrapper).append($contentWrapper).addClass('tabs-initialized');
             $tabsContainer.empty().append($labelWrapper).append($contentWrapper).addClass('tabs-initialized');
         });
         });
第43行: 第67行:
             var match = $clicked.attr('class').match(/mw-customtoggle-game(\d+)/);
             var match = $clicked.attr('class').match(/mw-customtoggle-game(\d+)/);
             if (!match) return;
             if (!match) return;
             var $myContent = $('#mw-customcollapsible-game' + match[1]);
             var $myContent = $('#mw-customcollapsible-game' + match[1]);
             if ($myContent.hasClass('mw-collapsed')) {
             if ($myContent.hasClass('mw-collapsed')) {
第54行: 第77行:
                 });
                 });
             }
             }
        });
        $content.find('.mw-custom-notetip').on('mouseenter', function() {
            var $this = $(this);
            var rect = this.getBoundingClientRect();
            $tooltip.text($this.data('notetip')).show();
            var tipHeight = $tooltip.outerHeight();
            var top = window.scrollY + rect.top - tipHeight - 10;
            if (rect.top - tipHeight < 10) top = window.scrollY + rect.bottom + 10;
            $tooltip.css({
                'top': top + 'px',
                'left': (rect.left + (rect.width / 2) - ($tooltip.outerWidth() / 2)) + 'px'
            });
        }).on('mouseleave', function() {
            $tooltip.hide();
         });
         });
     });
     });
});
});

2026年5月10日 (日) 10:33的版本

$(function() {
    var $tooltip = $('#custom-notetip-popup');
    if (!$tooltip.length) {
        $tooltip = $('<div id="custom-notetip-popup"></div>').appendTo('body');
    }

    mw.hook('wikipage.content').add(function($content) {
        $content.find('.mw-custom-notetip').on('mouseenter', function() {
            var $this = $(this);
            var text = $this.attr('data-notetip');
            if (!text) return;

            var rect = this.getBoundingClientRect();
            $tooltip.text(text).show();

            var tipHeight = $tooltip.outerHeight();
            var tipWidth = $tooltip.outerWidth();
            
            var top = window.scrollY + rect.top - tipHeight - 10;
            var left = window.scrollX + rect.left + (rect.width / 2) - (tipWidth / 2);

            if (rect.top - tipHeight < 20) {
                top = window.scrollY + rect.bottom + 10;
            }

            var winWidth = $(window).width();
            if (left < 10) left = 10;
            if (left + tipWidth > winWidth - 10) left = winWidth - tipWidth - 10;

            $tooltip.css({ 'top': top + 'px', 'left': left + 'px', 'display': 'block' });
        }).on('mouseleave', function() {
            $tooltip.hide();
        });

        mw.loader.using('jquery.makeCollapsible').then(function() {
            $content.find('.mw-collapsible').makeCollapsible();
        });

        $content.find('.Tabs:not(.tabs-initialized)').each(function() {
            var $tabsContainer = $(this);
            var $tabItems = $tabsContainer.find('> .Tab');
            if (!$tabItems.length) return;
            var $labelWrapper = $('<div class="TabLabel"></div>');
            var $contentWrapper = $('<div class="TabContent"></div>');
            $tabItems.each(function(i) {
                var $item = $(this);
                var $label = $item.find('> .TabLabelText');
                var $contentBox = $item.find('> .TabContentText');
                if (i === 0) {
                    $label.addClass('selected');
                    $contentBox.addClass('selected');
                }
                $label.on('click', function() {
                    $labelWrapper.find('.TabLabelText').removeClass('selected');
                    $contentWrapper.find('.TabContentText').removeClass('selected');
                    $(this).addClass('selected');
                    $contentBox.addClass('selected');
                });
                $labelWrapper.append($label);
                $contentWrapper.append($contentBox);
            });
            $tabsContainer.empty().append($labelWrapper).append($contentWrapper).addClass('tabs-initialized');
        });

        $content.find('.nav-pill-btn').on('click', function() {
            var $clicked = $(this);
            var match = $clicked.attr('class').match(/mw-customtoggle-game(\d+)/);
            if (!match) return;
            var $myContent = $('#mw-customcollapsible-game' + match[1]);
            if ($myContent.hasClass('mw-collapsed')) {
                $('.nav-pill-content').not($myContent).each(function() {
                    var $other = $(this);
                    if (!$other.hasClass('mw-collapsed')) {
                        var otherNum = $other.attr('id').replace('mw-customcollapsible-game', '');
                        $('.mw-customtoggle-game' + otherNum).first().click();
                    }
                });
            }
        });
    });
});