Debian Codegraph @

extensions/Echo/modules/ui/mw.echo.ui.ConfirmationPopupWidget.js

raw symbols SCIP
1 ( function () {
2 /**
3 * Confirmation overlay widget, especially for mobile display.
4 * The behavior of this widget is to appear with a given confirmation
5 * message and then disappear after a given interval.
6 *
7 * @class
8 * @extends OO.ui.Widget
9 *
10 * @constructor
11 * @param {Object} [config] Configuration object
12 * @param {number} [config.interval=2000] The number of milliseconds that it takes
13 * for the popup to disappear after appearing.
14 */
15 mw.echo.ui.ConfirmationPopupWidget = function MwEchoUiConfirmationPopupWidget( config ) {
16 config = config || {};
17
18 // Parent constructor
19 mw.echo.ui.ConfirmationPopupWidget.super.call( this, config );
20
21 this.labelWidget = new OO.ui.LabelWidget( config );
22 this.iconWidget = new OO.ui.IconWidget( Object.assign( { icon: 'checkAll' }, config ) );
23 this.interval = config.interval || 2000;
24
25 this.$element
26 .addClass( 'mw-echo-ui-confirmationPopupWidget' )
27 .append(
28 $( '<div>' )
29 .addClass( 'mw-echo-ui-confirmationPopupWidget-popup' )
30 .append( this.iconWidget.$element, this.labelWidget.$element )
31 )
32 // We're using explicit hide here because the widget uses
33 // animated fadeOut
34 .hide();
35 };
36
37 /* Initialization */
38
39 OO.inheritClass( mw.echo.ui.ConfirmationPopupWidget, OO.ui.Widget );
40
41 /**
42 * Show the widget and then animate its fade out.
43 */
44 mw.echo.ui.ConfirmationPopupWidget.prototype.showAnimated = function () {
45 // OOUI removes the oo-ui-image-invert class when it is initialized
46 // without explicit flag classes, so we have to re-add this when we
47 // display the icon for the icon to be inverted
48 this.iconWidget.$element.addClass( 'oo-ui-image-invert' );
49 this.$element.show();
50 setTimeout( this.hide.bind( this ), this.interval );
51 };
52
53 /**
54 * Hide the widget by fading it out
55 *
56 * @private
57 */
58 mw.echo.ui.ConfirmationPopupWidget.prototype.hide = function () {
59 // FIXME: Use CSS transition
60 // eslint-disable-next-line no-jquery/no-fade
61 this.$element.fadeOut();
62 };
63
64 /**
65 * Delegate to labelWidget.setLabel()
66 *
67 * @param {jQuery|string|OO.ui.HtmlSnippet|Function|null} label Label nodes; text; a function that returns nodes or
68 * text; or null for no label
69 */
70 mw.echo.ui.ConfirmationPopupWidget.prototype.setLabel = function ( label ) {
71 this.labelWidget.setLabel( label );
72 };
73 }() );