]> source.dussan.org Git - jquery-ui.git/commitdiff
Dialog: Track the instance as soon as the dialog is opened
authorScott González <scott.gonzalez@gmail.com>
Wed, 23 Jul 2014 15:10:14 +0000 (11:10 -0400)
committerScott González <scott.gonzalez@gmail.com>
Wed, 23 Jul 2014 15:10:14 +0000 (11:10 -0400)
Fixes #10152

ui/dialog.js

index 470676cbe2239bb2fb28ecb2a0e0ffee9da4c9f2..5561a96cde38116e1b546484964358bdd919819a 100644 (file)
@@ -273,6 +273,11 @@ return $.widget( "ui.dialog", {
                        that._trigger( "focus" );
                });
 
+               // Track the dialog immediately upon openening in case a focus event
+               // somehow occurs outside of the dialog before an element inside the
+               // dialog is focused (#10152)
+               this._makeFocusTarget();
+
                this._trigger( "open" );
        },
 
@@ -584,14 +589,18 @@ return $.widget( "ui.dialog", {
 
        _trackFocus: function() {
                this._on( this.widget(), {
-                       "focusin": function( event ) {
-                               this._untrackInstance();
-                               this._trackingInstances().unshift( this );
+                       focusin: function( event ) {
+                               this._makeFocusTarget();
                                this._focusedElement = $( event.target );
                        }
                });
        },
 
+       _makeFocusTarget: function() {
+               this._untrackInstance();
+               this._trackingInstances().unshift( this );
+       },
+
        _untrackInstance: function() {
                var instances = this._trackingInstances(),
                        exists = $.inArray( this, instances );