| 1 |
|
| 2 |
|
| 3 |
const activeNotification = {}; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
function add( container, message, id, classes = [], timeout = 4000, onDismiss = () => {} ) { |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
let popupWidget; |
| 21 |
|
| 22 |
|
| 23 |
return mw.loader.using( 'oojs-ui-core' ).then( () => { |
| 24 |
|
| 25 |
if ( id && activeNotification[ id ] ) { |
| 26 |
return activeNotification[ id ]; |
| 27 |
} |
| 28 |
const content = document.createElement( 'p' ); |
| 29 |
content.textContent = message; |
| 30 |
popupWidget = new OO.ui.PopupWidget( { |
| 31 |
|
| 32 |
$content: $( content ), |
| 33 |
padded: true, |
| 34 |
autoClose: timeout !== false, |
| 35 |
head: timeout === false, |
| 36 |
anchor: true, |
| 37 |
align: 'center', |
| 38 |
position: 'below', |
| 39 |
classes: [ 'vector-popup-notification' ].concat( classes ), |
| 40 |
container |
| 41 |
} ); |
| 42 |
|
| 43 |
popupWidget.$element.appendTo( container ); |
| 44 |
popupWidget.on( 'closing', () => { |
| 45 |
onDismiss(); |
| 46 |
} ); |
| 47 |
if ( popupWidget && id ) { |
| 48 |
activeNotification[ id ] = popupWidget; |
| 49 |
} |
| 50 |
return popupWidget; |
| 51 |
} ); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
function hide( popupWidget ) { |
| 60 |
popupWidget.toggle( false ); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
function show( popupWidget, timeout = 4000 ) { |
| 70 |
popupWidget.toggle( true ); |
| 71 |
popupWidget.toggleClipping( true ); |
| 72 |
|
| 73 |
if ( timeout === false ) { |
| 74 |
return; |
| 75 |
} |
| 76 |
setTimeout( () => { |
| 77 |
hide( popupWidget ); |
| 78 |
}, timeout ); |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
function hideAll() { |
| 86 |
for ( const key in activeNotification ) { |
| 87 |
const popupWidget = activeNotification[ key ]; |
| 88 |
hide( popupWidget ); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
module.exports = { |
| 93 |
add, |
| 94 |
hide, |
| 95 |
hideAll, |
| 96 |
show |
| 97 |
}; |