2018-11-12 13:56:38 +00:00
|
|
|
( function () {
|
2016-08-23 20:57:04 +00:00
|
|
|
/**
|
|
|
|
* Confirmation overlay widget, especially for mobile display.
|
|
|
|
* The behavior of this widget is to appear with a given confirmation
|
2018-01-31 23:59:23 +00:00
|
|
|
* message and then disappear after a given interval.
|
2016-08-23 20:57:04 +00:00
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends OO.ui.Widget
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration object
|
|
|
|
* @cfg {number} [interval=2000] The number of milliseconds that it takes
|
|
|
|
* for the popup to disappear after appearing.
|
|
|
|
*/
|
|
|
|
mw.echo.ui.ConfirmationPopupWidget = function MwEchoUiConfirmationPopupWidget( config ) {
|
|
|
|
config = config || {};
|
|
|
|
|
|
|
|
// Parent constructor
|
2018-05-22 14:56:46 +00:00
|
|
|
mw.echo.ui.ConfirmationPopupWidget.super.call( this, config );
|
2016-08-23 20:57:04 +00:00
|
|
|
|
2018-01-31 23:59:23 +00:00
|
|
|
this.labelWidget = new OO.ui.LabelWidget( config );
|
2018-03-22 21:21:06 +00:00
|
|
|
this.iconWidget = new OO.ui.IconWidget( $.extend( { icon: 'checkAll' }, config ) );
|
2016-08-23 20:57:04 +00:00
|
|
|
this.interval = config.interval || 2000;
|
|
|
|
|
|
|
|
this.$element
|
|
|
|
.addClass( 'mw-echo-ui-confirmationPopupWidget' )
|
|
|
|
.append(
|
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 'mw-echo-ui-confirmationPopupWidget-popup' )
|
2018-01-31 23:59:23 +00:00
|
|
|
.append( this.iconWidget.$element, this.labelWidget.$element )
|
2016-08-23 20:57:04 +00:00
|
|
|
)
|
|
|
|
// We're using explicit hide here because the widget uses
|
|
|
|
// animated fadeOut
|
|
|
|
.hide();
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Initialization */
|
|
|
|
|
|
|
|
OO.inheritClass( mw.echo.ui.ConfirmationPopupWidget, OO.ui.Widget );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the widget and then animate its fade out.
|
|
|
|
*/
|
|
|
|
mw.echo.ui.ConfirmationPopupWidget.prototype.showAnimated = function () {
|
|
|
|
// OOUI removes the oo-ui-image-invert class when it is initialized
|
|
|
|
// without explicit flag classes, so we have to re-add this when we
|
|
|
|
// display the icon for the icon to be inverted
|
2018-01-31 23:59:23 +00:00
|
|
|
this.iconWidget.$element.addClass( 'oo-ui-image-invert' );
|
2016-08-23 20:57:04 +00:00
|
|
|
this.$element.show();
|
|
|
|
setTimeout( this.hide.bind( this ), this.interval );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide the widget by fading it out
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
mw.echo.ui.ConfirmationPopupWidget.prototype.hide = function () {
|
2019-02-06 01:42:53 +00:00
|
|
|
// FIXME: Use CSS transition
|
2019-04-03 22:57:13 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-fade
|
2016-08-23 20:57:04 +00:00
|
|
|
this.$element.fadeOut();
|
|
|
|
};
|
2018-01-31 23:59:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Delegate to labelWidget.setLabel()
|
|
|
|
*
|
|
|
|
* @param {jQuery|string|OO.ui.HtmlSnippet|Function|null} label Label nodes; text; a function that returns nodes or
|
|
|
|
* text; or null for no label
|
|
|
|
*/
|
|
|
|
mw.echo.ui.ConfirmationPopupWidget.prototype.setLabel = function ( label ) {
|
|
|
|
this.labelWidget.setLabel( label );
|
|
|
|
};
|
2018-11-12 13:56:38 +00:00
|
|
|
}() );
|