From e163e1e2d681c4111ae14843fa61356038032fbf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20Carrasco=20Mo=C3=B1ino?= Date: Sat, 9 Nov 2013 22:08:25 +0100 Subject: [PATCH] Add a constructor to all GQ animation implementations so as we can pass parameters in the properties object. Fix a couple of issues which were preventing to reuse GQ animations multiple times --- .../client/plugins/effects/ClipAnimation.java | 52 +++++++++++++++---- .../plugins/effects/PropertiesAnimation.java | 17 ++++-- .../plugins/effects/TransitionsAnimation.java | 5 ++ 3 files changed, 60 insertions(+), 14 deletions(-) diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/ClipAnimation.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/ClipAnimation.java index 2285230c..c22631a0 100755 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/ClipAnimation.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/ClipAnimation.java @@ -20,6 +20,7 @@ import com.google.gwt.dom.client.Element; import com.google.gwt.query.client.Function; import com.google.gwt.query.client.GQuery; import com.google.gwt.query.client.Properties; +import com.google.gwt.query.client.js.JsUtils; import com.google.gwt.query.client.plugins.Effects; /** @@ -51,20 +52,44 @@ public class ClipAnimation extends PropertiesAnimation { private static final String[] attrsToSave = new String[]{ "position", "overflow", "visibility", "white-space", "top", "left", "width", "height"}; - Action action; - Corner corner; - Direction direction; - int percent; + private Action action; + private Corner corner; + private Direction direction; private GQuery back = Effects.$(); private Function[] funcs; private Effects g; + private Action currentAction; + + public ClipAnimation(Element elem, Properties p, Function... funcs) { + super(elem, p, funcs); + corner = Corner.CENTER; + try { + corner = Corner.valueOf(getNormalizedValue("clip-origin", p)); + } catch (Exception e) { + } + direction = Direction.BIDIRECTIONAL; + try { + direction = Direction.valueOf(getNormalizedValue("clip-direction", p)); + } catch (Exception e) { + } + action = Action.TOGGLE; + try { + action = Action.valueOf(getNormalizedValue("clip-action", p)); + } catch (Exception e) { + } + + this.funcs = funcs; + e = elem; + g = GQuery.$(e).as(Effects.Effects); + } + + private String getNormalizedValue(String value, Properties p) { + return JsUtils.hyphenize(p.getStr("clip-direction")).replace("-", "_").toUpperCase(); + } public ClipAnimation(Element elem, Action a, Corner c, Direction d, Easing easing, Properties p, final Function... funcs) { super(easing, elem, p, funcs); - if (a == Action.TOGGLE) { - a = GQuery.$(elem).isVisible() ? Action.HIDE : Action.SHOW; - } this.action = a; this.corner = c; this.direction = d; @@ -90,7 +115,7 @@ public class ClipAnimation extends PropertiesAnimation { @Override public void onComplete() { super.onComplete(); - if (action == Action.HIDE) { + if (currentAction == Action.HIDE) { g.hide(); } g.restoreCssAttrs(attrsToSave); @@ -103,8 +128,10 @@ public class ClipAnimation extends PropertiesAnimation { @Override public void onStart() { + boolean hidden = !g.isVisible(); super.onStart(); - g.show(); + currentAction = action != Action.TOGGLE ? action : hidden ? Action.SHOW : Action.HIDE; + g.saveCssAttrs(attrsToSave); // CSS clip only works with absolute/fixed positioning @@ -123,13 +150,16 @@ public class ClipAnimation extends PropertiesAnimation { } g.css("overflow", "hidden"); g.css("visivility", "visible"); + + // Set the initial clip viewport before showing the element + onUpdate(0); + g.show(); } @Override public void onUpdate(double progress) { super.onUpdate(progress); - - if (action == Action.HIDE) { + if (currentAction == Action.HIDE) { progress = (1 - progress); } int w = g.outerWidth(); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/PropertiesAnimation.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/PropertiesAnimation.java index d9404e22..86400081 100755 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/PropertiesAnimation.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/PropertiesAnimation.java @@ -269,14 +269,24 @@ public class PropertiesAnimation extends GQAnimation { } protected Easing easing; - protected JsObjectArray effects = JsObjectArray.create(); + protected JsObjectArray effects; protected Function[] funcs; protected Properties prps; - private Effects g; + public PropertiesAnimation(Element elem, Properties p, Function... funcs) { + this(null, elem, p, funcs); + } + public PropertiesAnimation(Easing easing, Element elem, Properties p, Function... funcs) { - this.easing = easing != null ? easing : EasingCurve.linear; + if (easing == null) { + try { + easing = EasingCurve.valueOf(p.getStr("easing")); + } catch (Exception e) { + easing = EasingCurve.linear; + } + } + this.easing = easing; this.e = elem; this.funcs = funcs; this.prps = p; @@ -314,6 +324,7 @@ public class PropertiesAnimation extends GQAnimation { @Override public void onStart() { + effects = JsObjectArray.create(); boolean resize = false; boolean move = false; boolean hidden = !g.isVisible(); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/TransitionsAnimation.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/TransitionsAnimation.java index d15f19ec..12935f78 100755 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/TransitionsAnimation.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/TransitionsAnimation.java @@ -22,6 +22,7 @@ import com.google.gwt.query.client.Function; import com.google.gwt.query.client.Properties; import com.google.gwt.query.client.js.JsObjectArray; import com.google.gwt.query.client.plugins.effects.Fx.TransitFx; +import com.google.gwt.query.client.plugins.effects.PropertiesAnimation.EasingCurve; import com.google.gwt.regexp.shared.MatchResult; /** @@ -92,6 +93,10 @@ public class TransitionsAnimation extends PropertiesAnimation { } private Transitions g; + + public TransitionsAnimation(Element elem, Properties p, Function... funcs) { + this(null, elem, p, funcs); + } public TransitionsAnimation(Easing easing, Element elem, Properties p, Function... funcs) { super(easing, elem, p, funcs); -- 2.39.5