Merge "Add url parameter to trigger autogenerated gallery type."
[mediawiki.git] / resources / mediawiki.action / mediawiki.action.view.postEdit.js
blob8e67ea92bd43aab2ca3e947a9eab5d887048c45c
1 ( function ( mw, $ ) {
2         'use strict';
4         var config = mw.config.get( [ 'wgAction', 'wgCookiePrefix', 'wgCurRevisionId' ] ),
5                 // This should match EditPage::POST_EDIT_COOKIE_KEY_PREFIX:
6                 cookieKey = config.wgCookiePrefix + 'PostEditRevision' + config.wgCurRevisionId,
7                 $div, id;
9         function showConfirmation( data ) {
10                 data = data || {};
11                 if ( data.message === undefined ) {
12                         data.message = $.parseHTML( mw.message( 'postedit-confirmation', data.user || mw.user ).escaped() );
13                 }
15                 $div = $(
16                         '<div class="postedit-container">' +
17                                 '<div class="postedit">' +
18                                         '<div class="postedit-icon postedit-icon-checkmark postedit-content"></div>' +
19                                         '<a href="#" class="postedit-close">&times;</a>' +
20                                 '</div>' +
21                         '</div>'
22                 );
24                 if ( typeof data.message === 'string' ) {
25                         $div.find( '.postedit-content' ).text( data.message );
26                 } else if ( typeof data.message === 'object' ) {
27                         $div.find( '.postedit-content' ).append( data.message );
28                 }
30                 $div
31                         .click( fadeOutConfirmation )
32                         .prependTo( 'body' );
34                 id = setTimeout( fadeOutConfirmation, 3000 );
35         }
37         function fadeOutConfirmation() {
38                 clearTimeout( id );
39                 $div.find( '.postedit' ).addClass( 'postedit postedit-faded' );
40                 setTimeout( removeConfirmation, 500 );
42                 return false;
43         }
45         function removeConfirmation() {
46                 $div.remove();
47                 mw.hook( 'postEdit.afterRemoval' ).fire();
48         }
50         mw.hook( 'postEdit' ).add( showConfirmation );
52         if ( config.wgAction === 'view' && $.cookie( cookieKey ) === '1' ) {
53                 $.cookie( cookieKey, null, { path: '/' } );
54                 mw.config.set( 'wgPostEdit', true );
56                 /**
57                  * @event postEdit
58                  * @member mw.hook
59                  * @param {Object} [data]
60                  * @param {string|jQuery|Array} [data.message] Message that listeners
61                  *  should use when displaying notifications. String for plain text,
62                  *  use array or jQuery object to pass actual nodes.
63                  * @param {string|mw.user} [data.user=mw.user] User that made the edit.
64                  */
65                 mw.hook( 'postEdit' ).fire();
66         }
68 } ( mediaWiki, jQuery ) );