mediawiki.notification: Expose close method to hide a Notification
authorAlex Monk <krenair@gmail.com>
Thu, 18 Jul 2013 18:06:16 +0000 (19:06 +0100)
committerBartosz Dziewoński <matma.rex@gmail.com>
Sat, 19 Oct 2013 12:56:23 +0000 (12:56 +0000)
Bug: 51338
Change-Id: Icd7fd1ac328094ddc2560d4804dd52fc85879867

resources/mediawiki/mediawiki.notification.js
resources/mediawiki/mediawiki.notify.js

index 70f639c..4ede809 100644 (file)
                 * @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
                 */
                notify: function ( message, options ) {
                        var notif;
                        } else {
                                preReadyNotifQueue.push( notif );
                        }
+                       return { close: $.proxy( notif.close, notif ) };
                },
 
                /**
index 83d95b6..743d651 100644 (file)
@@ -1,22 +1,23 @@
 /**
  * @class mw.plugin.notify
  */
-( function ( mw ) {
+( function ( mw, $ ) {
        'use strict';
 
        /**
         * @see mw.notification#notify
         * @param message
         * @param options
+        * @return {jQuery.Promise}
         */
        mw.notify = function ( message, options ) {
+               var d = $.Deferred();
                // Don't bother loading the whole notification system if we never use it.
                mw.loader.using( 'mediawiki.notification', function () {
-                       // Don't bother calling mw.loader.using a second time after we've already loaded mw.notification.
-                       mw.notify = mw.notification.notify;
                        // Call notify with the notification the user requested of us.
-                       mw.notify( message, options );
-               } );
+                       d.resolve( mw.notification.notify( message, options ) );
+               }, d.reject );
+               return d.promise();
        };
 
        /**
@@ -24,4 +25,4 @@
         * @mixins mw.plugin.notify
         */
 
-}( mediaWiki ) );
+}( mediaWiki, jQuery ) );