From a58e79923d90941265a98712d6ab382adff48bca Mon Sep 17 00:00:00 2001 From: Chris Malley Date: Sat, 19 Jan 2019 21:06:32 -0700 Subject: [PATCH] convert ComboBox and its subtypes to class, https://github.com/phetsims/sun/issues/456 --- .../view/RealMoleculesComboBox.js | 96 ++++++++++--------- 1 file changed, 51 insertions(+), 45 deletions(-) diff --git a/js/realmolecules/view/RealMoleculesComboBox.js b/js/realmolecules/view/RealMoleculesComboBox.js index 0ff1221c..9db57837 100644 --- a/js/realmolecules/view/RealMoleculesComboBox.js +++ b/js/realmolecules/view/RealMoleculesComboBox.js @@ -1,4 +1,4 @@ -// Copyright 2014-2017, University of Colorado Boulder +// Copyright 2014-2019, University of Colorado Boulder /** * Combo box for choosing a real molecule. @@ -9,62 +9,68 @@ define( function( require ) { 'use strict'; // modules - var ComboBox = require( 'SUN/ComboBox' ); - var ComboBoxItem = require( 'SUN/ComboBoxItem' ); - var inherit = require( 'PHET_CORE/inherit' ); - var moleculePolarity = require( 'MOLECULE_POLARITY/moleculePolarity' ); - var PhetFont = require( 'SCENERY_PHET/PhetFont' ); - var RichText = require( 'SCENERY/nodes/RichText' ); - var StringUtils = require( 'PHETCOMMON/util/StringUtils' ); - var Text = require( 'SCENERY/nodes/Text' ); + const ComboBox = require( 'SUN/ComboBox' ); + const ComboBoxItem = require( 'SUN/ComboBoxItem' ); + const moleculePolarity = require( 'MOLECULE_POLARITY/moleculePolarity' ); + const PhetFont = require( 'SCENERY_PHET/PhetFont' ); + const RichText = require( 'SCENERY/nodes/RichText' ); + const StringUtils = require( 'PHETCOMMON/util/StringUtils' ); + const Text = require( 'SCENERY/nodes/Text' ); // strings - var moleculeString = require( 'string!MOLECULE_POLARITY/molecule' ); - var patternSymbolNameString = require( 'string!MOLECULE_POLARITY/pattern.symbolName' ); + const moleculeString = require( 'string!MOLECULE_POLARITY/molecule' ); + const patternSymbolNameString = require( 'string!MOLECULE_POLARITY/pattern.symbolName' ); - /** - * @param {RealMolecule[]} molecules - * @param {Property.} moleculeProperty - * @param {Node} listParent - * @constructor - */ - function RealMoleculesComboBox( molecules, moleculeProperty, listParent ) { + class RealMoleculesComboBox extends ComboBox { - // label - var labelNode = new Text( moleculeString, { - font: new PhetFont( 22 ), - maxWidth: 150 - } ); + /** + * @param {RealMolecule[]} molecules + * @param {Property.} moleculeProperty + * @param {Node} listParent + * @constructor + */ + constructor( molecules, moleculeProperty, listParent ) { - // items - var items = []; - for ( var i = 0; i < molecules.length; i++ ) { + // label + const labelNode = new Text( moleculeString, { + font: new PhetFont( 22 ), + maxWidth: 150 + } ); - var molecule = molecules[ i ]; + // {ComboBoxItem[]} + const items = molecules.map( createItem ); - var text = StringUtils.fillIn( patternSymbolNameString, { - symbol: molecule.symbol, - name: molecule.name + super( items, moleculeProperty, listParent, { + labelNode: labelNode, + listPosition: 'above', + highlightFill: 'rgb(218,255,255)', + cornerRadius: 8, + maxWidth: 450 } ); + } + } - var node = new RichText( text, { - maxWidth: 200, - font: new PhetFont( 18 ) - } ); + moleculePolarity.register( 'RealMoleculesComboBox', RealMoleculesComboBox ); - items[ i ] = new ComboBoxItem( node, molecule ); - } + /** + * Creates an item for the combo box. + * @param {RealMolecule} molecule + * @returns {ComboBoxItem} + */ + function createItem( molecule ) { - ComboBox.call( this, items, moleculeProperty, listParent, { - labelNode: labelNode, - listPosition: 'above', - highlightFill: 'rgb(218,255,255)', - cornerRadius: 8, - maxWidth: 450 + const text = StringUtils.fillIn( patternSymbolNameString, { + symbol: molecule.symbol, + name: molecule.name } ); - } - moleculePolarity.register( 'RealMoleculesComboBox', RealMoleculesComboBox ); + const node = new RichText( text, { + maxWidth: 200, + font: new PhetFont( 18 ) + } ); + + return new ComboBoxItem( node, molecule ); + } - return inherit( ComboBox, RealMoleculesComboBox ); + return RealMoleculesComboBox; } );