mw.notification: Re-implement autoHideSeconds as string preset option
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 20 Jan 2017 03:25:59 +0000 (03:25 +0000)
committerAaron Schulz <aschulz@wikimedia.org>
Sun, 22 Jan 2017 07:43:18 +0000 (07:43 +0000)
Instead of allowing freeform number values, make it a preset-based
string where pre-defined values are encouraged.

A numerical override is still possible by creating a new preset,
but this undocumented/private for now.

Follows-up 4b9992a0, which added this option. No usage found
as of yet in Wikimedia Git, thus no deprecation/back-compat.

Also:
* Unbreaks `#autoHideSeconds` reference in #autoHideLimit doc.
* Improve wording of #autoHideLimit doc.

Bug: T155228
Change-Id: Id84d8b616fe26b9976263f4bd6bdc70cc8a539ba

resources/src/mediawiki/mediawiki.notification.js

index 7a3fb0a..4849f5a 100644 (file)
@@ -71,7 +71,7 @@
                $notificationContent.appendTo( $notification );
 
                // Private state parameters, meant for internal use only
-               // autoHideSeconds: Number of seconds to wait before auto-hiding notifications.
+               // autoHideSeconds: String alias for number of seconds for timeout of auto-hiding notifications.
                // isOpen: Set to true after .start() is called to avoid double calls.
                //         Set back to false after .close() to avoid duplicating the close animation.
                // isPaused: false after .resume(), true after .pause(). Avoids duplicating or breaking the hide timeouts.
@@ -80,8 +80,9 @@
                //          to stop replacement of a tagged notification with another notification using the same message.
                // options: The options passed to the notification with a little sanitization. Used by various methods.
                // $notification: jQuery object containing the notification DOM node.
-               // Set hide delay
-               this.autoHideSeconds = options.autoHideSeconds;
+               this.autoHideSeconds = options.autoHideSeconds &&
+                       notification.autoHideSeconds[ options.autoHideSeconds ] ||
+                       notification.autoHideSeconds.short;
                this.isOpen = false;
                this.isPaused = true;
                this.message = message;
                 *   be hidden after shown. Or if it should persist.
                 *
                 * - autoHideSeconds:
-                *   Number of seconds to wait before auto-hiding notifications.
+                *   Key to #autoHideSeconds for number of seconds for timeout of auto-hide
+                *   notifications.
                 *
                 * - tag:
                 *   An optional string. When a notification is tagged only one message
                 */
                defaults: {
                        autoHide: true,
-                       autoHideSeconds: 5,
+                       autoHideSeconds: 'short',
                        tag: false,
                        title: undefined,
                        type: false
                },
 
+               /**
+                * @private
+                * @property {Object}
+                */
+               autoHideSeconds: {
+                       'short': 5,
+                       'long': 30
+               },
+
                /**
                 * @property {number}
-                * Maximum number of notifications to count down auto-hide timers for.
-                * Only the first #autoHideLimit notifications being displayed will
-                * auto-hide. Any notifications further down in the list will only start
-                * counting down to auto-hide after the first few messages have closed.
+                * Maximum number of simultaneous notifications to start auto-hide timers for.
+                * Only this number of notifications being displayed will be auto-hidden at one time.
+                * Any additional notifications in the list will only start counting their timeout for
+                * auto-hiding after the previous messages have been closed.
                 *
-                * This basically represents the number of notifications the user should
-                * be able to process in #autoHideSeconds time.
+                * This basically represents the minimal number of notifications the user should
+                * be able to process during the {@link #defaults default} #autoHideSeconds time.
                 */
                autoHideLimit: 3
        };