跳转到内容

MediaWiki:Gadget-noteTAvector.js

维基百科,自由的百科全书

这是本页的一个历史版本,由WhitePhosphorus留言 | 贡献2023年6月17日 (六) 01:52 (Fix: do not remove the mw-indicator class - used by MediaWiki:Gadget-noteTA.js to add click event)编辑。这可能和当前版本存在着巨大的差异。

注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
var noteTAvector = ( function() {
    var associatedPages = document.getElementById( 'p-associated-pages' );
    var useLegacyMode = !associatedPages;
    var makeSpan = function () {
        return $( '<span style="padding:1px 3px; background: #d3e3f4; color:#000000;height:85%;">汉</span><span style="padding:1px 3px; background: #e9e9e9; color:#434343;height:85%;">漢</span>' );
    };
    var mapIndicatorLegacy = function() {
        $( '<a href="#">' ).html( makeSpan() )
            .click( function( e ) {
                e.preventDefault();
            } )
            .wrap( '<ul><li><span></span></li></ul>' )
            .parent().parent().parent().appendTo( this );
    };
    var mapIndicator = function () {
        makeSpan().appendTo( this );
    };

    var $node = $( 'body.skin-vector-legacy,body.skin-vector-2022' )
        .find( '.mw-indicator[id^=mw-indicator-noteTA-]' )
        .removeAttr( 'style' )
        .empty()
        .each( useLegacyMode ? mapIndicatorLegacy : mapIndicator );

    if ( useLegacyMode ) {
        $node.addClass( 'vector-menu' )
            .addClass( 'vector-menu-tabs' )
            .addClass( 'vector-menu-tabs-legacy' )
            .css( 'float', 'left' )
            .insertAfter( '#p-variants' );
    } else {
        if ( $node.length ) {
            var plink = mw.util.addPortletLink('p-associated-pages', '#', '' );
            var plinkAnchor = plink.querySelector( 'a' );
            plink.style.maxHeight = '32px';
            if ( plinkAnchor ) {
                $node.appendTo( plinkAnchor );
            }
        }
    }
} );

mw.hook('wikipage.content').add( function () {
    //if ( $( '#p-variants' ).next().hasClass('vectorTabs') ) return;
    $( '#p-variants' ).next().remove(); // Will blink duing load preview, but this will avoid the icon won't removed if the TA template is removed, and avoid repeated click event listener from noteTAViewer.
    $( function () {
        setTimeout(noteTAvector, 1);
    } );
});