5 * Fired after an edit was successfully saved.
7 * Does not fire for null edits.
11 * @param {Object} [data] Optional data
12 * @param {string|jQuery|Array} [data.message] Message that listeners
13 * should use when displaying notifications. String for plain text,
14 * use array or jQuery object to pass actual nodes.
15 * @param {string|mw.user} [data.user=mw.user] User that made the edit.
19 * After the listener for #postEdit removes the notification.
21 * @event postEdit_afterRemoval
26 config
= mw
.config
.get( [ 'wgAction', 'wgCurRevisionId' ] ),
27 // This should match EditPage::POST_EDIT_COOKIE_KEY_PREFIX:
28 cookieKey
= 'PostEditRevision' + config
.wgCurRevisionId
;
30 function showConfirmation( data
) {
31 var $container
, $popup
, $content
, timeoutId
;
33 function fadeOutConfirmation() {
34 $popup
.addClass( 'postedit-faded' );
35 setTimeout( function () {
37 mw
.hook( 'postEdit.afterRemoval' ).fire();
43 if ( data
.message
=== undefined ) {
44 data
.message
= $.parseHTML( mw
.message( 'postedit-confirmation-saved', data
.user
|| mw
.user
).escaped() );
47 $content
= $( '<div>' ).addClass( 'postedit-icon postedit-icon-checkmark postedit-content' );
48 if ( typeof data
.message
=== 'string' ) {
49 $content
.text( data
.message
);
50 } else if ( typeof data
.message
=== 'object' ) {
51 $content
.append( data
.message
);
54 $popup
= $( '<div>' ).addClass( 'postedit mw-notification' ).append(
56 $( '<a>' ).addClass( 'postedit-close' ).attr( 'href', '#' ).text( '×' )
57 ).on( 'click', function ( e
) {
59 clearTimeout( timeoutId
);
60 fadeOutConfirmation();
63 $container
= $( '<div>' ).addClass( 'postedit-container' ).append( $popup
);
64 timeoutId
= setTimeout( fadeOutConfirmation
, 3000 );
66 $( 'body' ).prepend( $container
);
69 mw
.hook( 'postEdit' ).add( showConfirmation
);
71 // Only when viewing wiki pages, that exist
72 // (E.g. not on special pages or non-view actions)
73 if ( config
.wgCurRevisionId
&& config
.wgAction
=== 'view' ) {
74 cookieVal
= mw
.cookie
.get( cookieKey
);
76 mw
.config
.set( 'wgPostEdit', true );
78 mw
.hook( 'postEdit' ).fire( {
79 // The following messages can be used here:
80 // postedit-confirmation-saved
81 // postedit-confirmation-created
82 // postedit-confirmation-restored
84 'postedit-confirmation-' + cookieVal
,
89 mw
.cookie
.set( cookieKey
, null );
93 }( mediaWiki
, jQuery
) );