mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
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
This commit is contained in:
parent
8fe87e2885
commit
8108ec82db
@ -150,4 +150,15 @@ asyncTest( "animateClass clears style properties when stopped", function() {
|
|||||||
start();
|
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);
|
})(jQuery);
|
||||||
|
23
ui/jquery.effects.core.js
vendored
23
ui/jquery.effects.core.js
vendored
@ -415,9 +415,16 @@ $.extend( $.effects, {
|
|||||||
size = {
|
size = {
|
||||||
width: element.width(),
|
width: element.width(),
|
||||||
height: element.height()
|
height: element.height()
|
||||||
};
|
},
|
||||||
|
active = document.activeElement;
|
||||||
|
|
||||||
element.wrap( wrapper );
|
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
|
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
|
// transfer positioning properties to the wrapper
|
||||||
@ -449,8 +456,18 @@ $.extend( $.effects, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
removeWrapper: function( element ) {
|
removeWrapper: function( element ) {
|
||||||
if ( element.parent().is( ".ui-effects-wrapper" ) )
|
var active = document.activeElement;
|
||||||
return element.parent().replaceWith( element );
|
|
||||||
|
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;
|
return element;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user