@@ -724,22 +724,27 @@ $.widget( "ui.dialog", {
724
724
return ;
725
725
}
726
726
727
- var that = this ,
728
- widgetFullName = this . widgetFullName ;
729
- if ( ! $ . ui . dialog . overlayInstances ) {
730
- // Prevent use of anchors and inputs.
731
- // We use a delay in case the overlay is created from an
732
- // event that we're going to be cancelling. (#2804)
733
- this . _delay ( function ( ) {
734
- // Handle .dialog().dialog("close") (#4065)
735
- if ( $ . ui . dialog . overlayInstances ) {
736
- this . document . bind ( "focusin.dialog" , function ( event ) {
737
- if ( ! that . _allowInteraction ( event ) ) {
738
- event . preventDefault ( ) ;
739
- $ ( ".ui-dialog:visible:last .ui-dialog-content" )
740
- . data ( widgetFullName ) . _focusTabbable ( ) ;
741
- }
742
- } ) ;
727
+ // We use a delay in case the overlay is created from an
728
+ // event that we're going to be cancelling (#2804)
729
+ var isOpening = true ;
730
+ this . _delay ( function ( ) {
731
+ isOpening = false ;
732
+ } ) ;
733
+
734
+ if ( ! this . document . data ( "ui-dialog-overlays" ) ) {
735
+
736
+ // Prevent use of anchors and inputs
737
+ this . _on ( this . document , {
738
+ focusin : function ( event ) {
739
+ if ( isOpening ) {
740
+ return ;
741
+ }
742
+
743
+ if ( ! this . _allowInteraction ( event ) ) {
744
+ event . preventDefault ( ) ;
745
+ this . document . find ( ".ui-dialog:visible:last .ui-dialog-content" )
746
+ . data ( this . widgetFullName ) . _focusTabbable ( ) ;
747
+ }
743
748
}
744
749
} ) ;
745
750
}
@@ -750,7 +755,8 @@ $.widget( "ui.dialog", {
750
755
this . _on ( this . overlay , {
751
756
mousedown : "_keepFocus"
752
757
} ) ;
753
- $ . ui . dialog . overlayInstances ++ ;
758
+ this . document . data ( "ui-dialog-overlays" ,
759
+ ( this . document . data ( "ui-dialog-overlays" ) || 0 ) + 1 ) ;
754
760
} ,
755
761
756
762
_destroyOverlay : function ( ) {
@@ -759,17 +765,20 @@ $.widget( "ui.dialog", {
759
765
}
760
766
761
767
if ( this . overlay ) {
762
- $ . ui . dialog . overlayInstances -- ;
763
-
764
- if ( ! $ . ui . dialog . overlayInstances ) {
765
- this . document . unbind ( "focusin.dialog" ) ;
768
+ var overlays = this . document . data ( "ui-dialog-overlays" ) - 1 ;
769
+
770
+ if ( ! overlays ) {
771
+ this . document
772
+ . off ( "focusin" )
773
+ . removeData ( "ui-dialog-overlays" ) ;
774
+ } else {
775
+ this . document . data ( "ui-dialog-overlays" , overlays ) ;
766
776
}
777
+
767
778
this . overlay . remove ( ) ;
768
779
this . overlay = null ;
769
780
}
770
781
}
771
782
} ) ;
772
783
773
- $ . ui . dialog . overlayInstances = 0 ;
774
-
775
784
} ( jQuery ) ) ;
0 commit comments