diff options
author | Scott González <scott.gonzalez@gmail.com> | 2017-05-11 13:58:08 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2017-05-17 11:29:09 -0400 |
commit | 5708046ea1ba4d6d86f431ec9fd32d28ae7542f6 (patch) | |
tree | 045175cfcd8a0200f8f7db53fda1a4d7f83e486d /ui/widgets | |
parent | 809f29efa79c3c9aba95e6d7ffef41f567cda3a5 (diff) | |
download | jquery-ui-5708046ea1ba4d6d86f431ec9fd32d28ae7542f6.tar.gz jquery-ui-5708046ea1ba4d6d86f431ec9fd32d28ae7542f6.zip |
Dialog: Fix shared event handler for modal dialogs
The old logic worked when all widgets of the same type used the same
event namespace. However, now that each instance has its own namespace,
we cannot use `_on()` for shared event handlers.
Fixes #15182
Closes gh-1817
Diffstat (limited to 'ui/widgets')
-rw-r--r-- | ui/widgets/dialog.js | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/ui/widgets/dialog.js b/ui/widgets/dialog.js index c8829331f..01780daf3 100644 --- a/ui/widgets/dialog.js +++ b/ui/widgets/dialog.js @@ -289,7 +289,7 @@ $.widget( "ui.dialog", { that._trigger( "focus" ); } ); - // Track the dialog immediately upon openening in case a focus event + // Track the dialog immediately upon opening in case a focus event // somehow occurs outside of the dialog before an element inside the // dialog is focused (#10152) this._makeFocusTarget(); @@ -863,20 +863,19 @@ $.widget( "ui.dialog", { if ( !this.document.data( "ui-dialog-overlays" ) ) { // Prevent use of anchors and inputs - // Using _on() for an event handler shared across many instances is - // safe because the dialogs stack and must be closed in reverse order - this._on( this.document, { - focusin: function( event ) { - if ( isOpening ) { - return; - } - - if ( !this._allowInteraction( event ) ) { - event.preventDefault(); - this._trackingInstances()[ 0 ]._focusTabbable(); - } + // This doesn't use `_on()` because it is a shared event handler + // across all open modal dialogs. + this.document.on( "focusin.ui-dialog", function( event ) { + if ( isOpening ) { + return; } - } ); + + var instance = this._trackingInstances()[ 0 ]; + if ( !instance._allowInteraction( event ) ) { + event.preventDefault(); + instance._focusTabbable(); + } + }.bind( this ) ); } this.overlay = $( "<div>" ) @@ -899,7 +898,7 @@ $.widget( "ui.dialog", { var overlays = this.document.data( "ui-dialog-overlays" ) - 1; if ( !overlays ) { - this._off( this.document, "focusin" ); + this.document.off( "focusin.ui-dialog" ); this.document.removeData( "ui-dialog-overlays" ); } else { this.document.data( "ui-dialog-overlays", overlays ); |