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', 'wgCookiePrefix', 'wgCurRevisionId' ] ),
22 // This should match EditPage::POST_EDIT_COOKIE_KEY_PREFIX:
23 cookieKey
= config
.wgCookiePrefix
+ 'PostEditRevision' + config
.wgCurRevisionId
,
24 cookieVal
= $.cookie( cookieKey
),
27 function showConfirmation( data
) {
29 if ( data
.message
=== undefined ) {
30 data
.message
= $.parseHTML( mw
.message( 'postedit-confirmation-saved', data
.user
|| mw
.user
).escaped() );
34 '<div class="postedit-container">' +
35 '<div class="postedit">' +
36 '<div class="postedit-icon postedit-icon-checkmark postedit-content"></div>' +
37 '<a href="#" class="postedit-close">×</a>' +
42 if ( typeof data
.message
=== 'string' ) {
43 $div
.find( '.postedit-content' ).text( data
.message
);
44 } else if ( typeof data
.message
=== 'object' ) {
45 $div
.find( '.postedit-content' ).append( data
.message
);
49 .click( fadeOutConfirmation
)
52 id
= setTimeout( fadeOutConfirmation
, 3000 );
55 function fadeOutConfirmation() {
57 $div
.find( '.postedit' ).addClass( 'postedit postedit-faded' );
58 setTimeout( removeConfirmation
, 500 );
63 function removeConfirmation() {
65 mw
.hook( 'postEdit.afterRemoval' ).fire();
68 mw
.hook( 'postEdit' ).add( showConfirmation
);
70 if ( config
.wgAction
=== 'view' && cookieVal
) {
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
,
83 $.cookie( cookieKey
, null, { path
: '/' } );
86 } ( mediaWiki
, jQuery
) );