Merge "Move section ID fallbacks into headers themselves"
[lhc/web/wiklou.git] / resources / src / mediawiki.action / mediawiki.action.view.postEdit.js
index 5dfdede..e0ab45a 100644 (file)
         * @member mw.hook
         */
 
-       var config = mw.config.get( [ 'wgAction', 'wgCurRevisionId' ] ),
-               // This should match EditPage::POST_EDIT_COOKIE_KEY_PREFIX:
-               cookieKey = 'PostEditRevision' + config.wgCurRevisionId,
-               cookieVal, $div, id;
-
-       function removeConfirmation() {
-               $div.remove();
-               mw.hook( 'postEdit.afterRemoval' ).fire();
-       }
-
-       function fadeOutConfirmation() {
-               clearTimeout( id );
-               $div.find( '.postedit' ).addClass( 'postedit postedit-faded' );
-               setTimeout( removeConfirmation, 500 );
-
-               return false;
-       }
+       var postEdit = mw.config.get( 'wgPostEdit' );
 
        function showConfirmation( data ) {
+               var $container, $popup, $content, timeoutId;
+
+               function fadeOutConfirmation() {
+                       $popup.addClass( 'postedit-faded' );
+                       setTimeout( function () {
+                               $container.remove();
+                               mw.hook( 'postEdit.afterRemoval' ).fire();
+                       }, 250 );
+               }
+
                data = data || {};
+
                if ( data.message === undefined ) {
                        data.message = $.parseHTML( mw.message( 'postedit-confirmation-saved', data.user || mw.user ).escaped() );
                }
 
-               $div = mw.template.get( 'mediawiki.action.view.postEdit', 'postEdit.html' ).render();
-
+               $content = $( '<div>' ).addClass( 'postedit-icon postedit-icon-checkmark postedit-content' );
                if ( typeof data.message === 'string' ) {
-                       $div.find( '.postedit-content' ).text( data.message );
+                       $content.text( data.message );
                } else if ( typeof data.message === 'object' ) {
-                       $div.find( '.postedit-content' ).append( data.message );
+                       $content.append( data.message );
                }
 
-               $div
-                       .click( fadeOutConfirmation )
-                       .prependTo( 'body' );
+               $popup = $( '<div>' ).addClass( 'postedit mw-notification' ).append( $content )
+                       .click( function () {
+                               clearTimeout( timeoutId );
+                               fadeOutConfirmation();
+                       } );
+
+               $container = $( '<div>' ).addClass( 'postedit-container' ).append( $popup );
+               timeoutId = setTimeout( fadeOutConfirmation, 3000 );
 
-               id = setTimeout( fadeOutConfirmation, 3000 );
+               $( 'body' ).prepend( $container );
        }
 
        mw.hook( 'postEdit' ).add( showConfirmation );
 
-       // Only when viewing wiki pages, that exist
-       // (E.g. not on special pages or non-view actions)
-       if ( config.wgCurRevisionId && config.wgAction === 'view' ) {
-               cookieVal = mw.cookie.get( cookieKey );
-               if ( cookieVal ) {
-                       mw.config.set( 'wgPostEdit', true );
-
-                       mw.hook( 'postEdit' ).fire( {
-                               // The following messages can be used here:
-                               // postedit-confirmation-saved
-                               // postedit-confirmation-created
-                               // postedit-confirmation-restored
-                               message: mw.msg(
-                                       'postedit-confirmation-' + cookieVal,
-                                       mw.user
-                               )
-                       } );
-
-                       mw.cookie.set( cookieKey, null );
-               }
+       if ( postEdit ) {
+               mw.hook( 'postEdit' ).fire( {
+                       // The following messages can be used here:
+                       // postedit-confirmation-saved
+                       // postedit-confirmation-created
+                       // postedit-confirmation-restored
+                       message: mw.msg(
+                               'postedit-confirmation-' + postEdit,
+                               mw.user
+                       )
+               } );
        }
 
 }( mediaWiki, jQuery ) );