MediaWiki:Gadget-editableRollback.js

$( function { 'use strict';

$( '.mw-rollback-link' ).find( 'a' ).click( function( evt ) {   var $rollback = $( '#rollback-summary' ), tmp;    evt.preventDefault;    if ( $( this ).parent.find( $rollback ).length ) {        $rollback.toggle;    } else {        var name;        $rollback.remove;        $( this ).prop( 'href', function( $, href ) { name = href.match( /&from=([^&]*)&token/ ); name = name[1].replace( /\+/g, ' ' ); } );       $( this ).after( ' ' +               '  ' + '' + ' '       );        $rollback = $( '#rollback-summary' );        // Style rollback form        $rollback.css( { '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.find( 'form' ).css( 'position', 'relative' );        $rollback.find( 'span' ).css( { 'position': 'absolute', 'left': '0px', 'right': '88px', 'top': '1px' } );       $rollback.find( '.rollback-submit-button' ).css( { 'position': 'absolute', 'right': '0' } );        // Default rollback text        $rollback.find( '.rollback-text' ).css( 'width', '100%' )                                          .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;    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( 'a' ) ) && !$( event.target ).is( $( '#rollback-summary' ) ) && !$( '#rollback-summary' ).has( event.target ).length ) {        $( '#rollback-summary' ).remove;    } } );

} );