MediaWiki:Gadget-switcher.js

De Wikipedia, la enciclopedia libre

Nota: Después de guardar, debes refrescar la caché de tu navegador para ver los cambios. Internet Explorer: mantén presionada Ctrl mientras pulsas Actualizar. Firefox: mientras presionas Mayús pulsas el botón Actualizar, (o presiona Ctrl-Shift-R). Los usuarios de Google Chrome y Safari pueden simplemente pulsar el botón Recargar. Para más detalles e instrucciones acerca de otros exploradores, véase Ayuda:Cómo limpiar la caché.

'use strict';
$( function () {
	$.each( document.querySelectorAll( '.switcher-container' ), function ( i ) {
		var activeElement, $radio,
			switchers = [], container = this, radioName = 'switcher-' + i, compact = $(container).hasClass('compact');
		$.each( this.children, function () {
			var switcher = this,
				$labelContainer = $( switcher.querySelector('.switcher-label') ),
				$labelText = $labelContainer.contents();
			if ( !$labelText.length ) {
				return;
			}
			switchers.push( switcher );
			$radio = $( '<input type="radio">' ).attr( 'name', radioName ).click( function () {
				$( activeElement ).hide();
				$( switcher ).show();
				activeElement = switcher;
			} );
			if ( !activeElement ) {
				// Elegir el primer elemento por defecto
				activeElement = switcher;
				$radio.prop( 'checked', true );
			} else if ( $labelContainer.attr( 'data-switcher-default' ) !== undefined ) {
				// Selección por defecto predeterminada
				$radio.click();
			} else {
				// Ocultar otras opciones
				$( switcher ).hide();
}
                        var $label = $( '<label style="display:block"></label>' );

                        //Estilo compacto
                        if ( compact ) {
                                $label.removeAttr('style');
                        }
                        $label.append( $radio, $labelText ).appendTo( container );
                        $labelContainer.remove();
		} );
		if ( switchers.length > 1 && !compact ) {
			$( '<label style="display:block">Ver todo</label>' ).prepend(
				$( '<input type="radio">' ).attr( 'name', radioName ).click( function () {
					$( switchers ).show();
					activeElement = switchers;
				} )
			).appendTo( container );
		}
		if ( switchers.length === 1 ) {
			$radio.remove();
		}
	} );
} );