Permalink
Browse files

Effects: Backporting 8108ec8 - Fixes #7595 - Wrapper-creating jquery-…

…ui animations will discard any focus state during the animation - Thanks @rubyruy
  • Loading branch information...
1 parent 4c57f36 commit 82df6924cbb0fa080590d83b4edc6183dd05ce93 @gnarf gnarf committed Aug 2, 2011
Showing with 20 additions and 3 deletions.
  1. +20 −3 ui/jquery.effects.core.js
View
@@ -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
@@ -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;
},

3 comments on commit 82df692

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.

Owner

gnarf replied May 2, 2012

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

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.