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
25 var config
= mw
.config
.get( [ 'wgAction', 'wgCurRevisionId' ] ),
26 // This should match EditPage::POST_EDIT_COOKIE_KEY_PREFIX:
27 cookieKey
= 'PostEditRevision' + config
.wgCurRevisionId
,
30 function removeConfirmation() {
32 mw
.hook( 'postEdit.afterRemoval' ).fire();
35 function fadeOutConfirmation() {
37 $div
.find( '.postedit' ).addClass( 'postedit postedit-faded' );
38 setTimeout( removeConfirmation
, 500 );
43 function showConfirmation( data
) {
45 if ( data
.message
=== undefined ) {
46 data
.message
= $.parseHTML( mw
.message( 'postedit-confirmation-saved', data
.user
|| mw
.user
).escaped() );
49 $div
= mw
.template
.get( 'mediawiki.action.view.postEdit', 'postEdit.html' ).render();
51 if ( typeof data
.message
=== 'string' ) {
52 $div
.find( '.postedit-content' ).text( data
.message
);
53 } else if ( typeof data
.message
=== 'object' ) {
54 $div
.find( '.postedit-content' ).append( data
.message
);
58 .click( fadeOutConfirmation
)
61 id
= setTimeout( fadeOutConfirmation
, 3000 );
64 mw
.hook( 'postEdit' ).add( showConfirmation
);
66 // Only when viewing wiki pages, that exist
67 // (E.g. not on special pages or non-view actions)
68 if ( config
.wgCurRevisionId
&& config
.wgAction
=== 'view' ) {
69 cookieVal
= mw
.cookie
.get( cookieKey
);
71 mw
.config
.set( 'wgPostEdit', true );
73 mw
.hook( 'postEdit' ).fire( {
74 // The following messages can be used here:
75 // postedit-confirmation-saved
76 // postedit-confirmation-created
77 // postedit-confirmation-restored
79 'postedit-confirmation-' + cookieVal
,
84 mw
.cookie
.set( cookieKey
, null );
88 }( mediaWiki
, jQuery
) );