Merge "Reorder SpecialRecentChanges::webOutput"
[lhc/web/wiklou.git] / resources / mediawiki.action / mediawiki.action.view.postEdit.js
1 ( function ( mw, $ ) {
2 'use strict';
3
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;
8
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 }
14
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 );
23
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 }
29
30 $div
31 .click( fadeOutConfirmation )
32 .prependTo( 'body' );
33
34 id = setTimeout( fadeOutConfirmation, 3000 );
35 }
36
37 function fadeOutConfirmation() {
38 clearTimeout( id );
39 $div.find( '.postedit' ).addClass( 'postedit postedit-faded' );
40 setTimeout( removeConfirmation, 500 );
41
42 return false;
43 }
44
45 function removeConfirmation() {
46 $div.remove();
47 mw.hook( 'postEdit.afterRemoval' ).fire();
48 }
49
50 mw.hook( 'postEdit' ).add( showConfirmation );
51
52 if ( config.wgAction === 'view' && $.cookie( cookieKey ) === '1' ) {
53 $.cookie( cookieKey, null, { path: '/' } );
54 mw.config.set( 'wgPostEdit', true );
55
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 }
67
68 } ( mediaWiki, jQuery ) );