Merge "RecentChanges, RecentChangesLinked, Watchlist: message when no items"
[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 if ( config.wgAction !== 'view' || $.cookie( cookieKey ) !== '1' ) {
10 return;
11 }
12
13 $.cookie( cookieKey, null, { path: '/' } );
14 mw.config.set( 'wgPostEdit', true );
15
16 function removeConfirmation() {
17 div.parentNode.removeChild( div );
18 mw.hook( 'postEdit.afterRemoval' ).fire();
19 }
20
21 function fadeOutConfirmation() {
22 clearTimeout( id );
23 div.firstChild.className = 'postedit postedit-faded';
24 setTimeout( removeConfirmation, 500 );
25 return false;
26 }
27
28 function showConfirmation() {
29 div = document.createElement( 'div' );
30 div.className = 'postedit-container';
31 div.innerHTML =
32 '<div class="postedit">' +
33 '<div class="postedit-icon postedit-icon-checkmark">' +
34 mw.message( 'postedit-confirmation', mw.user ).escaped() +
35 '</div>' +
36 '<a href="#" class="postedit-close">&times;</a>' +
37 '</div>';
38 id = setTimeout( fadeOutConfirmation, 3000 );
39 div.firstChild.lastChild.onclick = fadeOutConfirmation;
40 document.body.insertBefore( div, document.body.firstChild );
41 }
42
43 mw.hook( 'postEdit' ).add( showConfirmation ).fire();
44
45 } ( mediaWiki, jQuery ) );