From ebd34704c08403e53a6dbf2b73213ddd2161b81c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20Carrasco=20Mo=C3=B1ino?= Date: Sat, 7 Dec 2013 20:46:13 +0100 Subject: [PATCH] Consider easing and duration passed in the properties object. Fix default duration in animate. --- .../gwt/query/client/plugins/Effects.java | 19 ++++++---- .../plugins/effects/PropertiesAnimation.java | 38 ++++++++++--------- 2 files changed, 32 insertions(+), 25 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 a14c307a..c7b66d5b 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 @@ -163,11 +163,16 @@ public class Effects extends QueuePlugin { * @param duration the duration in milliseconds of the animation * @param easing the easing function to use for the transition */ - public Effects animate(Object stringOrProperties, final int duration, - final Easing easing, final Function... funcs) { + public Effects animate(Object stringOrProperties, int duration, Easing easing, Function... funcs) { final Properties p = (stringOrProperties instanceof String) - ? $$((String) stringOrProperties) : (Properties) stringOrProperties; + ? $$((String) stringOrProperties) : (Properties) stringOrProperties; + + if (p.getStr("duration") != null) { + duration = p.getInt("duration"); + } + + duration = Math.abs(duration); for (Element e: elements()) { if (Fx.css3) { @@ -237,7 +242,7 @@ public class Effects extends QueuePlugin { * complete */ public Effects animate(Object stringOrProperties, Function... funcs) { - return animate(stringOrProperties, 500, funcs); + return animate(stringOrProperties, Speed.DEFAULT, funcs); } /** @@ -303,7 +308,7 @@ public class Effects extends QueuePlugin { * Animate the set of matched elements using the clip or scale property. It is possible to show or * hide a set of elements, specify the direction of the animation and the start corner of the * effect. Finally it executes the set of functions passed as arguments. - * + * * @deprecated use animate() instead */ @Deprecated @@ -316,7 +321,7 @@ public class Effects extends QueuePlugin { * Animate the set of matched elements using the clip or scale property. It is possible to show or * hide a set of elements, specify the direction of the animation and the start corner of the * effect. Finally it executes the set of functions passed as arguments. - * + * * @deprecated use animate() instead */ @Deprecated @@ -337,7 +342,7 @@ public class Effects extends QueuePlugin { * Animate the set of matched elements using the clip or scale property. It is possible to show or * hide a set of elements, specify the direction of the animation and the start corner of the * effect. Finally it executes the set of functions passed as arguments. - * + * * @deprecated use animate() instead */ @Deprecated 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 d18a220a..88e485ce 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 @@ -49,28 +49,28 @@ public class PropertiesAnimation extends GQAnimation { */ public Easing SWING = EasingCurve.swing; } - + /** * This is a collection of most popular curves used in web animations * implemented using the Bezier Curve instead of a different algorithm per * animation. - * + * * The toString() method returns the string parameter which can be used * for CSS3 transition-timing-function properties, example: *
 
    transition-timing-function: ease;
    transition-timing-function: cubic-bezier(0, 0, 1, 1);
-     
+
    * 
- * + * * This enum can be used with customized transitions in this way: *
-    
+
     $("#foo").animate($$("{top:'500px',left:'500px'}"), 400, EasingCurve.custom.with(.02,.01,.47,1));
-     
+
    * 
- * + * */ public static enum EasingCurve implements Easing { linear (0, 0, 1, 1) { @@ -116,7 +116,7 @@ public class PropertiesAnimation extends GQAnimation { easeOutBack (.175, .885,.32,1.275), easeInOutBack (.68,-.55,.265,1.55), custom(0, 0, 1, 1); - + private Bezier c = new Bezier(0, 0, 1, 1); EasingCurve(double x1, double y1, double x2, double y2) { with(x1, y1, x2, y2); @@ -134,12 +134,12 @@ public class PropertiesAnimation extends GQAnimation { } protected static final String[] ATTRS_TO_SAVE = new String[]{"overflow"}; - + private static final RegExp REGEX_NUMBER_UNIT = RegExp.compile("^([0-9+-.]+)(.*)?$"); protected static final RegExp REGEX_SYMBOL_NUMBER_UNIT = RegExp.compile("^([+-]=)?([0-9+-.]+)(.*)?$"); - protected static final RegExp REGEX_NON_PIXEL_ATTRS = + protected static final RegExp REGEX_NON_PIXEL_ATTRS = RegExp.compile("z-?index|font-?weight|opacity|zoom|line-?height|scale|rotation|^\\$", "i"); private static final RegExp REGEX_COLOR_ATTR = RegExp.compile(".*color$", "i"); @@ -277,19 +277,21 @@ public class PropertiesAnimation extends GQAnimation { this(null, elem, p, funcs); } - public PropertiesAnimation(Easing easing, Element elem, Properties p, Function... funcs) { + public PropertiesAnimation(Easing ease, Element elem, Properties p, Function... funcs) { + try { + easing = EasingCurve.valueOf(p.getStr("easing")); + } catch (Exception e) { + } if (easing == null) { - try { - easing = EasingCurve.valueOf(p.getStr("easing")); - } catch (Exception e) { - easing = EasingCurve.linear; - } + easing = ease; + } + if (easing == null) { + easing = EasingCurve.swing; } - this.easing = easing; this.funcs = funcs; setProperties(p); setElement(elem); - + g = $(e).as(Effects.Effects); } -- 2.39.5