Skip to content
Permalink
Browse files

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
  • Loading branch information
gnarf committed Aug 2, 2011
1 parent 8fe87e2 commit 8108ec82dbc1c203893db18aac827b93d48cfc07
Showing with 31 additions and 3 deletions.
  1. +11 −0 tests/unit/effects/effects_core.js
  2. +20 −3 ui/jquery.effects.core.js
@@ -150,4 +150,15 @@ asyncTest( "animateClass clears style properties when stopped", function() {
start();
});

test( "createWrapper and removeWrapper retain focused elements (#7595)", function() {
expect( 2 );
var test = $( "div.hidden" ).show(),
input = $( "<input>" ).appendTo( test ).focus();

$.effects.createWrapper( test );
equal( document.activeElement, input[ 0 ], "Active element is still input after createWrapper" );
$.effects.removeWrapper( test );
equal( document.activeElement, input[ 0 ], "Active element is still input after removeWrapper" );
})

})(jQuery);
@@ -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;
},

0 comments on commit 8108ec8

Please sign in to comment.
You can’t perform that action at this time.