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 removeConfirmation() {
29 mw
.hook( 'postEdit.afterRemoval' ).fire();
32 function fadeOutConfirmation() {
34 $div
.find( '.postedit' ).addClass( 'postedit postedit-faded' );
35 setTimeout( removeConfirmation
, 500 );
40 function showConfirmation( data
) {
42 if ( data
.message
=== undefined ) {
43 data
.message
= $.parseHTML( mw
.message( 'postedit-confirmation-saved', data
.user
|| mw
.user
).escaped() );
46 $div
= mw
.template
.get( 'mediawiki.action.view.postEdit', 'postEdit.html' ).render();
48 if ( typeof data
.message
=== 'string' ) {
49 $div
.find( '.postedit-content' ).text( data
.message
);
50 } else if ( typeof data
.message
=== 'object' ) {
51 $div
.find( '.postedit-content' ).append( data
.message
);
55 .click( fadeOutConfirmation
)
58 id
= setTimeout( fadeOutConfirmation
, 3000 );
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
) );