@@ -183,8 +183,7 @@ return $.widget( "ui.dialog", {
183183 enable : $ . noop ,
184184
185185 close : function ( event ) {
186- var activeElement ,
187- that = this ;
186+ var that = this ;
188187
189188 if ( ! this . _isOpen || this . _trigger ( "beforeClose" , event ) === false ) {
190189 return ;
@@ -197,21 +196,10 @@ return $.widget( "ui.dialog", {
197196
198197 if ( ! this . opener . filter ( ":focusable" ) . focus ( ) . length ) {
199198
200- // support: IE9
201- // IE9 throws an "Unspecified error" accessing document.activeElement from an <iframe>
202- try {
203- activeElement = this . document [ 0 ] . activeElement ;
204-
205- // Support: IE9, IE10
206- // If the <body> is blurred, IE will switch windows, see #4520
207- if ( activeElement && activeElement . nodeName . toLowerCase ( ) !== "body" ) {
208-
209- // Hiding a focused element doesn't trigger blur in WebKit
210- // so in case we have nothing to focus on, explicitly blur the active element
211- // https://bugs.webkit.org/show_bug.cgi?id=47182
212- $ ( activeElement ) . blur ( ) ;
213- }
214- } catch ( error ) { }
199+ // Hiding a focused element doesn't trigger blur in WebKit
200+ // so in case we have nothing to focus on, explicitly blur the active element
201+ // https://bugs.webkit.org/show_bug.cgi?id=47182
202+ $ . ui . safeBlur ( $ . ui . safeActiveElement ( this . document [ 0 ] ) ) ;
215203 }
216204
217205 this . _hide ( this . uiDialog , this . options . hide , function ( ) {
@@ -255,7 +243,7 @@ return $.widget( "ui.dialog", {
255243 }
256244
257245 this . _isOpen = true ;
258- this . opener = $ ( this . document [ 0 ] . activeElement ) ;
246+ this . opener = $ ( $ . ui . safeActiveElement ( this . document [ 0 ] ) ) ;
259247
260248 this . _size ( ) ;
261249 this . _position ( ) ;
@@ -311,7 +299,7 @@ return $.widget( "ui.dialog", {
311299
312300 _keepFocus : function ( event ) {
313301 function checkFocus ( ) {
314- var activeElement = this . document [ 0 ] . activeElement ,
302+ var activeElement = $ . ui . safeActiveElement ( this . document [ 0 ] ) ,
315303 isActive = this . uiDialog [ 0 ] === activeElement ||
316304 $ . contains ( this . uiDialog [ 0 ] , activeElement ) ;
317305 if ( ! isActive ) {
0 commit comments