| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
module.exports = function ( options ) { |
| 18 |
const $successBox = $( '.mw-notify-success' ), |
| 19 |
$warningBox = $( '.mw-notify-warning' ), |
| 20 |
$errorBox = $( '.mw-notify-error' ); |
| 21 |
|
| 22 |
|
| 23 |
let $msgBox, type; |
| 24 |
if ( $successBox.length ) { |
| 25 |
$msgBox = $successBox; |
| 26 |
type = 'info'; |
| 27 |
} else if ( $warningBox.length ) { |
| 28 |
$msgBox = $warningBox; |
| 29 |
type = 'warn'; |
| 30 |
} else if ( $errorBox.length ) { |
| 31 |
$msgBox = $errorBox; |
| 32 |
type = 'error'; |
| 33 |
} else { |
| 34 |
return; |
| 35 |
} |
| 36 |
|
| 37 |
const autoHide = $msgBox.attr( 'data-mw-autohide' ) === 'true'; |
| 38 |
|
| 39 |
|
| 40 |
const msg = options && options.msg || $msgBox.text(); |
| 41 |
$msgBox.detach(); |
| 42 |
|
| 43 |
let notif = mw.notification.notify( msg, { autoHide: autoHide, type: type } ); |
| 44 |
if ( !autoHide ) { |
| 45 |
|
| 46 |
$( document ).one( 'keydown mousedown', () => { |
| 47 |
if ( notif ) { |
| 48 |
notif.close(); |
| 49 |
notif = null; |
| 50 |
} |
| 51 |
} ); |
| 52 |
} |
| 53 |
}; |