2 * Exposes a method for converting a messagebox to a notification.
4 * @module mediawiki.notification.convertmessagebox
8 * Convert a messagebox to a notification.
11 * const convertmessagebox = require( 'mediawiki.notification.convertmessagebox' );
13 * @method (require("mediawiki.notification.convertmessagebox"))
14 * @param {Object} [options] Options
15 * @param {mw.Message} [options.msg] Message key (must be loaded already)
17 module.exports = function ( options ) {
18 const $successBox = $( '.mw-notify-success' ),
19 $warningBox = $( '.mw-notify-warning' ),
20 $errorBox = $( '.mw-notify-error' );
22 // If there is a message box and javascript is enabled, use a slick notification instead!
24 if ( $successBox.length ) {
25 $msgBox = $successBox;
27 } else if ( $warningBox.length ) {
28 $msgBox = $warningBox;
30 } else if ( $errorBox.length ) {
37 const autoHide = $msgBox.attr( 'data-mw-autohide' ) === 'true';
39 // If the msg param is given, use it, otherwise use the text of the successbox
40 const msg = options && options.msg || $msgBox.text();
43 let notif = mw.notification.notify( msg, { autoHide: autoHide, type: type } );
45 // 'change' event not reliable!
46 $( document ).one( 'keydown mousedown', () => {