From d272d916800f4f7fb150033ff2225778f7d0056e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20Carrasco=20Mo=C3=B1ino?= Date: Sat, 7 Dec 2013 17:24:54 +0100 Subject: [PATCH] Use ClipAnimations by default because they extends default ones. Add properties based constructors so as we can customize any animation via properties --- .../gwt/query/client/plugins/Effects.java | 7 ++-- .../client/plugins/effects/ClipAnimation.java | 21 +++++++++--- .../plugins/effects/TransitionsAnimation.java | 33 +++++++++++++++++-- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Effects.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Effects.java index 8de5d91c..75026b3a 100755 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Effects.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Effects.java @@ -24,10 +24,8 @@ import com.google.gwt.query.client.plugins.effects.ClipAnimation; import com.google.gwt.query.client.plugins.effects.ClipAnimation.Action; import com.google.gwt.query.client.plugins.effects.ClipAnimation.Direction; import com.google.gwt.query.client.plugins.effects.Fx; -import com.google.gwt.query.client.plugins.effects.PropertiesAnimation; import com.google.gwt.query.client.plugins.effects.PropertiesAnimation.Easing; import com.google.gwt.query.client.plugins.effects.PropertiesAnimation.EasingCurve; -import com.google.gwt.query.client.plugins.effects.TransitionsAnimation; import com.google.gwt.query.client.plugins.effects.TransitionsAnimation.TransitionsClipAnimation; /** @@ -169,15 +167,14 @@ public class Effects extends QueuePlugin { public Effects animate(Object stringOrProperties, final int duration, final Easing easing, final Function... funcs) { - final Properties p = (stringOrProperties instanceof String) ? $$((String) stringOrProperties) : (Properties) stringOrProperties; for (Element e: elements()) { if (Fx.css3) { - new TransitionsAnimation(easing, e, p, funcs).run(duration); + new TransitionsClipAnimation(easing, e, p, funcs).run(duration); } else { - queueAnimation(e, new PropertiesAnimation(easing, e, p, funcs), duration); + queueAnimation(e, new ClipAnimation(easing, e, p, funcs), duration); } } return this; 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 e0047fc0..deead04d 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 @@ -49,7 +49,7 @@ public class ClipAnimation extends PropertiesAnimation { } private static final String[] attrsToSave = new String[]{ - "position", "overflow", "visibility", "white-space", "top", "left", "width", "height"}; + "position", "overflow", "visibility", "white-space", "top", "left", "width", "height"}; private Action action; private Corner corner; @@ -59,7 +59,11 @@ public class ClipAnimation extends PropertiesAnimation { private Action currentAction; public ClipAnimation(Element elem, Properties p, Function... funcs) { - super(elem, p, funcs); + this(null, elem, p, funcs); + } + + public ClipAnimation(Easing easing, Element elem, Properties p, Function... funcs) { + super(easing, elem, p, funcs); corner = Corner.CENTER; try { corner = Corner.valueOf(getNormalizedValue("clip-origin", p)); @@ -77,8 +81,8 @@ public class ClipAnimation extends PropertiesAnimation { g = GQuery.$(e).as(Effects.Effects); } - private static String getNormalizedValue(String value, Properties p) { - return JsUtils.hyphenize(p.getStr("clip-direction")).replace("-", "_").toUpperCase(); + public static String getNormalizedValue(String value, Properties p) { + return JsUtils.hyphenize(p.getStr(value)).replace("-", "_").toUpperCase(); } public ClipAnimation(Element elem, Action a, Corner c, Direction d, Easing easing, @@ -97,6 +101,9 @@ public class ClipAnimation extends PropertiesAnimation { @Override public void onComplete() { super.onComplete(); + if (action == null) { + return; + } if (currentAction == Action.HIDE) { g.hide(); } @@ -110,6 +117,9 @@ public class ClipAnimation extends PropertiesAnimation { public void onStart() { boolean hidden = !g.isVisible(); super.onStart(); + if (action == null) { + return; + } currentAction = action != Action.TOGGLE ? action : hidden ? Action.SHOW : Action.HIDE; g.saveCssAttrs(attrsToSave); @@ -139,6 +149,9 @@ public class ClipAnimation extends PropertiesAnimation { @Override public void onUpdate(double progress) { super.onUpdate(progress); + if (action == null) { + return; + } if (currentAction == Action.HIDE) { progress = (1 - progress); } 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 14865119..0bb7e1e3 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 @@ -15,7 +15,9 @@ */ package com.google.gwt.query.client.plugins.effects; -import static com.google.gwt.query.client.GQuery.*; +import static com.google.gwt.query.client.GQuery.$; +import static com.google.gwt.query.client.GQuery.$$; +import static com.google.gwt.query.client.plugins.effects.ClipAnimation.getNormalizedValue; import com.google.gwt.dom.client.Element; import com.google.gwt.query.client.Function; @@ -40,6 +42,28 @@ public class TransitionsAnimation extends PropertiesAnimation { private Direction direction; private Action currentAction; + public TransitionsClipAnimation(Element elem, Properties p, Function... funcs) { + this(null, elem, p, funcs); + } + + public TransitionsClipAnimation(Easing easing, Element elem, Properties p, Function... funcs) { + super(easing, 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) { + } + try { + action = Action.valueOf(getNormalizedValue("clip-action", p)); + } catch (Exception e) { + } + } + public TransitionsClipAnimation(Element elem, Action a, Corner c, Direction d, Easing easing, Properties p, final Function... funcs) { super(easing, elem, p, funcs); @@ -52,7 +76,9 @@ public class TransitionsAnimation extends PropertiesAnimation { boolean hidden = !g.isVisible(); super.onStart(); - + if (action == null) { + return; + } currentAction = action != Action.TOGGLE ? action : hidden ? Action.SHOW : Action.HIDE; int bit = currentAction == Action.HIDE ? 1 : 0; @@ -84,6 +110,9 @@ public class TransitionsAnimation extends PropertiesAnimation { @Override public void onComplete() { super.onComplete(); + if (action == null) { + return; + } if (currentAction == Action.HIDE) { g.hide(); } -- 2.39.5