]> source.dussan.org Git - gwtquery.git/commitdiff
Misc fixes. Sample animation.
authorRay Cromwell <cromwellian@gmail.com>
Thu, 7 May 2009 07:43:31 +0000 (07:43 +0000)
committerRay Cromwell <cromwellian@gmail.com>
Thu, 7 May 2009 07:43:31 +0000 (07:43 +0000)
gwtquery-core/src/main/java/com/google/gwt/query/client/Effects.java
gwtquery-core/src/main/java/com/google/gwt/query/client/EventsListener.java
gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java
gwtquery-core/src/main/java/com/google/gwt/query/rebind/LazyGenerator.java
samples/src/main/java/gwtquery/samples/client/GwtQuerySampleModule.java

index 77d3c06e94f6569089498ac3d15dd40835c379ef..4278755a90a4c1c4e92fddf120adfb17045f2329 100644 (file)
@@ -15,9 +15,9 @@
  */\r
 package com.google.gwt.query.client;\r
 \r
+import com.google.gwt.core.client.Duration;\r
 import com.google.gwt.dom.client.Element;\r
 import com.google.gwt.dom.client.NodeList;\r
-import com.google.gwt.core.client.Duration;\r
 import com.google.gwt.user.client.Timer;\r
 \r
 /**\r
@@ -114,8 +114,12 @@ public class Effects extends GQuery {
         return elem.getPropertyDouble(prop);\r
       }\r
       double r = parseDouble(GQuery.curCSS(elem, prop, force));\r
-      return !Double.isNaN(r) && r > -10000 ? r\r
+      r = !Double.isNaN(r) && r > -10000 ? r\r
           : parseDouble(GQuery.curCSS(elem, prop, false));\r
+      if (Double.isNaN(r)) {\r
+        r = 0;\r
+      }\r
+      return r;\r
     }\r
 \r
     public void hide() {\r
@@ -520,10 +524,10 @@ public class Effects extends GQuery {
   }\r
 \r
   /**\r
-   * Fade out all matched elements by adjusting their opacity to 0, then\r
-   * setting display to "none". Only the opacity is adjusted for this\r
-   * animation, meaning that all of the matched elements should already have\r
-   * some form of height and width associated with them.\r
+   * Fade out all matched elements by adjusting their opacity to 0, then setting\r
+   * display to "none". Only the opacity is adjusted for this animation, meaning\r
+   * that all of the matched elements should already have some form of height\r
+   * and width associated with them.\r
    */\r
   public Effects fadeOut(int speed) {\r
     return fadeOut(speed, null);\r
index ae08998638b0507763c04070b076a37e4a8a087e..9ca86194bb6c4fc3ccd969b018beab15cbd3b11e 100644 (file)
@@ -130,6 +130,7 @@ class EventsListener implements EventListener {
       if (listener.hasEventType(etype)) {
         if (!listener.fire(event)) {
           event.cancelBubble(true);
+          event.stopPropagation();
           event.preventDefault();
         }
       }
index 45bf4d76e42be8a8f7950c0fe616a31b0a07c111..14741f7979a8712826fc5cf03f48c5e775dc13b1 100644 (file)
@@ -32,14 +32,12 @@ import com.google.gwt.dom.client.Style;
 import com.google.gwt.dom.client.TextAreaElement;\r
 import static com.google.gwt.query.client.Effects.Effects;\r
 import static com.google.gwt.query.client.Events.Events;\r
-import com.google.gwt.query.client.impl.DocumentStyleImpl;\r
-import com.google.gwt.query.client.css.BackgroundColor;\r
-import com.google.gwt.query.client.css.RGBColor;\r
 import com.google.gwt.query.client.css.CssProperty;\r
-import com.google.gwt.query.client.css.TakesLength;\r
 import com.google.gwt.query.client.css.Length;\r
-import com.google.gwt.query.client.css.TakesPercentage;\r
 import com.google.gwt.query.client.css.Percentage;\r
+import com.google.gwt.query.client.css.TakesLength;\r
+import com.google.gwt.query.client.css.TakesPercentage;\r
+import com.google.gwt.query.client.impl.DocumentStyleImpl;\r
 import com.google.gwt.user.client.DOM;\r
 import com.google.gwt.user.client.Event;\r
 import com.google.gwt.user.client.Window;\r
@@ -290,12 +288,23 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
     return new GQuery(elements);\r
   }\r
 \r
+  /**\r
+   * Wrap a GQuery around an existing element.\r
+   */\r
   public static GQuery $(Element element) {\r
     JSArray a = JSArray.create();\r
     a.addNode(element);\r
     return new GQuery(a);\r
   }\r
 \r
+  /**\r
+   * Wrap a GQuery around an event's target element.\r
+   */\r
+  public static GQuery $(Event event) {\r
+    return $(event.getCurrentTarget());\r
+  }\r
+\r
+\r
   /**\r
    * Wrap a JSON object.\r
    */\r
@@ -2470,7 +2479,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
     if (name != null && value != null) {\r
       d.put(name, value);\r
     }\r
-    return name != null ? value : id;\r
+    return name != null ? d.get(name) : id;\r
   }\r
 \r
   private void dequeue(Element elem, String type) {\r
@@ -2581,7 +2590,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
         qq.enqueue(data);\r
       }\r
       if (SelectorEngine.eq(type, "__FXqueue") && qq.length() == 1) {\r
-        data.f(elem);\r
+        if(data != null) {\r
+          data.f(elem);\r
+        }\r
       }\r
       return qq;\r
     }\r
index 4523222a6fa39acdd40579b2173644f0f613aa84..0f15fb9fcaac4a491820b594ba05aa2bc215e3e9 100644 (file)
@@ -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("};");
index 74a137b74d4c8eb9eb9ca210a2269c743b5f005b..cd9c3247e4789e0aa02f6ae193a752b816027404 100644 (file)
@@ -1,17 +1,13 @@
 package gwtquery.samples.client;\r
 \r
 import com.google.gwt.core.client.EntryPoint;\r
-import com.google.gwt.query.client.$;\r
-import com.google.gwt.query.client.Function;\r
 import com.google.gwt.query.client.Effects;\r
+import com.google.gwt.query.client.Function;\r
 import com.google.gwt.query.client.GQuery;\r
-import com.google.gwt.query.client.css.CSS;\r
 import static com.google.gwt.query.client.GQuery.$;\r
+import static com.google.gwt.query.client.GQuery.$$;\r
 import static com.google.gwt.query.client.GQuery.lazy;\r
-import static com.google.gwt.query.client.css.CSS.*;\r
-import static com.google.gwt.query.client.css.Length.*;\r
-import static com.google.gwt.query.client.css.Percentage.*;\r
-import static com.google.gwt.query.client.css.RGBColor.*;\r
+import com.google.gwt.user.client.Event;\r
 \r
 /**\r
  * Copyright 2007 Timepedia.org Licensed under the Apache License, Version 2.0\r
@@ -34,27 +30,30 @@ public class GwtQuerySampleModule implements EntryPoint {
 \r
   public void onModuleLoad() {\r
     GQuery q = $(".note");\r
-    q.setCss(CSS.BACKGROUND_COLOR, CSS.RED);\r
-    q.setCss(TEXT_ALIGN, LEFT);\r
-    q.setCss(VERTICAL_ALIGN, px(10));\r
 \r
-    $("div > div").hover(lazy().\r
-        css("color", "red").\r
-        done(), lazy().\r
+    $("div > div").\r
         css("color", "blue").\r
-        done());\r
-\r
-//    $(".note").dblclick(\r
-//        lazy().as(Effects.Effects).\r
-//            fadeOut().\r
-//        done());\r
-//     $("div.outer").dblclick(new Function() {\r
-//       @Override\r
-//       public boolean f(Event e, Object data) {\r
-//         $(e.getCurrentTarget()).as(Effects.Effects).slideUp();\r
-//         return true;\r
-//       }\r
-//     });\r
-//    $("div").wrapAll("<table border=2><tr><td></td></tr></table>");\r
+        hover(\r
+            lazy().\r
+              css("color", "red").\r
+            done(),\r
+            lazy().\r
+              css("color", "blue").\r
+            done());\r
+    $("div.outer > div").css("position", "relative").dblclick(new Function() {\r
+      public boolean f(Event e) {\r
+        $("div.outer > div").as(Effects.Effects).\r
+            animate($$("left: '+=100'"), 400, Effects.Easing.LINEAR, null).\r
+            animate($$("top: '+=100'"), 400, Effects.Easing.LINEAR, null).\r
+            animate($$("left: '-=100'"), 400, Effects.Easing.LINEAR, null).\r
+            animate($$("top: '-=100'"), 400, Effects.Easing.LINEAR, null);\r
+\r
+        return true;\r
+      }\r
+    });\r
+    $(".note").click(lazy().fadeOut().done());\r
+    $(".note").append(" Hello");\r
+\r
+\r
   }\r
 }\r