4 * var convertmessagebox = require( 'mediawiki.notification.convertmessagebox' );
6 * @class mw.plugin.convertmessagebox
13 * Convert a messagebox to a notification.
15 * Checks if a message box with class `.mw-notify-success`, `.mw-notify-warning`, or `.mw-notify-error`
16 * exists and converts it into a mw.Notification with the text of the element or a given message key.
18 * By default the notification will automatically hide after 5s, or when the user clicks the element.
19 * This can be overridden by setting attribute `data-mw-autohide="true"`.
21 * @param {Object} [options] Options
22 * @param {mw.Message} [options.msg] Message key (must be loaded already)
24 function convertmessagebox( options ) {
25 var $msgBox, type, autoHide, msg, notif,
26 $successBox = $( '.mw-notify-success' ),
27 $warningBox = $( '.mw-notify-warning' ),
28 $errorBox = $( '.mw-notify-error' );
30 // If there is a message box and javascript is enabled, use a slick notification instead!
31 if ( $successBox.length ) {
32 $msgBox = $successBox;
34 } else if ( $warningBox.length ) {
35 $msgBox = $warningBox;
37 } else if ( $errorBox.length ) {
44 autoHide = $msgBox.attr( 'data-mw-autohide' ) === 'true';
46 // If the msg param is given, use it, otherwise use the text of the successbox
47 msg = options && options.msg || $msgBox.text();
50 notif = mw.notification.notify( msg, { autoHide: autoHide, type: type } );
52 // 'change' event not reliable!
53 $( document ).one( 'keydown mousedown', function () {
62 module.exports = convertmessagebox;
64 }( mediaWiki, jQuery ) );