From 8108ec82dbc1c203893db18aac827b93d48cfc07 Mon Sep 17 00:00:00 2001 From: Corey Frang Date: Tue, 2 Aug 2011 16:54:24 -0500 Subject: Effects: Adding a check to retain focused elements after wrapping and unwrapping in animations - Fixes #7595 - Wrapper-creating jquery-ui animations will discard any focus state during the animation - Thanks @rubyruy --- ui/jquery.effects.core.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'ui') diff --git a/ui/jquery.effects.core.js b/ui/jquery.effects.core.js index b08cd6cf4..15d81b4b0 100644 --- a/ui/jquery.effects.core.js +++ b/ui/jquery.effects.core.js @@ -415,9 +415,16 @@ $.extend( $.effects, { size = { width: element.width(), height: element.height() - }; + }, + active = document.activeElement; element.wrap( wrapper ); + + // Fixes #7595 - Elements lose focus when wrapped. + if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) { + $( active ).focus(); + } + wrapper = element.parent(); //Hotfix for jQuery 1.4 since some change in wrap() seems to actually loose the reference to the wrapped element // transfer positioning properties to the wrapper @@ -449,8 +456,18 @@ $.extend( $.effects, { }, removeWrapper: function( element ) { - if ( element.parent().is( ".ui-effects-wrapper" ) ) - return element.parent().replaceWith( element ); + var active = document.activeElement; + + if ( element.parent().is( ".ui-effects-wrapper" ) ) { + element.parent().replaceWith( element ); + + // Fixes #7595 - Elements lose focus when wrapped. + if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) { + $( active ).focus(); + } + } + + return element; }, -- cgit v1.2.3