mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 18:39:52 +00:00
Small code cleanups for the MWDismissibleMessageWidget
* Re-focus the input field after closing the message. * Store only the message key. That's all that's needed. * Avoid a class property that's not needed. * Use the config object instead of calling .setLabel() manually. Bug: T284742 Change-Id: If8e8bb6460fa5aea8ddd46c2e27b5f08b7772896
This commit is contained in:
parent
13d1c4d2ac
commit
feb902aba0
|
@ -91,7 +91,8 @@ ve.ui.MWTemplatePlaceholderPage = function VeUiMWTemplatePlaceholderPage( placeh
|
|||
// TODO: remove when templateSearchImprovements are out of beta
|
||||
var feedbackMessage = new ve.ui.MWDismissibleMessageWidget( {
|
||||
message: mw.message( 'visualeditor-dialog-transclusion-feedback-message' )
|
||||
} );
|
||||
} )
|
||||
.connect( this, { close: 'focus' } );
|
||||
|
||||
addTemplateFieldsetConfig = ve.extendObject( addTemplateFieldsetConfig, {
|
||||
// The following messages are used here:
|
||||
|
|
|
@ -14,26 +14,27 @@
|
|||
* @cfg {mw.Message} message Message to display
|
||||
*/
|
||||
ve.ui.MWDismissibleMessageWidget = function VeUiMWDismissibleMessageWidget( config ) {
|
||||
var $label = config.message.parseDom();
|
||||
$label.filter( 'a' ).attr( 'target', '_blank' );
|
||||
// eslint-disable-next-line no-jquery/variable-pattern
|
||||
config.label = $label;
|
||||
|
||||
// Parent constructor
|
||||
ve.ui.MWDismissibleMessageWidget.super.call( this, config );
|
||||
|
||||
// Properties
|
||||
this.message = config.message;
|
||||
this.dismissButton = new OO.ui.ButtonWidget( {
|
||||
this.messageKey = config.message.key;
|
||||
delete config.message;
|
||||
|
||||
var dismissButton = new OO.ui.ButtonWidget( {
|
||||
icon: 'close',
|
||||
framed: false
|
||||
} );
|
||||
|
||||
// Initialization
|
||||
this.dismissButton
|
||||
} )
|
||||
.connect( this, { click: 'onDismissClick' } );
|
||||
|
||||
this.$element
|
||||
.addClass( 've-ui-dismissibleMessageWidget' )
|
||||
.prepend( this.dismissButton.$element );
|
||||
|
||||
var $message = this.message.parseDom();
|
||||
$message.filter( 'a' ).attr( 'target', '_blank' );
|
||||
this.setLabel( $message );
|
||||
.prepend( dismissButton.$element );
|
||||
|
||||
var hidden = !!mw.storage.get( this.getStorageKey() );
|
||||
this.toggle( !hidden );
|
||||
|
@ -56,13 +57,15 @@ ve.ui.MWDismissibleMessageWidget.static.storageKeyPrefix = 'mwe-visualeditor-hid
|
|||
* @return {string} The local storage key
|
||||
*/
|
||||
ve.ui.MWDismissibleMessageWidget.prototype.getStorageKey = function () {
|
||||
return this.constructor.static.storageKeyPrefix + this.message.key;
|
||||
return this.constructor.static.storageKeyPrefix + this.messageKey;
|
||||
};
|
||||
|
||||
/**
|
||||
* Respond to dismiss button click event.
|
||||
* @fires close
|
||||
*/
|
||||
ve.ui.MWDismissibleMessageWidget.prototype.onDismissClick = function () {
|
||||
mw.storage.set( this.getStorageKey(), '1' );
|
||||
this.toggle( false );
|
||||
this.emit( 'close' );
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue