diff --git a/view/resources/jquery/wikibase/jquery.wikibase.entitytermsforlanguagelistview.js b/view/resources/jquery/wikibase/jquery.wikibase.entitytermsforlanguagelistview.js index 0ad6c953ae8..25da36d6e22 100644 --- a/view/resources/jquery/wikibase/jquery.wikibase.entitytermsforlanguagelistview.js +++ b/view/resources/jquery/wikibase/jquery.wikibase.entitytermsforlanguagelistview.js @@ -72,6 +72,11 @@ */ _moreLanguagesItems: {}, + /** + * @type {string[]} List of languages shown per default. + */ + _defaultLanguages: [], + /** * @see jQuery.ui.TemplatedWidget._create */ @@ -83,6 +88,13 @@ } PARENT.prototype._create.call( this ); + this._defaultLanguages = this.options.userLanguages; + + var furtherLanguages = this._getMoreLanguages(); + if ( 'mul' in furtherLanguages ) { + // We have a mul term, always show it per default (but in the last position) + this._defaultLanguages.push( 'mul' ); + } this._verifyExistingDom(); this._createListView(); @@ -123,19 +135,23 @@ // Scrape languages from static HTML: var mismatchAt = null, - userLanguages = this.options.userLanguages; + languages = this._defaultLanguages; $entitytermsforlanguageview.each( function ( i ) { var match = $( this ) .attr( 'class' ) .match( /(?:^|\s)wikibase-entitytermsforlanguageview-(\S+)/ ); - if ( match && match[ 1 ] !== userLanguages[ i ] ) { + if ( match && match[ 1 ] !== languages[ i ] ) { + if ( match[ 1 ] !== 'mul' ) { + // "mul" might be included in the existing term box, but we want it to be after + // everything else, thus discarding it is expected. + mw.log.warn( 'Existing entitytermsforlanguagelistview DOM does not match configured languages' ); + } mismatchAt = i; return false; } } ); if ( mismatchAt !== null ) { - mw.log.warn( 'Existing entitytermsforlanguagelistview DOM does not match configured languages' ); $entitytermsforlanguageview.slice( mismatchAt ).remove(); } }, @@ -183,7 +199,7 @@ }; } } ), - value: this.options.userLanguages.map( function ( lang ) { + value: this._defaultLanguages.map( function ( lang ) { return self._getValueForLanguage( lang ); } ), listItemNodeName: 'TR' @@ -222,7 +238,7 @@ */ _hasMoreLanguages: function () { var fingerprint = this.options.value, - minLength = this.options.userLanguages.length; + minLength = this._defaultLanguages.length; if ( fingerprint.getLabels().length > minLength || fingerprint.getDescriptions().length > minLength @@ -340,7 +356,7 @@ languages[ lang ] = lang; } ); - this.options.userLanguages.forEach( function ( lang ) { + this._defaultLanguages.forEach( function ( lang ) { delete languages[ lang ]; } ); diff --git a/view/tests/qunit/jquery/wikibase/jquery.wikibase.entitytermsforlanguagelistview.tests.js b/view/tests/qunit/jquery/wikibase/jquery.wikibase.entitytermsforlanguagelistview.tests.js index bb6e406b5ca..a34c07eb6ae 100644 --- a/view/tests/qunit/jquery/wikibase/jquery.wikibase.entitytermsforlanguagelistview.tests.js +++ b/view/tests/qunit/jquery/wikibase/jquery.wikibase.entitytermsforlanguagelistview.tests.js @@ -83,6 +83,11 @@ undefined, 'Created widget.' ); + assert.deepEqual( + entitytermsforlanguagelistview._defaultLanguages, + [ 'de', 'en' ], + 'Default languages without "mul".' + ); entitytermsforlanguagelistview.destroy(); @@ -158,4 +163,19 @@ assert.strictEqual( !entitytermsforlanguagelistview._hasMoreLanguages(), true ); } ); + QUnit.test( 'mul handling', function ( assert ) { + var fingerprint = createFingerprint(); + fingerprint.setLabel( 'mul', new datamodel.Term( 'mul', 'mul-label' ) ); + + var $entitytermsforlanguagelistview = createEntitytermsforlanguagelistview( { value: fingerprint } ), + entitytermsforlanguagelistview + = $entitytermsforlanguagelistview.data( 'entitytermsforlanguagelistview' ); + + assert.deepEqual( + entitytermsforlanguagelistview._defaultLanguages, + [ 'de', 'en', 'mul' ], + 'Default languages if a "mul" term is present.' + ); + } ); + }() );