7 * @param {Object} [data] Optional data
8 * @param {string|jQuery|Array} [data.message] Message that listeners
9 * should use when displaying notifications. String for plain text,
10 * use array or jQuery object to pass actual nodes.
11 * @param {string|mw.user} [data.user=mw.user] User that made the edit.
15 * After the listener for #postEdit removes the notification.
17 * @event postEdit_afterRemoval
21 var config
= mw
.config
.get( [ 'wgAction', 'wgCurRevisionId' ] ),
22 // This should match EditPage::POST_EDIT_COOKIE_KEY_PREFIX:
23 cookieKey
= 'PostEditRevision' + config
.wgCurRevisionId
,
24 cookieVal
= mw
.cookie
.get( cookieKey
),
27 function showConfirmation( data
) {
29 if ( data
.message
=== undefined ) {
30 data
.message
= $.parseHTML( mw
.message( 'postedit-confirmation-saved', data
.user
|| mw
.user
).escaped() );
33 $div
= mw
.template
.get( 'mediawiki.action.view.postEdit', 'postEdit.html' ).render();
35 if ( typeof data
.message
=== 'string' ) {
36 $div
.find( '.postedit-content' ).text( data
.message
);
37 } else if ( typeof data
.message
=== 'object' ) {
38 $div
.find( '.postedit-content' ).append( data
.message
);
42 .click( fadeOutConfirmation
)
45 id
= setTimeout( fadeOutConfirmation
, 3000 );
48 function fadeOutConfirmation() {
50 $div
.find( '.postedit' ).addClass( 'postedit postedit-faded' );
51 setTimeout( removeConfirmation
, 500 );
56 function removeConfirmation() {
58 mw
.hook( 'postEdit.afterRemoval' ).fire();
61 mw
.hook( 'postEdit' ).add( showConfirmation
);
63 if ( config
.wgAction
=== 'view' && cookieVal
) {
64 mw
.config
.set( 'wgPostEdit', true );
66 mw
.hook( 'postEdit' ).fire( {
67 // The following messages can be used here:
68 // postedit-confirmation-saved
69 // postedit-confirmation-created
70 // postedit-confirmation-restored
72 'postedit-confirmation-' + cookieVal
,
76 mw
.cookie
.set( cookieKey
, null );
79 } ( mediaWiki
, jQuery
) );