Cleanups and optimizations related to .parseDom()

E.g. avoid calling the rather expensive method multiple times
in a row, if only 1 of the results is needed.

Change-Id: Iff1d2c0892367e927303f6f45d3231e04c045cab
This commit is contained in:
Thiemo Kreuz 2021-08-31 15:58:44 +02:00 committed by Thiemo Kreuz (WMDE)
parent fa0792e002
commit 36bd65dda7
3 changed files with 21 additions and 21 deletions

View file

@ -148,7 +148,7 @@
// The following messages are used here:
// * minoredit
// * watchthis
var $label = $( '<span>' ).append( mw.message( options[ 'label-message' ] ).parseDom() );
var $label = mw.message( options[ 'label-message' ] ).parseDom();
var config = $.extend( {
accessKey: accesskey,
@ -178,7 +178,7 @@
checkboxFields.push(
new OO.ui.FieldLayout( checkbox, {
align: 'inline',
label: $label.contents(),
label: $label,
title: title,
invisibleLabel: !!options.invisibleLabel,
// * ve-ui-mwSaveDialog-field-wpMinoredit

View file

@ -46,23 +46,25 @@ ve.ui.MWIncludesContextItem.static.modelClasses = [
/* Methods */
ve.ui.MWIncludesContextItem.prototype.getLabelMessage = function () {
var map = {
'mw:Includes/NoInclude': mw.message( 'visualeditor-includes-noinclude-start' ).text(),
'mw:Includes/NoInclude/End': mw.message( 'visualeditor-includes-noinclude-end' ).text(),
'mw:Includes/OnlyInclude': mw.message( 'visualeditor-includes-onlyinclude-start' ).text(),
'mw:Includes/OnlyInclude/End': mw.message( 'visualeditor-includes-onlyinclude-end' ).text(),
'mw:Includes/IncludeOnly': mw.message( 'visualeditor-includes-includeonly' ).text()
};
return map[ this.model.getAttribute( 'type' ) ];
var key = {
'mw:Includes/NoInclude': 'visualeditor-includes-noinclude-start',
'mw:Includes/NoInclude/End': 'visualeditor-includes-noinclude-end',
'mw:Includes/OnlyInclude': 'visualeditor-includes-onlyinclude-start',
'mw:Includes/OnlyInclude/End': 'visualeditor-includes-onlyinclude-end',
'mw:Includes/IncludeOnly': 'visualeditor-includes-includeonly'
}[ this.model.getAttribute( 'type' ) ];
// eslint-disable-next-line mediawiki/msg-doc
return key ? mw.message( key ).text() : '';
};
ve.ui.MWIncludesContextItem.prototype.getDescriptionMessage = function () {
var map = {
'mw:Includes/NoInclude': mw.message( 'visualeditor-includes-noinclude-description' ).parseDom(),
'mw:Includes/OnlyInclude': mw.message( 'visualeditor-includes-onlyinclude-description' ).parseDom(),
'mw:Includes/IncludeOnly': mw.message( 'visualeditor-includes-includeonly-description' ).parseDom()
};
return map[ this.model.getAttribute( 'type' ) ] || '';
var key = {
'mw:Includes/NoInclude': 'visualeditor-includes-noinclude-description',
'mw:Includes/OnlyInclude': 'visualeditor-includes-onlyinclude-description',
'mw:Includes/IncludeOnly': 'visualeditor-includes-includeonly-description'
}[ this.model.getAttribute( 'type' ) ];
// eslint-disable-next-line mediawiki/msg-doc
return key ? mw.message( key ).parseDom() : '';
};
/**

View file

@ -14,13 +14,13 @@
* @cfg {mw.Message} message Message to display
*/
ve.ui.MWDismissibleMessageWidget = function VeUiMWDismissibleMessageWidget( config ) {
var $label = config.message.parseDom();
// eslint-disable-next-line no-jquery/variable-pattern
config.label = $label;
config.label = config.message.parseDom();
// Parent constructor
ve.ui.MWDismissibleMessageWidget.super.call( this, config );
ve.targetLinksToNewWindow( this.$label[ 0 ] );
// Properties
this.messageKey = config.message.key;
delete config.message;
@ -32,8 +32,6 @@ ve.ui.MWDismissibleMessageWidget = function VeUiMWDismissibleMessageWidget( conf
} )
.connect( this, { click: 'onDismissClick' } );
ve.targetLinksToNewWindow( this.$element[ 0 ] );
this.$element
.addClass( 've-ui-dismissibleMessageWidget' )
.prepend( dismissButton.$element );