From 73af71879347196ae0dbe61767ff322164c2bfbe Mon Sep 17 00:00:00 2001 From: samreid Date: Wed, 9 Jan 2019 09:32:46 -0700 Subject: [PATCH] Use setVisible for primary Dialog interface, see https://github.com/phetsims/sun/issues/369 --- js/Dialog.js | 67 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/js/Dialog.js b/js/Dialog.js index b15425c7..03ee3909 100644 --- a/js/Dialog.js +++ b/js/Dialog.js @@ -299,43 +299,60 @@ define( require => { inherit( Panel, Dialog, { - // @public - show: function() { - if ( !this.isShowing ) { - window.phet.joist.sim.showPopup( this, this.isModal ); - this.isShowing = true; + /** + * Show or hide the dialog + * @param {boolean} visible + * @public + */ + setVisible( visible ) { + Panel.prototype.setVisible.call( this, visible ); + if ( visible ) { + if ( !this.isShowing ) { + window.phet.joist.sim.showPopup( this, this.isModal ); + this.isShowing = true; + + // a11y - store the currently active element before hiding all other accessible content + // so that the active element isn't blurred + this.activeElement = this.activeElement || Display.focusedNode; + this.setAccessibleViewsVisible( false ); + + // In case the window size has changed since the dialog was hidden, we should try layout out again. + // See https://github.com/phetsims/joist/issues/362 + this.updateLayout(); + + // Do this last + this.showCallback && this.showCallback(); + } + } + else { + if ( this.isShowing ) { - // a11y - store the currently active element before hiding all other accessible content - // so that the active element isn't blurred - this.activeElement = this.activeElement || Display.focusedNode; - this.setAccessibleViewsVisible( false ); + window.phet.joist.sim.hidePopup( this, this.isModal ); + this.isShowing = false; - // In case the window size has changed since the dialog was hidden, we should try layout out again. - // See https://github.com/phetsims/joist/issues/362 - this.updateLayout(); + // a11y - when the dialog is hidden, make all ScreenView content visible to assistive technology + this.setAccessibleViewsVisible( true ); - // Do this last - this.showCallback && this.showCallback(); + // Do this last + this.hideCallback && this.hideCallback(); + } } }, + // @public + // @deprecated - use setVisible + show: function() { + this.setVisible( true ); + }, + /** * Hide the dialog. If you create a new dialog next time you show(), be sure to dispose this * dialog instead. * @public + * @deprecated - use setVisible */ hide: function() { - if ( this.isShowing ) { - - window.phet.joist.sim.hidePopup( this, this.isModal ); - this.isShowing = false; - - // a11y - when the dialog is hidden, make all ScreenView content visible to assistive technology - this.setAccessibleViewsVisible( true ); - - // Do this last - this.hideCallback && this.hideCallback(); - } + this.setVisible( false ); }, /**