MediaWiki:CategoryListPrefixRemover.js

/** * Part of the "RemoveCategoryListPrefix" template * @see Template:RemoveCategoryListPrefix * * @author Daniel Werner * @version 0.1.1 * * History: * # Version 0.1  -- January 9, 2012: Initial release * # Version 0.1.1 -- January 11, 2012: MW 1.16 compatibility * * (c) 2012 - Daniel Werner */

// use addOnloadHook for MW 1.16 compatibility! addOnloadHook(function {

window.categoryListPrefixManager = new( function {	/*	 * Object for removing a certain prefix from category members on a category page.	 */ 	this.categoryListPrefixRemover = function {		/**		 * @var string		 */		this.prefix = '';		/**		 * Removes all prefixes from the pages category list.		 * @return integer number of replacements		 */		this.doRemove = function {			// escaped prefix for inner scope:			var prefix = ( this.prefix ).replace( new RegExp( '[.\\\\+*?\\[\\^\\]${}=!<>|:\\/-]','g' ), '\\$&' );			var i = 0; // counter			$( '#mw-pages ul li a' ).each( function( index ) { // get old text and remove prefix var expr = new RegExp( '^' + prefix ); var oldText = $( this ).text; var newText = oldText.replace( expr, '' ); if( newText !== oldText ) { i++; }				// set new text $( this ).text( newText ); } );			return i;		}		/**		 * Sets the prefix that should be removed when calling this.remove		 */		this.setPrefix = function( prefix ) {			this.prefix = prefix;		}		/**		 * @return string the prefix		 */		this.getPrefix = function {			return this.prefix;		}	}

var remover = new this.categoryListPrefixRemover; $( '.categoryListPrefixRemover' ).each( function( index ) {		var prefix = $.trim( $( this ).text );		remover.setPrefix( prefix + ':' );		remover.doRemove;		return;	} ); } );

} ); //END addOnloadHook