1
1
// Copyright 2018, University of Colorado Boulder
2
2
3
3
/**
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
6
5
*
7
- * @author Jonathan Olson <[email protected] >
6
+ * @author Jonathan Olson (PhET Interactive Simulations)
8
7
* @author Sam Reid (PhET Interactive Simulations)
9
- * @author Andrea Lin
8
+ * @author Andrea Lin (PhET Interactive Simulations)
10
9
* @author Chris Malley (PixelZoom, Inc.)
11
10
*/
12
- define ( function ( require ) {
11
+ define ( require => {
13
12
'use strict' ;
14
13
15
14
// 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' ) ;
34
33
35
34
// strings
36
- var closeString = SunA11yStrings . close . value ;
35
+ const closeString = SunA11yStrings . close . value ;
37
36
38
37
// constants
39
- var CLOSE_BUTTON_WIDTH = 14 ;
38
+ const CLOSE_BUTTON_WIDTH = 14 ;
40
39
41
40
/**
42
41
* @param {Node } content - The content to display inside the dialog (not including the title)
@@ -45,8 +44,6 @@ define( function( require ) {
45
44
*/
46
45
function Dialog ( content , options ) {
47
46
48
- var self = this ;
49
-
50
47
options = _ . extend ( {
51
48
52
49
/* Margins and spacing:
@@ -101,7 +98,7 @@ define( function( require ) {
101
98
layoutStrategy : Dialog . DEFAULT_LAYOUT_STRATEGY ,
102
99
103
100
// close button options
104
- closeButtonListener : function ( ) { self . hide ( ) ; } ,
101
+ closeButtonListener : ( ) => this . hide ( ) ,
105
102
closeButtonTouchAreaXDilation : 0 ,
106
103
closeButtonTouchAreaYDilation : 0 ,
107
104
closeButtonMouseAreaXDilation : 0 ,
@@ -154,15 +151,15 @@ define( function( require ) {
154
151
this . isShowing = false ;
155
152
156
153
// create close button
157
- var closeButton = new CloseButton ( {
154
+ const closeButton = new CloseButton ( {
158
155
159
156
iconLength : CLOSE_BUTTON_WIDTH ,
160
- listener : function ( ) {
157
+ listener : ( ) => {
161
158
options . closeButtonListener ( ) ;
162
159
163
160
// if listener was fired because of accessibility
164
161
if ( closeButton . buttonModel . isA11yClicking ( ) ) {
165
- self . focusActiveElement ( ) ;
162
+ this . focusActiveElement ( ) ;
166
163
}
167
164
} ,
168
165
@@ -192,40 +189,39 @@ define( function( require ) {
192
189
// Align content, title, and close button using spacing and margin options
193
190
194
191
// align content and title (if provided) vertically
195
- var contentAndTitle = new VBox ( {
192
+ const contentAndTitle = new VBox ( {
196
193
children : options . title ? [ options . title , content ] : [ content ] ,
197
194
spacing : options . ySpacing ,
198
195
align : options . titleAlign
199
196
} ) ;
200
197
201
198
// add topMargin, bottomMargin, and leftMargin
202
- var contentAndTitleWithMargins = new AlignBox ( contentAndTitle , {
199
+ const contentAndTitleWithMargins = new AlignBox ( contentAndTitle , {
203
200
topMargin : options . topMargin ,
204
201
bottomMargin : options . bottomMargin ,
205
202
leftMargin : options . leftMargin
206
203
} ) ;
207
204
208
205
// add closeButtonTopMargin and closeButtonRightMargin
209
- var closeButtonWithMargins = new AlignBox ( closeButton , {
206
+ const closeButtonWithMargins = new AlignBox ( closeButton , {
210
207
topMargin : options . closeButtonTopMargin ,
211
208
rightMargin : options . closeButtonRightMargin
212
209
} ) ;
213
210
214
211
// create content for Panel
215
- var dialogContent = new HBox ( {
212
+ const dialogContent = new HBox ( {
216
213
children : [ contentAndTitleWithMargins , closeButtonWithMargins ] ,
217
214
spacing : options . xSpacing ,
218
215
align : 'top'
219
216
} ) ;
220
217
221
218
Panel . call ( this , dialogContent , options ) ;
222
219
223
- var sim = window . phet . joist . sim ;
220
+ const sim = window . phet . joist . sim ;
224
221
225
222
// @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 ) ;
229
225
230
226
this . updateLayout ( ) ;
231
227
@@ -234,9 +230,7 @@ define( function( require ) {
234
230
235
231
// a11y - set the order of content, close button first so remaining content can be read from top to bottom
236
232
// 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 ) ;
240
234
241
235
// a11y - set the aria-labelledby relation so that whenever focus enters the dialog the title is read
242
236
if ( options . title && options . title . tagName ) {
@@ -254,23 +248,23 @@ define( function( require ) {
254
248
this . activeElement = options . focusOnCloseNode || null ;
255
249
256
250
// 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 ;
260
254
261
255
if ( domEvent . keyCode === KeyboardUtil . KEY_ESCAPE ) {
262
256
domEvent . preventDefault ( ) ;
263
- self . hide ( ) ;
264
- self . focusActiveElement ( ) ;
257
+ this . hide ( ) ;
258
+ this . focusActiveElement ( ) ;
265
259
}
266
260
else if ( domEvent . keyCode === KeyboardUtil . KEY_TAB && FullScreen . isFullScreen ( ) ) {
267
261
268
262
// prevent a particular bug in Windows 7/8.1 Firefox where focus gets trapped in the document
269
263
// when the navigation bar is hidden and there is only one focusable element in the DOM
270
264
// 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 ;
274
268
275
269
if ( noNextFocusable && noPreviousFocusable ) {
276
270
domEvent . preventDefault ( ) ;
@@ -281,9 +275,9 @@ define( function( require ) {
281
275
this . addInputListener ( escapeListener ) ;
282
276
283
277
// @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 ) ;
287
281
288
282
closeButton . dispose ( ) ;
289
283
@@ -297,7 +291,7 @@ define( function( require ) {
297
291
sun . register ( 'Dialog' , Dialog ) ;
298
292
299
293
// @private
300
- Dialog . DEFAULT_LAYOUT_STRATEGY = function ( dialog , simBounds , screenBounds , scale ) {
294
+ Dialog . DEFAULT_LAYOUT_STRATEGY = ( dialog , simBounds , screenBounds , scale ) => {
301
295
302
296
// The size is set in the Sim.topLayer, but we need to update the location here
303
297
dialog . center = simBounds . center . times ( 1.0 / scale ) ;
@@ -363,7 +357,7 @@ define( function( require ) {
363
357
* @param {boolean } visible
364
358
*/
365
359
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 ++ ) {
367
361
this . sim . screens [ i ] . view . accessibleVisible = visible ;
368
362
}
369
363
this . sim . navigationBar . accessibleVisible = visible ;
@@ -414,7 +408,7 @@ define( function( require ) {
414
408
} , options ) ;
415
409
416
410
// close button shape, an 'X'
417
- var closeButtonShape = new Shape ( )
411
+ const closeButtonShape = new Shape ( )
418
412
. moveTo ( - options . iconLength / 2 , - options . iconLength / 2 )
419
413
. lineTo ( options . iconLength / 2 , options . iconLength / 2 )
420
414
. moveTo ( options . iconLength / 2 , - options . iconLength / 2 )
@@ -432,7 +426,6 @@ define( function( require ) {
432
426
}
433
427
434
428
sun . register ( 'Dialog.CloseButton' , CloseButton ) ;
435
-
436
429
inherit ( RectangularPushButton , CloseButton ) ;
437
430
438
431
return Dialog ;
0 commit comments