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
,
28 cookieVal
= mw
.cookie
.get( cookieKey
),
31 function removeConfirmation() {
33 mw
.hook( 'postEdit.afterRemoval' ).fire();
36 function fadeOutConfirmation() {
38 $div
.find( '.postedit' ).addClass( 'postedit postedit-faded' );
39 setTimeout( removeConfirmation
, 500 );
44 function showConfirmation( data
) {
46 if ( data
.message
=== undefined ) {
47 data
.message
= $.parseHTML( mw
.message( 'postedit-confirmation-saved', data
.user
|| mw
.user
).escaped() );
50 $div
= mw
.template
.get( 'mediawiki.action.view.postEdit', 'postEdit.html' ).render();
52 if ( typeof data
.message
=== 'string' ) {
53 $div
.find( '.postedit-content' ).text( data
.message
);
54 } else if ( typeof data
.message
=== 'object' ) {
55 $div
.find( '.postedit-content' ).append( data
.message
);
59 .click( fadeOutConfirmation
)
62 id
= setTimeout( fadeOutConfirmation
, 3000 );
65 mw
.hook( 'postEdit' ).add( showConfirmation
);
67 if ( config
.wgAction
=== 'view' && cookieVal
) {
68 mw
.config
.set( 'wgPostEdit', true );
70 mw
.hook( 'postEdit' ).fire( {
71 // The following messages can be used here:
72 // postedit-confirmation-saved
73 // postedit-confirmation-created
74 // postedit-confirmation-restored
76 'postedit-confirmation-' + cookieVal
,
80 mw
.cookie
.set( cookieKey
, null );
83 }( mediaWiki
, jQuery
) );