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 form > 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' ) );

$( '#mw-content-text' ).on( 'click', '.edit-rollback', 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( 'Revert consecutive edits by ' + name + ' (talk)' );	}	// 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 ); } );

$( '#mw-content-text' ).on( 'click', '.rollback-submit-button', 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 $( '#mw-content-text' ).on( 'keypress', '.rollback-text', function ( e ) {	if ( e.which === 13 ) {		e.preventDefault;		$( '.rollback-submit-button' ).click;	} } );

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

} );