User:Bene*/summary.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/**
* Script to allow adding edit summaries to edits.
*
* @author [[User:Bene*]]
*/
( function( $, mw, wb ) {
'use strict';
if ( mw.config.get( 'wbEntityId' ) === null ) {
return;
}
var widgetOpener = '<a href="#"\
class="summary-toggle ui-toggler-icon ui-icon ui-icon-triangle-1-s ui-toggler-icon3dtrans"\
style="display: inline-block; width: 15px; height: 12px;"\
></a>';
var summary = '';
var oldPost = wb.api.RepoApi.prototype._post;
wb.api.RepoApi.prototype._post = function( params ) {
if ( summary !== '' ) {
params.summary = summary;
summary = '';
}
return oldPost.apply( this, [params] );
};
function showWidget() {
summary = prompt( 'Editsummary:', summary );
}
function addWidgetOpener() {
// wait for ajax calls to finish
setTimeout( function() {
$( '.summary-toggle' ).remove();
$( '.wikibase-toolbar-button-save' ).after(
$( widgetOpener ).click( function( e ) {
e.preventDefault();
showWidget();
} )
);
}, 1000 );
}
$( function() {
$( document ).on( 'click', '.wikibase-toolbar-button-edit, .wikibase-toolbar-button-add', function() {
addWidgetOpener( $( this ) );
} );
} );
} )( jQuery, mediaWiki, wikibase );