aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRay Cromwell <cromwellian@gmail.com>2009-05-07 07:43:31 +0000
committerRay Cromwell <cromwellian@gmail.com>2009-05-07 07:43:31 +0000
commit0ed7f3c4acaa7575a37894d7106238d0cef742ab (patch)
tree094eba6b18c0802490defc341db3bc1e29908fae
parent503766b707d661aff81957e0f860d854bb608fda (diff)
downloadgwtquery-0ed7f3c4acaa7575a37894d7106238d0cef742ab.tar.gz
gwtquery-0ed7f3c4acaa7575a37894d7106238d0cef742ab.zip
Misc fixes. Sample animation.
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/Effects.java16
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/EventsListener.java1
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java25
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/rebind/LazyGenerator.java2
-rw-r--r--samples/src/main/java/gwtquery/samples/client/GwtQuerySampleModule.java53
5 files changed, 56 insertions, 41 deletions
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Effects.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Effects.java
index 77d3c06e..4278755a 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Effects.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/Effects.java
@@ -15,9 +15,9 @@
*/
package com.google.gwt.query.client;
+import com.google.gwt.core.client.Duration;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NodeList;
-import com.google.gwt.core.client.Duration;
import com.google.gwt.user.client.Timer;
/**
@@ -114,8 +114,12 @@ public class Effects extends GQuery {
return elem.getPropertyDouble(prop);
}
double r = parseDouble(GQuery.curCSS(elem, prop, force));
- return !Double.isNaN(r) && r > -10000 ? r
+ r = !Double.isNaN(r) && r > -10000 ? r
: parseDouble(GQuery.curCSS(elem, prop, false));
+ if (Double.isNaN(r)) {
+ r = 0;
+ }
+ return r;
}
public void hide() {
@@ -520,10 +524,10 @@ public class Effects extends GQuery {
}
/**
- * Fade out all matched elements by adjusting their opacity to 0, then
- * setting display to "none". Only the opacity is adjusted for this
- * animation, meaning that all of the matched elements should already have
- * some form of height and width associated with them.
+ * Fade out all matched elements by adjusting their opacity to 0, then setting
+ * display to "none". Only the opacity is adjusted for this animation, meaning
+ * that all of the matched elements should already have some form of height
+ * and width associated with them.
*/
public Effects fadeOut(int speed) {
return fadeOut(speed, null);
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/EventsListener.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/EventsListener.java
index ae089986..9ca86194 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/EventsListener.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/EventsListener.java
@@ -130,6 +130,7 @@ class EventsListener implements EventListener {
if (listener.hasEventType(etype)) {
if (!listener.fire(event)) {
event.cancelBubble(true);
+ event.stopPropagation();
event.preventDefault();
}
}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java
index 45bf4d76..14741f79 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java
@@ -32,14 +32,12 @@ import com.google.gwt.dom.client.Style;
import com.google.gwt.dom.client.TextAreaElement;
import static com.google.gwt.query.client.Effects.Effects;
import static com.google.gwt.query.client.Events.Events;
-import com.google.gwt.query.client.impl.DocumentStyleImpl;
-import com.google.gwt.query.client.css.BackgroundColor;
-import com.google.gwt.query.client.css.RGBColor;
import com.google.gwt.query.client.css.CssProperty;
-import com.google.gwt.query.client.css.TakesLength;
import com.google.gwt.query.client.css.Length;
-import com.google.gwt.query.client.css.TakesPercentage;
import com.google.gwt.query.client.css.Percentage;
+import com.google.gwt.query.client.css.TakesLength;
+import com.google.gwt.query.client.css.TakesPercentage;
+import com.google.gwt.query.client.impl.DocumentStyleImpl;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Window;
@@ -290,6 +288,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
return new GQuery(elements);
}
+ /**
+ * Wrap a GQuery around an existing element.
+ */
public static GQuery $(Element element) {
JSArray a = JSArray.create();
a.addNode(element);
@@ -297,6 +298,14 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
+ * Wrap a GQuery around an event's target element.
+ */
+ public static GQuery $(Event event) {
+ return $(event.getCurrentTarget());
+ }
+
+
+ /**
* Wrap a JSON object.
*/
public static Properties $$(String properties) {
@@ -2470,7 +2479,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
if (name != null && value != null) {
d.put(name, value);
}
- return name != null ? value : id;
+ return name != null ? d.get(name) : id;
}
private void dequeue(Element elem, String type) {
@@ -2581,7 +2590,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
qq.enqueue(data);
}
if (SelectorEngine.eq(type, "__FXqueue") && qq.length() == 1) {
- data.f(elem);
+ if(data != null) {
+ data.f(elem);
+ }
}
return qq;
}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/LazyGenerator.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/LazyGenerator.java
index 4523222a..0f15fb9f 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/LazyGenerator.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/LazyGenerator.java
@@ -221,7 +221,7 @@ public class LazyGenerator extends Generator {
sw.outdent();
sw.println("}");
sw.outdent();
- sw.println("return true;");
+ sw.println("return false;");
sw.println("}");
sw.outdent();
sw.println("};");
diff --git a/samples/src/main/java/gwtquery/samples/client/GwtQuerySampleModule.java b/samples/src/main/java/gwtquery/samples/client/GwtQuerySampleModule.java
index 74a137b7..cd9c3247 100644
--- a/samples/src/main/java/gwtquery/samples/client/GwtQuerySampleModule.java
+++ b/samples/src/main/java/gwtquery/samples/client/GwtQuerySampleModule.java
@@ -1,17 +1,13 @@
package gwtquery.samples.client;
import com.google.gwt.core.client.EntryPoint;
-import com.google.gwt.query.client.$;
-import com.google.gwt.query.client.Function;
import com.google.gwt.query.client.Effects;
+import com.google.gwt.query.client.Function;
import com.google.gwt.query.client.GQuery;
-import com.google.gwt.query.client.css.CSS;
import static com.google.gwt.query.client.GQuery.$;
+import static com.google.gwt.query.client.GQuery.$$;
import static com.google.gwt.query.client.GQuery.lazy;
-import static com.google.gwt.query.client.css.CSS.*;
-import static com.google.gwt.query.client.css.Length.*;
-import static com.google.gwt.query.client.css.Percentage.*;
-import static com.google.gwt.query.client.css.RGBColor.*;
+import com.google.gwt.user.client.Event;
/**
* Copyright 2007 Timepedia.org Licensed under the Apache License, Version 2.0
@@ -34,27 +30,30 @@ public class GwtQuerySampleModule implements EntryPoint {
public void onModuleLoad() {
GQuery q = $(".note");
- q.setCss(CSS.BACKGROUND_COLOR, CSS.RED);
- q.setCss(TEXT_ALIGN, LEFT);
- q.setCss(VERTICAL_ALIGN, px(10));
- $("div > div").hover(lazy().
- css("color", "red").
- done(), lazy().
+ $("div > div").
css("color", "blue").
- done());
-
-// $(".note").dblclick(
-// lazy().as(Effects.Effects).
-// fadeOut().
-// done());
-// $("div.outer").dblclick(new Function() {
-// @Override
-// public boolean f(Event e, Object data) {
-// $(e.getCurrentTarget()).as(Effects.Effects).slideUp();
-// return true;
-// }
-// });
-// $("div").wrapAll("<table border=2><tr><td></td></tr></table>");
+ hover(
+ lazy().
+ css("color", "red").
+ done(),
+ lazy().
+ css("color", "blue").
+ done());
+ $("div.outer > div").css("position", "relative").dblclick(new Function() {
+ public boolean f(Event e) {
+ $("div.outer > div").as(Effects.Effects).
+ animate($$("left: '+=100'"), 400, Effects.Easing.LINEAR, null).
+ animate($$("top: '+=100'"), 400, Effects.Easing.LINEAR, null).
+ animate($$("left: '-=100'"), 400, Effects.Easing.LINEAR, null).
+ animate($$("top: '-=100'"), 400, Effects.Easing.LINEAR, null);
+
+ return true;
+ }
+ });
+ $(".note").click(lazy().fadeOut().done());
+ $(".note").append(" Hello");
+
+
}
}