MediaWiki:Gadget-switcher.js

'use strict'; $( function {	$.each( document.querySelectorAll( '.switcher-container' ), function ( i ) { var activeElement, $radio, switchers = [], container = this, radioName = 'switcher-' + i;		$.each( this.children, function {			var switcher = this,				$labelContainer = $( switcher.querySelector('.switcher-label') ),				$labelText = $labelContainer.contents;			if ( !$labelText.length ) {				return;			}			switchers.push( switcher );			$radio = $( ' ' ).attr( 'name', radioName ).click( function  { $( activeElement ).hide; $( switcher ).show; activeElement = switcher; } );			if ( !activeElement ) {				// Mark the first one as selected				activeElement = switcher;				$radio.prop( 'checked', true );			} else if ( $labelContainer.attr( 'data-switcher-default' ) !== undefined ) {				// Custom default				$radio.click;			} else {				// Hide non-default				$( switcher ).hide;			}			$( ' ' ).append( $radio, $labelText ).appendTo( container );			$labelContainer.remove;		} ); if ( switchers.length > 1 ) { $( 'Show all ' ).prepend(				$( ' ' ).attr( 'name', radioName ).click( function { $( switchers ).show; activeElement = switchers; } )			).appendTo( container ); }		if ( switchers.length === 1 ) { $radio.remove; }	} ); } );