User:MSchottlender-WMF/MinimalRCFilters.js

/** * A gadget to toggle normal and minimal view for RCFilters product * ** Advanced users only ** * Please note that this must be loaded along with the CSS side. * * To use: * In your User/common.js load both files: * mw.loader.load( 'https://www.mediawiki.org/w/index.php?title=User:MSchottlender-WMF/MinimalRCFilters.css&action=raw&ctype=text/css', 'text/css' ); * mw.loader.load( 'https://www.mediawiki.org/w/index.php?title=User:MSchottlender-WMF/MinimalRCFilters.js&action=raw&ctype=text/javascript' ); */ ( function ( mw, $ ) { 	if ( !$( '.rcfilters-head' ).length ) { 		return; 	}

// Only load where RCFilters exist mw.hook( 'advanced-filters-ui-initialized' ).add( function {		// NOTE: The advanced-filters-ui-initialized will be available soon		// Using 'wikipage.content' is unsafe because it is fired multiple times		// when results are reloaded.		var prefName = 'userjs-rcfilters-view-minimal',			currValue = mw.user.options.get( prefName ) || 'normal',			$button = $( ' ' )				.text( 'Toggle Minimal' )				.on( 'click', function  { var newState = currValue === 'normal' ? 'minimal' : 'normal'; // Update cookie mw.user.options.set( prefName, newState ); new mw.Api.saveOption( prefName, newState ); // Toggle the class $( '.mw-rcfilters-ui-ready' ).toggleClass( 'mw-rcfilters-ui-minimal', newState === 'minimal' ); $( '.mw-rcfilters-ui-overlay' ).toggleClass( 'mw-rcfilters-ui-minimal', newState === 'minimal' ); // Update button label updateButtonLabel( newState ); // Update value currValue = newState; } );		// Initialize		updateButtonLabel( currValue );		$( '.mw-rcfilters-ui-filterWrapperWidget-top .mw-rcfilters-ui-table .mw-rcfilters-ui-row' )			.append( $( ' ' )					.addClass( 'mw-rcfilters-ui-cell' ) .append(						$( ' ' )							.addClass( 'mw-rcfilters-ui-cell' )							.append( $button )					) );		function updateButtonLabel( state ) {			$button.text( state === 'normal' ? 'Set Minimal View' : 'Set Normal View' );		}	} ); }( mediaWiki, jQuery ) );