Localisation updates from https://translatewiki.net.
[mediawiki.git] / resources / mediawiki.action / mediawiki.action.view.postEdit.js
blob6e4df9f0d2c59c4461538e18fb35ad4ca9f25cfe
1 ( function ( mw, $ ) {
2         'use strict';
4         /**
5          * @event postEdit
6          * @member mw.hook
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.
12          */
14         /**
15          * After the listener for #postEdit removes the notification.
16          *
17          * @event postEdit_afterRemoval
18          * @member mw.hook
19          */
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                 $div, id;
26         function showConfirmation( data ) {
27                 data = data || {};
28                 if ( data.message === undefined ) {
29                         data.message = $.parseHTML( mw.message( 'postedit-confirmation', data.user || mw.user ).escaped() );
30                 }
32                 $div = $(
33                         '<div class="postedit-container">' +
34                                 '<div class="postedit">' +
35                                         '<div class="postedit-icon postedit-icon-checkmark postedit-content"></div>' +
36                                         '<a href="#" class="postedit-close">&times;</a>' +
37                                 '</div>' +
38                         '</div>'
39                 );
41                 if ( typeof data.message === 'string' ) {
42                         $div.find( '.postedit-content' ).text( data.message );
43                 } else if ( typeof data.message === 'object' ) {
44                         $div.find( '.postedit-content' ).append( data.message );
45                 }
47                 $div
48                         .click( fadeOutConfirmation )
49                         .prependTo( 'body' );
51                 id = setTimeout( fadeOutConfirmation, 3000 );
52         }
54         function fadeOutConfirmation() {
55                 clearTimeout( id );
56                 $div.find( '.postedit' ).addClass( 'postedit postedit-faded' );
57                 setTimeout( removeConfirmation, 500 );
59                 return false;
60         }
62         function removeConfirmation() {
63                 $div.remove();
64                 mw.hook( 'postEdit.afterRemoval' ).fire();
65         }
67         mw.hook( 'postEdit' ).add( showConfirmation );
69         if ( config.wgAction === 'view' && $.cookie( cookieKey ) === '1' ) {
70                 $.cookie( cookieKey, null, { path: '/' } );
71                 mw.config.set( 'wgPostEdit', true );
73                 mw.hook( 'postEdit' ).fire();
74         }
76 } ( mediaWiki, jQuery ) );