From 0fe2debf0013cd964d2073438792b3aec598993c Mon Sep 17 00:00:00 2001 From: Manuel Carrasco Moñino Date: Sat, 9 Nov 2013 12:14:21 +0100 Subject: Make clip-animation extend properties-animation, so as we can mix clip effects with any other property. Fixed some issues in this class as well --- .../client/plugins/effects/ClipAnimation.java | 69 +++++++++++++--------- 1 file changed, 41 insertions(+), 28 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 e81e6340..b38e4747 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 @@ -15,16 +15,17 @@ */ package com.google.gwt.query.client.plugins.effects; + 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.plugins.Effects; -import com.google.gwt.query.client.plugins.Effects.GQAnimation; /** - * Animation wich uses the css clip property to show/hide an element. + * Animation which uses the css clip property to show/hide an element. */ -public class ClipAnimation extends GQAnimation { +public class ClipAnimation extends PropertiesAnimation { /** * Type of the effect action. @@ -48,7 +49,7 @@ public class ClipAnimation extends GQAnimation { } private static final String[] attrsToSave = new String[]{ - "position", "overflow", "visibility", "white-space", "top", "left"}; + "position", "overflow", "visibility", "white-space", "top", "left", "width", "height"}; Action action; Corner corner; @@ -58,8 +59,8 @@ public class ClipAnimation extends GQAnimation { private Function[] funcs; private Effects g; - public ClipAnimation(Element elem, Action a, Corner c, Direction d, - final Function... funcs) { + 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; } @@ -71,6 +72,10 @@ public class ClipAnimation extends GQAnimation { g = GQuery.$(e).as(Effects.Effects); } + public ClipAnimation(Element elem, Action a, Corner c, Direction d, final Function... funcs) { + this(elem, a, c, d, null, Properties.create(), funcs); + } + @Override public void onCancel() { Boolean jumpToEnd = Effects.$(e).data(Effects.JUMP_TO_END, Boolean.class); @@ -97,49 +102,57 @@ public class ClipAnimation extends GQAnimation { @Override public void onStart() { + super.onStart(); g.show(); g.saveCssAttrs(attrsToSave); - if (!"absolute".equalsIgnoreCase(g.css("position", true))) { - g.css("position", "absolute"); - g.css("top", g.offset().top + "px"); - g.css("left", g.offset().left + "px"); + + // CSS clip only works with absolute/fixed positioning + if (!g.css("position", true).matches("absolute|fixed")) { + // Add a temporary element to replace the original one, so nothing is moved when + // setting the absolute position to our element back = back.add(g.before("
")).prev(); back.height(g.height()); back.width(g.width()); + // change the position property, but keeping its original position and sizes + g.css("top", g.offset().top + "px"); + g.css("left", g.offset().left + "px"); + g.css("width", g.width() + "px"); + g.css("height", g.height() + "px"); + g.css("position", "absolute"); } g.css("overflow", "hidden"); g.css("visivility", "visible"); - super.onStart(); } @Override public void onUpdate(double progress) { + super.onUpdate(progress); + if (action == Action.HIDE) { progress = (1 - progress); } - int top = 0; - int left = 0; - int right = g.width(); - int bottom = g.height(); + int w = g.outerWidth(), h = g.outerHeight(); + int top = 0, left = 0, right = w, bottom = h; if (direction == Direction.VERTICAL || direction == Direction.BIDIRECTIONAL) { - bottom = (int) (g.height() * progress); + bottom = (int) (h * progress); } - if (direction == Direction.HORIZONTAL - || direction == Direction.BIDIRECTIONAL) { - right = (int) (g.width() * progress); + if (direction == Direction.HORIZONTAL || direction == Direction.BIDIRECTIONAL) { + right = (int) (w * progress); } if (corner == Corner.CENTER) { - top = (g.height() - bottom) / 2; - left = (g.width() - right) / 2; - } else if (corner == Corner.BOTTOM_LEFT) { - top = (g.height() - bottom); - } else if (corner == Corner.TOP_RIGHT) { - left = (g.width() - right); - } else if (corner == Corner.BOTTOM_RIGHT) { - left = (g.width() - right); - top = (g.height() - bottom); + top = (h - bottom) / 2; + left = (w - right) / 2; + } + if (corner == Corner.TOP_RIGHT || corner == Corner.BOTTOM_RIGHT) { + left = (w - right); + right = w; } + if (corner == Corner.BOTTOM_LEFT || corner == Corner.BOTTOM_RIGHT) { + top = (h - bottom); + bottom = h; + } + String rect = top + "px " + right + "px " + bottom + "px " + left + "px"; g.css("clip", "rect(" + rect + ")"); } -- cgit v1.2.3 From 5f3474f1e610f7bddb2dc847cc1a52bf6d4cec5f Mon Sep 17 00:00:00 2001 From: Manuel Carrasco Moñino Date: Sat, 9 Nov 2013 15:15:19 +0100 Subject: Adding missing method in widgets, and javadocs --- .../com/google/gwt/query/client/plugins/Widgets.java | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java index 7e7f3462..6367e7b7 100755 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java @@ -110,10 +110,7 @@ public class Widgets extends QueuePlugin { } /** - * Create a {@link Button} widget for each selected element. The - * initializers will be called on each new {@link Button} created - * by passing them in parameter. - * + * Create a {@link Button} widget for each selected element. */ public Widgets button() { return widgets(new ButtonWidgetFactory(), null); @@ -129,10 +126,25 @@ public class Widgets extends QueuePlugin { return widgets(new ButtonWidgetFactory(), initializers); } + /** + * Create a {@link Panel} widget for each selected element. + */ public Widgets panel() { return widgets(new HtmlPanelWidgetFactory(), null); } + /** + * Create a {@link Label} widget for each selected element. + */ + public Widgets label() { + return widgets(new LabelWidgetFactory(), null); + } + + /** + * Create a {@link Label} widget for each selected element. The + * initializers will be called on each new {@link Label} created + * by passing them in parameter. + */ public Widgets label(WidgetInitializer