]> source.dussan.org Git - jquery-ui.git/commitdiff
Dialog: Safe activeElement access.
authorTJ VanToll <tj.vantoll@gmail.com>
Mon, 30 Sep 2013 14:49:42 +0000 (17:49 +0300)
committerScott González <scott.gonzalez@gmail.com>
Tue, 26 Nov 2013 20:07:39 +0000 (15:07 -0500)
Fixed #9420 - Dialog: Close causes blur of window in IE9
Fixed #8443 - Dialog: "unspecified error" when using ie9 and iframe
(cherry picked from commit 2dfe85d3e2269a571e07bd550bbd838ee703b833)

ui/jquery.ui.dialog.js

index 22bbfbc6d859141ddb65c1e8f306d9d2c830e315..9e2a3b8bc22ac3d8d7e3bd5b4f72eafd7c68df60 100644 (file)
@@ -169,7 +169,8 @@ $.widget( "ui.dialog", {
        enable: $.noop,
 
        close: function( event ) {
-               var that = this;
+               var activeElement,
+                       that = this;
 
                if ( !this._isOpen || this._trigger( "beforeClose", event ) === false ) {
                        return;
@@ -179,10 +180,22 @@ $.widget( "ui.dialog", {
                this._destroyOverlay();
 
                if ( !this.opener.filter(":focusable").focus().length ) {
-                       // Hiding a focused element doesn't trigger blur in WebKit
-                       // so in case we have nothing to focus on, explicitly blur the active element
-                       // https://bugs.webkit.org/show_bug.cgi?id=47182
-                       $( this.document[0].activeElement ).blur();
+
+                       // support: IE9
+                       // IE9 throws an "Unspecified error" accessing document.activeElement from an <iframe>
+                       try {
+                               activeElement = this.document[ 0 ].activeElement;
+
+                               // Support: IE9, IE10
+                               // If the <body> is blurred, IE will switch windows, see #4520
+                               if ( activeElement && activeElement.nodeName.toLowerCase() !== "body" ) {
+
+                                       // Hiding a focused element doesn't trigger blur in WebKit
+                                       // so in case we have nothing to focus on, explicitly blur the active element
+                                       // https://bugs.webkit.org/show_bug.cgi?id=47182
+                                       $( activeElement ).blur();
+                               }
+                       } catch ( error ) {}
                }
 
                this._hide( this.uiDialog, this.options.hide, function() {