mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateData
synced 2024-12-03 11:56:16 +00:00
Simplify .length and "is empty" checks in JavaScript
I actually find this easier to read, to be honest. It also makes the code a little more robust, e.g. undefined and the empty string are both considered empty. Note that unlike in PHP the string "0" is not empty in JavaScript. Change-Id: I2961287c2798b8bb0f6992e002f5a6f333889448
This commit is contained in:
parent
69b6c08a94
commit
bd08464c45
|
@ -907,7 +907,7 @@ Model.prototype.outputTemplateData = function () {
|
|||
}
|
||||
|
||||
// Template maps
|
||||
if ( this.maps === undefined || Object.keys( this.maps ).length === 0 ) {
|
||||
if ( !this.maps || !Object.keys( this.maps ).length ) {
|
||||
delete result.maps;
|
||||
} else {
|
||||
result.maps = this.maps;
|
||||
|
@ -921,7 +921,7 @@ Model.prototype.outputTemplateData = function () {
|
|||
}
|
||||
|
||||
// Format
|
||||
if ( this.format === null ) {
|
||||
if ( !this.format ) {
|
||||
delete result.format;
|
||||
} else {
|
||||
result.format = this.format;
|
||||
|
|
|
@ -531,7 +531,7 @@ Dialog.prototype.onMapInfoChange = function ( value ) {
|
|||
// Otherwise disable the done button if maps object is populated
|
||||
this.actions.setAbilities( { done: false } );
|
||||
} finally {
|
||||
if ( this.mapsGroup.items.length === 0 ) {
|
||||
if ( !this.mapsGroup.items.length ) {
|
||||
this.actions.setAbilities( { done: true } );
|
||||
this.removeMapButton.setDisabled( true );
|
||||
}
|
||||
|
@ -1313,7 +1313,7 @@ Dialog.prototype.importParametersFromTemplateCode = function () {
|
|||
|
||||
let $message = $( [] ),
|
||||
state = 'success';
|
||||
if ( response.imported.length === 0 ) {
|
||||
if ( !response.imported.length ) {
|
||||
$message = $( '<p>' ).text( mw.msg( 'templatedata-modal-errormsg-import-noparams' ) );
|
||||
state = 'error';
|
||||
} else {
|
||||
|
|
|
@ -101,7 +101,7 @@ LanguageSearchWidget.prototype.addResults = function () {
|
|||
return false;
|
||||
} );
|
||||
|
||||
if ( query === '' || matchedProperty ) {
|
||||
if ( !query || matchedProperty ) {
|
||||
items.push(
|
||||
languageResult
|
||||
.updateLabel( query, matchedProperty, compare )
|
||||
|
|
Loading…
Reference in a new issue