MediaWiki:Gadget-Infobox.js

From wikishia

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
( function ( $ ) {
    'use strict';
    $( function () {
        $( '.switcher-container' ).each( function ( i ) {
            var activeElement, $showRadio, $showAllRadio;
            var elements = [], container = this;
            var radioName = 'switcher-' + i;
            $( this ).children().each( function () {
                var self = this;
                var $labelContainer = $( this ).find( '.switcher-label' );
                var $labelText = $labelContainer.contents();
                if ( !$labelText.length ) {
                    return;
                }
                elements.push( this );
                $showRadio = $( '<input type="radio" />' ).attr( 'name', radioName ).click( function () {
                    $( activeElement ).hide();
                    $( self ).show();
                    activeElement = self;
                } );
                $( '<label style="white-space: nowrap"></label>' ).append( $showRadio ).append( $labelText ).appendTo( container ).after( '<wbr>' );
                if ( !activeElement ) {
                    activeElement = this;
                    $showRadio.prop( 'checked', true );
                } else if ( $labelContainer.is( '[data-switcher-default]' ) ) {
                    $showRadio.click();
                } else {
                    $( this ).hide();
                }
                $labelContainer.remove();
            } );
            if ( elements.length > 1 ) {
                $.when( mw.loader.using( [ 'mediawiki.api' ] ) )
                    .then( function () {
                        return new mw.Api().loadMessagesIfMissing( ['Pagetriage-filter-all'] );
                    })
                    .then( function () {
                        $showAllRadio = $( '<input type="radio" />' ).attr( 'name', radioName ).click( function () {
                            $( elements ).show();
                            activeElement = elements;
                        } );
                        $( '<label style="display:block">' )
                            .text( " " + mw.msg( 'Pagetriage-filter-all' ) )
                            .prepend( $showAllRadio )
                            .appendTo( container );
                    } );
            } else if ( elements.length === 1 ) {
                $showRadio.remove();
            }
        } );
    } );
} )( jQuery );