Debian Codegraph @

extensions/VisualEditor/lib/ve/src/ui/widgets/ve.ui.LanguageResultWidget.js

raw symbols SCIP
1 /*!
2 * VisualEditor UserInterface LanguageResultWidget class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * Creates an ve.ui.LanguageResultWidget object.
9 *
10 * @class
11 * @extends OO.ui.OptionWidget
12 *
13 * @constructor
14 * @param {Object} [config] Configuration options
15 */
16 ve.ui.LanguageResultWidget = function VeUiLanguageResultWidget( config ) {
17 // Parent constructor
18 ve.ui.LanguageResultWidget.super.call( this, config );
19
20 // Initialization
21 this.$element.addClass( 've-ui-languageResultWidget' );
22 this.name = new OO.ui.LabelWidget( { classes: [ 've-ui-languageResultWidget-name' ] } );
23 this.otherMatch = new OO.ui.LabelWidget( { classes: [ 've-ui-languageResultWidget-otherMatch' ] } );
24 this.setLabel( this.otherMatch.$element.add( this.name.$element ) );
25 };
26
27 /* Inheritance */
28
29 OO.inheritClass( ve.ui.LanguageResultWidget, OO.ui.OptionWidget );
30
31 /* Methods */
32
33 /**
34 * Update labels based on query
35 *
36 * @param {string} query Query text which matched this result
37 * @param {string} matchedProperty Data property which matched the query text
38 * @param {Function} [compare] String comparator
39 * @return {ve.ui.LanguageResultWidget}
40 * @chainable
41 */
42 ve.ui.LanguageResultWidget.prototype.updateLabel = function ( query, matchedProperty, compare ) {
43 const data = this.getData();
44
45 if ( matchedProperty === 'name' ) {
46 this.name.setHighlightedQuery( data.name, query, compare );
47 } else {
48 this.name.setLabel( data.name );
49 }
50 if ( matchedProperty === 'code' || matchedProperty === 'autonym' ) {
51 this.otherMatch.setHighlightedQuery( data[ matchedProperty ], query, compare );
52 } else {
53 this.otherMatch.setLabel( data.code );
54 }
55
56 return this;
57 };