2021-06-10 16:27:01 +00:00
|
|
|
/**
|
|
|
|
* Creates a ve.ui.MWDismissibleMessageWidget object.
|
|
|
|
*
|
|
|
|
* This widget allows a user to permanently dismiss a message widget
|
|
|
|
* {@see OO.ui.MessageWidget}. When the widget is dismissed, a flag
|
|
|
|
* is set in the local storage. This flag will then be used to prevent
|
|
|
|
* the widget from being shown on subsequent views.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends OO.ui.MessageWidget
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} config Configuration options
|
|
|
|
* @cfg {mw.Message} message Message to display
|
|
|
|
*/
|
|
|
|
ve.ui.MWDismissibleMessageWidget = function VeUiMWDismissibleMessageWidget( config ) {
|
2021-06-16 08:31:34 +00:00
|
|
|
var $label = config.message.parseDom();
|
|
|
|
$label.filter( 'a' ).attr( 'target', '_blank' );
|
|
|
|
// eslint-disable-next-line no-jquery/variable-pattern
|
|
|
|
config.label = $label;
|
|
|
|
|
2021-06-10 16:27:01 +00:00
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWDismissibleMessageWidget.super.call( this, config );
|
|
|
|
|
|
|
|
// Properties
|
2021-06-16 08:31:34 +00:00
|
|
|
this.messageKey = config.message.key;
|
|
|
|
delete config.message;
|
|
|
|
|
|
|
|
var dismissButton = new OO.ui.ButtonWidget( {
|
2021-06-10 16:27:01 +00:00
|
|
|
icon: 'close',
|
|
|
|
framed: false
|
2021-06-16 08:31:34 +00:00
|
|
|
} )
|
2021-06-10 16:27:01 +00:00
|
|
|
.connect( this, { click: 'onDismissClick' } );
|
2021-06-16 08:31:34 +00:00
|
|
|
|
2021-06-10 16:27:01 +00:00
|
|
|
this.$element
|
|
|
|
.addClass( 've-ui-dismissibleMessageWidget' )
|
2021-06-16 08:31:34 +00:00
|
|
|
.prepend( dismissButton.$element );
|
2021-06-10 16:27:01 +00:00
|
|
|
|
|
|
|
var hidden = !!mw.storage.get( this.getStorageKey() );
|
|
|
|
this.toggle( !hidden );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWDismissibleMessageWidget, OO.ui.MessageWidget );
|
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWDismissibleMessageWidget.static.storageKeyPrefix = 'mwe-visualeditor-hide-';
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates a local storage key using both a shared prefix and
|
|
|
|
* the message's key {@see mw.Message}.
|
|
|
|
*
|
|
|
|
* @return {string} The local storage key
|
|
|
|
*/
|
|
|
|
ve.ui.MWDismissibleMessageWidget.prototype.getStorageKey = function () {
|
2021-06-16 08:31:34 +00:00
|
|
|
return this.constructor.static.storageKeyPrefix + this.messageKey;
|
2021-06-10 16:27:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Respond to dismiss button click event.
|
2021-06-16 08:31:34 +00:00
|
|
|
* @fires close
|
2021-06-10 16:27:01 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWDismissibleMessageWidget.prototype.onDismissClick = function () {
|
|
|
|
mw.storage.set( this.getStorageKey(), '1' );
|
|
|
|
this.toggle( false );
|
2021-06-16 08:31:34 +00:00
|
|
|
this.emit( 'close' );
|
2021-06-10 16:27:01 +00:00
|
|
|
};
|