MediaWiki:Gadget-editableRollback.js

$( function { 'use strict';

$( '.mw-rollback-link' ).find( 'a' ).after( ' ' )

// Style all the things in one go mw.util.addCSS( [	'.edit-rollback {',		'display: inline-block;',		'width: 10px;',		'height: 10px;',		'margin-left: 2px;',		'background-image: url(http://media-mcw.cursecdn.com/6/6c/Edit_pencil.png);',		'cursor: pointer;',	'}',	'#rollback-summary {',		'position: absolute;',		'padding: 10px;',		'border: 1px solid #CCC;',		'background-color: #F9F9F9;',		'left: 182px;',		'z-index: 99;',		'right: 26px;',		'height: 24px;',		'box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.2);',	'}',	'#rollback-summary form {',		'position: relative;',	'}',	'#rollback-summary span {',		'position: absolute;',		'left: 0;',		'right: 88px;',		'top: 1px;',	'}',	'#rollback-summary .rollback-submit-button {',		'position: absolute;',		'right: 0',	'}',	'#rollback-summary .rollback-text {',		'width: 100%;',	'}' ].join( '\n' ) );

$( '#content' ).delegate( '.edit-rollback', 'click', function {	var $rollback = $( '#rollback-summary' );	if ( $( this ).parent.find( $rollback ).length ) {		$rollback.toggle;	} else {		$rollback.remove;		var name;		$( this ).closest( '.mw-rollback-link' ).find( 'a' ).prop( 'href', function( $, href ) { name = href.match( /&from=([^&]*)&token/ ); name = name[1].replace( /\+/g, ' ' ); } );		$( this ).after( ' ' +				'  ' + '' + ' '		);		$rollback = $( '#rollback-summary' );		// Default rollback text		$rollback.find( '.rollback-text' ).val( 'Reverted edits by ' + name + ' (talk) to last revision by $1' );	}	// This puts the cursor at the end of the text	$rollback.find( 'input:first' ).focus;	var tmp = $rollback.find( 'input:first' ).val;	$rollback.find( 'input:first' ).val( '' ).val( tmp ); } );

$( '.rollback-submit-button' ).live( 'click', function {	var $link = $( this ).closest( '.mw-rollback-link' );	window.location = $link.find( 'a' ).prop( 'href' ) + '&summary=' + $link.find( '.rollback-text' ).val; } );

// Allow rollback to be submitted by pressing enter while focused on the input field $( '.rollback-text' ).live( 'keypress', function ( evt ) {	if ( evt.which === 13 ) {		evt.preventDefault;		$( '.rollback-submit-button' ).click;	} } );

// Close rollback if clicked anywhere else $( window ).click( function( event ) {	if ( !$( event.target ).is( $( '.mw-rollback-link' ).find( '.edit-rollback' ) ) && !$( event.target ).is( $( '#rollback-summary' ) ) && !$( '#rollback-summary' ).has( event.target ).length ) {		$( '#rollback-summary' ).remove;	} } );

} );