Merge "resourceloader: Sanitize lang code before creating Language object"
[lhc/web/wiklou.git] / resources / mediawiki / mediawiki.notification.js
index 4ede809..b5fd69c 100644 (file)
@@ -4,21 +4,23 @@
        var notification,
                // The #mw-notification-area div that all notifications are contained inside.
                $area,
+               // Number of open notification boxes at any time
+               openNotificationCount = 0,
                isPageReady = false,
                preReadyNotifQueue = [];
 
        /**
-        * Creates a Notification object for 1 message.
-        * Does not insert anything into the document (see #start).
+        * A Notification object for 1 message.
         *
-        * The "_" in the name is to avoid a bug (http://github.com/senchalabs/jsduck/issues/304)
+        * The "_" in the name is to avoid a bug (http://github.com/senchalabs/jsduck/issues/304).
         * It is not part of the actual class name.
         *
         * @class mw.Notification_
         * @alternateClassName mw.Notification
-        * @private
         *
-        * @constructor
+        * @constructor The constructor is not publicly accessible; use mw.notification#notify instead.
+        *  This does not insert anything into the document (see #start).
+        * @private
         */
        function Notification( message, options ) {
                var $notification, $notificationTitle, $notificationContent;
        }
 
        /**
-        * Start the notification.
-        * This inserts it into the page, closes any matching tagged notifications,
-        * handles the fadeIn animations and repacement transitions, and starts autoHide timers.
+        * Start the notification. Called automatically by mw.notification#notify
+        * (possibly asynchronously on document-ready).
+        *
+        * This inserts the notification into the page, closes any matching tagged notifications,
+        * handles the fadeIn animations and replacement transitions, and starts autoHide timers.
+        *
+        * @private
         */
        Notification.prototype.start = function () {
                var
                        autohideCount,
                        notif;
 
+               $area.show();
+
                if ( this.isOpen ) {
                        return;
                }
 
                this.isOpen = true;
+               openNotificationCount++;
 
                options = this.options;
                $notification = this.$notification;
         * Close/hide the notification.
         *
         * @param {Object} options An object containing options for the closing of the notification.
-        *  These are typically only used internally.
         *
         *  - speed: Use a close speed different than the default 'slow'.
         *  - placeholder: Set to false to disable the placeholder transition.
                        return;
                }
                this.isOpen = false;
+               openNotificationCount--;
                // Clear any remaining timeout on close
                this.pause();
 
                                complete: function () {
                                        // Remove the notification
                                        $( this ).remove();
+                                       // Hide the area manually after closing the last notification, since it has padding,
+                                       // causing it to obscure whatever is behind it in spite of being invisible (bug 52659).
+                                       // It's okay to do this before getting rid of the placeholder, as it's invisible as well.
+                                       if ( openNotificationCount === 0 ) {
+                                               $area.hide();
+                                       }
                                        if ( options.placeholder ) {
                                                // Use a fast slide up animation after closing to make it look like the notifications
                                                // below slide up into place when the notification disappears
         * Helper function, take a list of notification divs and call
         * a function on the Notification instance attached to them.
         *
+        * @private
+        * @static
         * @param {jQuery} $notifications A jQuery object containing notification divs
         * @param {string} fn The name of the function to call on the Notification instance
         */
                 * @param {HTMLElement|jQuery|mw.Message|string} message
                 * @param {Object} options The options to use for the notification.
                 *  See #defaults for details.
-                * @return {Object} Object with a close function to close the notification
+                * @return {mw.Notification} Notification object
                 */
                notify: function ( message, options ) {
                        var notif;
                        } else {
                                preReadyNotifQueue.push( notif );
                        }
-                       return { close: $.proxy( notif.close, notif ) };
+
+                       return notif;
                },
 
                /**