Skip to content

Commit

Permalink
Effects: Backporting 8108ec8 - Fixes #7595 - Wrapper-creating jquery-…
Browse files Browse the repository at this point in the history
…ui animations will discard any focus state during the animation - Thanks @rubyruy
  • Loading branch information
gnarf committed Aug 2, 2011
1 parent 4c57f36 commit 82df692
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions ui/jquery.effects.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,16 @@ $.extend($.effects, {
border: 'none',
margin: 0,
padding: 0
});
}),
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
Expand All @@ -394,8 +401,18 @@ $.extend($.effects, {
},

removeWrapper: function(element) {
if (element.parent().is('.ui-effects-wrapper'))
return element.parent().replaceWith(element);
var parent,
active = document.activeElement;

if (element.parent().is('.ui-effects-wrapper')) {
parent = element.parent().replaceWith(element);
// Fixes #7595 - Elements lose focus when wrapped.
if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) {
$( active ).focus();
}
return parent;
}

return element;
},

Expand Down

3 comments on commit 82df692

@coling
Copy link

@coling coling commented on 82df692 May 2, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've noticed a problem with this commit. It's outlined here;
mihaild/jquery-html5-upload#2
but I get the problem in my own plugin (not really gotten around to releasing it publicly yet as it needs a fair bit of supporting documentation and I'm lazy).

Basically, the problem is Firefox veto'ing actions. For me it only happens on the second upload when I initiate a graphical effect.
"Security Manager vetoed action arg 0 [nsIDOMHTMLDivElement.contains]"

Putting the $.contains() test inside a try/catch block avoids the error and thus is a suitable fix. I'll open a new issue about it.

@gnarf
Copy link
Member Author

@gnarf gnarf commented on 82df692 May 2, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please provide a test case on jsFiddle and put it on the ticket? http://bugs.jqueryui.com/ticket/8288

@coling
Copy link

@coling coling commented on 82df692 May 2, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the test case would be a pain to write as I thought it was going to be pretty involved, but I was able to create it pretty easily in the end. I've updated the ticket.

Please sign in to comment.