Skip to content

Commit 3cdf4fc

Browse files
committed
Converted to const, this, arrow, see #437
1 parent 8d4c4a6 commit 3cdf4fc

File tree

1 file changed

+50
-57
lines changed

1 file changed

+50
-57
lines changed

js/Dialog.js

+50-57
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
11
// Copyright 2018, University of Colorado Boulder
22

33
/**
4-
* General dialog type
5-
* Used to live at 'JOIST/Dialog'. Moved to 'SUN/Dialog' on 4/10/2018
4+
* General dialog type. Migrated from Joist on 4/10/2018
65
*
7-
* @author Jonathan Olson <[email protected]>
6+
* @author Jonathan Olson (PhET Interactive Simulations)
87
* @author Sam Reid (PhET Interactive Simulations)
9-
* @author Andrea Lin
8+
* @author Andrea Lin (PhET Interactive Simulations)
109
* @author Chris Malley (PixelZoom, Inc.)
1110
*/
12-
define( function( require ) {
11+
define( require => {
1312
'use strict';
1413

1514
// modules
16-
var AccessibilityUtil = require( 'SCENERY/accessibility/AccessibilityUtil' );
17-
var AccessiblePeer = require( 'SCENERY/accessibility/AccessiblePeer' );
18-
var AlignBox = require( 'SCENERY/nodes/AlignBox' );
19-
var DialogIO = require( 'SUN/DialogIO' );
20-
var Display = require( 'SCENERY/display/Display' );
21-
var FullScreen = require( 'SCENERY/util/FullScreen' );
22-
var HBox = require( 'SCENERY/nodes/HBox' );
23-
var inherit = require( 'PHET_CORE/inherit' );
24-
var KeyboardUtil = require( 'SCENERY/accessibility/KeyboardUtil' );
25-
var Panel = require( 'SUN/Panel' );
26-
var Path = require( 'SCENERY/nodes/Path' );
27-
var RectangularButtonView = require( 'SUN/buttons/RectangularButtonView' );
28-
var RectangularPushButton = require( 'SUN/buttons/RectangularPushButton' );
29-
var Shape = require( 'KITE/Shape' );
30-
var sun = require( 'SUN/sun' );
31-
var SunA11yStrings = require( 'SUN/SunA11yStrings' );
32-
var Tandem = require( 'TANDEM/Tandem' );
33-
var VBox = require( 'SCENERY/nodes/VBox' );
15+
const AccessibilityUtil = require( 'SCENERY/accessibility/AccessibilityUtil' );
16+
const AccessiblePeer = require( 'SCENERY/accessibility/AccessiblePeer' );
17+
const AlignBox = require( 'SCENERY/nodes/AlignBox' );
18+
const DialogIO = require( 'SUN/DialogIO' );
19+
const Display = require( 'SCENERY/display/Display' );
20+
const FullScreen = require( 'SCENERY/util/FullScreen' );
21+
const HBox = require( 'SCENERY/nodes/HBox' );
22+
const inherit = require( 'PHET_CORE/inherit' );
23+
const KeyboardUtil = require( 'SCENERY/accessibility/KeyboardUtil' );
24+
const Panel = require( 'SUN/Panel' );
25+
const Path = require( 'SCENERY/nodes/Path' );
26+
const RectangularButtonView = require( 'SUN/buttons/RectangularButtonView' );
27+
const RectangularPushButton = require( 'SUN/buttons/RectangularPushButton' );
28+
const Shape = require( 'KITE/Shape' );
29+
const sun = require( 'SUN/sun' );
30+
const SunA11yStrings = require( 'SUN/SunA11yStrings' );
31+
const Tandem = require( 'TANDEM/Tandem' );
32+
const VBox = require( 'SCENERY/nodes/VBox' );
3433

3534
// strings
36-
var closeString = SunA11yStrings.close.value;
35+
const closeString = SunA11yStrings.close.value;
3736

3837
// constants
39-
var CLOSE_BUTTON_WIDTH = 14;
38+
const CLOSE_BUTTON_WIDTH = 14;
4039

4140
/**
4241
* @param {Node} content - The content to display inside the dialog (not including the title)
@@ -45,8 +44,6 @@ define( function( require ) {
4544
*/
4645
function Dialog( content, options ) {
4746

48-
var self = this;
49-
5047
options = _.extend( {
5148

5249
/* Margins and spacing:
@@ -101,7 +98,7 @@ define( function( require ) {
10198
layoutStrategy: Dialog.DEFAULT_LAYOUT_STRATEGY,
10299

103100
// close button options
104-
closeButtonListener: function() { self.hide(); },
101+
closeButtonListener: () => this.hide(),
105102
closeButtonTouchAreaXDilation: 0,
106103
closeButtonTouchAreaYDilation: 0,
107104
closeButtonMouseAreaXDilation: 0,
@@ -154,15 +151,15 @@ define( function( require ) {
154151
this.isShowing = false;
155152

156153
// create close button
157-
var closeButton = new CloseButton( {
154+
const closeButton = new CloseButton( {
158155

159156
iconLength: CLOSE_BUTTON_WIDTH,
160-
listener: function() {
157+
listener: () => {
161158
options.closeButtonListener();
162159

163160
// if listener was fired because of accessibility
164161
if ( closeButton.buttonModel.isA11yClicking() ) {
165-
self.focusActiveElement();
162+
this.focusActiveElement();
166163
}
167164
},
168165

@@ -192,40 +189,39 @@ define( function( require ) {
192189
// Align content, title, and close button using spacing and margin options
193190

194191
// align content and title (if provided) vertically
195-
var contentAndTitle = new VBox( {
192+
const contentAndTitle = new VBox( {
196193
children: options.title ? [ options.title, content ] : [ content ],
197194
spacing: options.ySpacing,
198195
align: options.titleAlign
199196
} );
200197

201198
// add topMargin, bottomMargin, and leftMargin
202-
var contentAndTitleWithMargins = new AlignBox( contentAndTitle, {
199+
const contentAndTitleWithMargins = new AlignBox( contentAndTitle, {
203200
topMargin: options.topMargin,
204201
bottomMargin: options.bottomMargin,
205202
leftMargin: options.leftMargin
206203
} );
207204

208205
// add closeButtonTopMargin and closeButtonRightMargin
209-
var closeButtonWithMargins = new AlignBox( closeButton, {
206+
const closeButtonWithMargins = new AlignBox( closeButton, {
210207
topMargin: options.closeButtonTopMargin,
211208
rightMargin: options.closeButtonRightMargin
212209
} );
213210

214211
// create content for Panel
215-
var dialogContent = new HBox( {
212+
const dialogContent = new HBox( {
216213
children: [ contentAndTitleWithMargins, closeButtonWithMargins ],
217214
spacing: options.xSpacing,
218215
align: 'top'
219216
} );
220217

221218
Panel.call( this, dialogContent, options );
222219

223-
var sim = window.phet.joist.sim;
220+
const sim = window.phet.joist.sim;
224221

225222
// @private
226-
this.updateLayout = function() {
227-
options.layoutStrategy( self, sim.boundsProperty.value, sim.screenBoundsProperty.value, sim.scaleProperty.value );
228-
};
223+
this.updateLayout = () =>
224+
options.layoutStrategy( this, sim.boundsProperty.value, sim.screenBoundsProperty.value, sim.scaleProperty.value );
229225

230226
this.updateLayout();
231227

@@ -234,9 +230,7 @@ define( function( require ) {
234230

235231
// a11y - set the order of content, close button first so remaining content can be read from top to bottom
236232
// with virtual cursor
237-
this.accessibleOrder = [ closeButton, options.title, content ].filter( function( node ) {
238-
return node !== undefined;
239-
} );
233+
this.accessibleOrder = [ closeButton, options.title, content ].filter( node => node !== undefined );
240234

241235
// a11y - set the aria-labelledby relation so that whenever focus enters the dialog the title is read
242236
if ( options.title && options.title.tagName ) {
@@ -254,23 +248,23 @@ define( function( require ) {
254248
this.activeElement = options.focusOnCloseNode || null;
255249

256250
// a11y - close the dialog when pressing "escape"
257-
var escapeListener = {
258-
keydown: function( event ) {
259-
var domEvent = event.domEvent;
251+
const escapeListener = {
252+
keydown: event => {
253+
const domEvent = event.domEvent;
260254

261255
if ( domEvent.keyCode === KeyboardUtil.KEY_ESCAPE ) {
262256
domEvent.preventDefault();
263-
self.hide();
264-
self.focusActiveElement();
257+
this.hide();
258+
this.focusActiveElement();
265259
}
266260
else if ( domEvent.keyCode === KeyboardUtil.KEY_TAB && FullScreen.isFullScreen() ) {
267261

268262
// prevent a particular bug in Windows 7/8.1 Firefox where focus gets trapped in the document
269263
// when the navigation bar is hidden and there is only one focusable element in the DOM
270264
// see https://bugzilla.mozilla.org/show_bug.cgi?id=910136
271-
var activeId = Display.focus.trail.getUniqueId();
272-
var noNextFocusable = AccessibilityUtil.getNextFocusable().id === activeId;
273-
var noPreviousFocusable = AccessibilityUtil.getPreviousFocusable().id === activeId;
265+
const activeId = Display.focus.trail.getUniqueId();
266+
const noNextFocusable = AccessibilityUtil.getNextFocusable().id === activeId;
267+
const noPreviousFocusable = AccessibilityUtil.getPreviousFocusable().id === activeId;
274268

275269
if ( noNextFocusable && noPreviousFocusable ) {
276270
domEvent.preventDefault();
@@ -281,9 +275,9 @@ define( function( require ) {
281275
this.addInputListener( escapeListener );
282276

283277
// @private - to be called on dispose()
284-
this.disposeDialog = function() {
285-
self.sim.resizedEmitter.removeListener( self.updateLayout );
286-
self.removeInputListener( escapeListener );
278+
this.disposeDialog = () => {
279+
this.sim.resizedEmitter.removeListener( this.updateLayout );
280+
this.removeInputListener( escapeListener );
287281

288282
closeButton.dispose();
289283

@@ -297,7 +291,7 @@ define( function( require ) {
297291
sun.register( 'Dialog', Dialog );
298292

299293
// @private
300-
Dialog.DEFAULT_LAYOUT_STRATEGY = function( dialog, simBounds, screenBounds, scale ) {
294+
Dialog.DEFAULT_LAYOUT_STRATEGY = ( dialog, simBounds, screenBounds, scale ) => {
301295

302296
// The size is set in the Sim.topLayer, but we need to update the location here
303297
dialog.center = simBounds.center.times( 1.0 / scale );
@@ -363,7 +357,7 @@ define( function( require ) {
363357
* @param {boolean} visible
364358
*/
365359
setAccessibleViewsVisible: function( visible ) {
366-
for ( var i = 0; i < this.sim.screens.length; i++ ) {
360+
for ( let i = 0; i < this.sim.screens.length; i++ ) {
367361
this.sim.screens[ i ].view.accessibleVisible = visible;
368362
}
369363
this.sim.navigationBar.accessibleVisible = visible;
@@ -414,7 +408,7 @@ define( function( require ) {
414408
}, options );
415409

416410
// close button shape, an 'X'
417-
var closeButtonShape = new Shape()
411+
const closeButtonShape = new Shape()
418412
.moveTo( -options.iconLength / 2, -options.iconLength / 2 )
419413
.lineTo( options.iconLength / 2, options.iconLength / 2 )
420414
.moveTo( options.iconLength / 2, -options.iconLength / 2 )
@@ -432,7 +426,6 @@ define( function( require ) {
432426
}
433427

434428
sun.register( 'Dialog.CloseButton', CloseButton );
435-
436429
inherit( RectangularPushButton, CloseButton );
437430

438431
return Dialog;

0 commit comments

Comments
 (0)