]> source.dussan.org Git - gwtquery.git/commitdiff
added queue stuff to its own class, so as plugins using queue have to extend this...
authorManolo Carrasco <manolo@apache.org>
Sun, 30 May 2010 06:11:36 +0000 (06:11 +0000)
committerManolo Carrasco <manolo@apache.org>
Sun, 30 May 2010 06:11:36 +0000 (06:11 +0000)
gwtquery-core/src/main/java/com/google/gwt/query/client/Effects.java
gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java
gwtquery-core/src/main/java/com/google/gwt/query/client/GQueryQueue.java [new file with mode: 0644]
gwtquery-core/src/main/java/com/google/gwt/query/client/LazyEffects.java
gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java

index d442491e20cad4de883eb2f6122cdb5a462013b1..b82baaa0289c43cf7bc56d7e3d3435efaabaa819 100644 (file)
@@ -23,7 +23,7 @@ import com.google.gwt.user.client.Timer;
 /**\r
  * Effects plugin for Gwt Query.\r
  */\r
-public class Effects extends GQuery {\r
+public class Effects extends GQueryQueue {\r
 \r
   /**\r
    * Built in easing functions.\r
@@ -290,7 +290,7 @@ public class Effects extends GQuery {
 \r
     public void complete(Element elem) {\r
       if (queue) {\r
-        $(elem).dequeue();\r
+        new Effects(elem).dequeue();\r
       }\r
       if (complete != null) {\r
         complete.f(elem);\r
index c310065a4807694878e806086a472c2ee1b6f3f9..8b01fa20e50b9d2a9d82cce8ac166f6cafa4cb63 100644 (file)
@@ -135,32 +135,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
       this[id]=obj;\r
     }-*/;\r
   }\r
-\r
-  public static final class Queue<T> extends JavaScriptObject {\r
-\r
-    public static Queue newInstance() {\r
-      return createArray().cast();\r
-    }\r
-\r
-    protected Queue() {\r
-    }\r
-\r
-    public native T dequeue() /*-{\r
-       return this.shift();\r
-    }-*/;\r
-\r
-    public native void enqueue(T foo) /*-{\r
-       this.push(foo);\r
-     }-*/;\r
-\r
-    public native int length() /*-{\r
-       return this.length;\r
-    }-*/;\r
-\r
-    public native T peek(int i) /*-{\r
-      return this[i];\r
-    }-*/;\r
-  }\r
   \r
   public static final Element window = window();\r
   public static final Document document = Document.get();\r
@@ -821,23 +795,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
     return bindOrFire(Event.ONDBLCLICK, null, f);\r
   }\r
 \r
-  /**\r
-   * Removes a queued function from the front of the queue and executes it.\r
-   */\r
-  public GQuery dequeue(String type) {\r
-    for (Element e : elements()) {\r
-      dequeue(e, type);\r
-    }\r
-    return this;\r
-  }\r
-\r
-  /**\r
-   * Removes a queued function from the front of the FX queue and executes it.\r
-   */\r
-  public GQuery dequeue() {\r
-    return dequeue("__FX");\r
-  }\r
-\r
   /**\r
    * Run one or more Functions over each element of the GQuery.\r
    * You have to override one of these funcions:\r
@@ -1568,50 +1525,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
     return pushStack(unique(result), "prevAll", getSelector());\r
   }\r
 \r
-  /**\r
-   * Returns a reference to the first element's queue (which is an array of\r
-   * functions).\r
-   */\r
-  public Queue<Function> queue(String type) {\r
-    return queue(elements.getItem(0), type, null);\r
-  }\r
-\r
-  /**\r
-   * Returns a reference to the FX queue.\r
-   */\r
-  public Queue<Function> queue() {\r
-    return queue(elements.getItem(0), "__FX", null);\r
-  }\r
-\r
-  /**\r
-   * Adds a new function, to be executed, onto the end of the queue of all\r
-   * matched elements.\r
-   */\r
-  public GQuery queue(String type, Function data) {\r
-    for (Element e : elements()) {\r
-      queue(e, type, data);\r
-    }\r
-    return this;\r
-  }\r
-\r
-  /**\r
-   * Replaces the current queue with the given queue on all matched elements.\r
-   */\r
-  public GQuery queue(String type, Queue data) {\r
-    for (Element e : elements()) {\r
-      replacequeue(e, type, data);\r
-    }\r
-    return this;\r
-  }\r
-\r
-  /**\r
-   * Adds a new function, to be executed, onto the end of the queue of all\r
-   * matched elements in the FX queue.\r
-   */\r
-  public GQuery queue(Function data) {\r
-    return queue("__FX", data);\r
-  }\r
-\r
   /**\r
    * Removes all matched elements from the DOM.\r
    */\r
@@ -2375,21 +2288,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
     return name != null ? d.getObject(name) : id;\r
   }\r
 \r
-  private void dequeue(Element elem, String type) {\r
-    Queue<Function> q = queue(elem, type, null);\r
-\r
-    if (q != null) {\r
-      Function f = q.dequeue();\r
-\r
-      if (SelectorEngine.eq(type, "__FX")) {\r
-        f = q.peek(0);\r
-      }\r
-      if (f != null) {\r
-        f.f(elem);\r
-      }\r
-    }\r
-  }\r
-\r
   private GQuery domManip(String html, int func) {\r
     return domManip(clean(html), func);\r
   }\r
@@ -2461,27 +2359,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
     return 0;\r
   }\r
 \r
-  private Queue<Function> queue(Element elem, String type, Function data) {\r
-    if (elem != null) {\r
-      type = type + "queue";\r
-      Object q = (Queue) data(elem, type, null);\r
-      if (q == null) {\r
-        q = data(elem, type, Queue.newInstance());\r
-      }\r
-      Queue<Function> qq = (Queue<Function>) q;\r
-      if (data != null) {\r
-        qq.enqueue(data);\r
-      }\r
-      if (SelectorEngine.eq(type, "__FXqueue") && qq.length() == 1) {\r
-        if (data != null) {\r
-          data.f(elem);\r
-        }\r
-      }\r
-      return qq;\r
-    }\r
-    return null;\r
-  }\r
-\r
   private void removeData(Element item, String name) {\r
     if (dataCache == null) {\r
       windowData = JavaScriptObject.createObject().cast();\r
@@ -2501,13 +2378,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
     }\r
   }\r
 \r
-  private void replacequeue(Element elem, String type, Queue data) {\r
-    if (elem != null) {\r
-      type = type + "queue";\r
-      data(elem, type, data);\r
-    }\r
-  }\r
-\r
   private static native Element window() /*-{\r
     return $wnd;\r
   }-*/;\r
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQueryQueue.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQueryQueue.java
new file mode 100644 (file)
index 0000000..23d8d23
--- /dev/null
@@ -0,0 +1,169 @@
+/*
+ * Copyright 2009 Google Inc.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.query.client;
+
+import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.NodeList;
+
+/**
+ * Class used in plugins which need a queue system.
+ */
+public abstract class GQueryQueue extends GQuery {
+
+  private static final class Queue<T> extends JavaScriptObject {
+
+    public static Queue<?> newInstance() {
+      return createArray().cast();
+    }
+
+    @SuppressWarnings("unused")
+    protected Queue() {
+    }
+
+    public native T dequeue() /*-{
+      return this.shift();
+    }-*/;
+
+    public native void enqueue(T foo) /*-{
+      this.push(foo);
+    }-*/;
+
+    public native int length() /*-{
+      return this.length;
+    }-*/;
+
+    public native T peek(int i) /*-{
+      return this[i];
+    }-*/;
+  }
+
+  public GQueryQueue(Element element) {
+    super(element);
+  }
+
+  public GQueryQueue(JSArray elements) {
+    super(elements);
+  }
+
+  public GQueryQueue(NodeList<Element> list) {
+    super(list);
+  }
+
+  /**
+   * Removes a queued function from the front of the FX queue and executes it.
+   */
+  public GQuery dequeue() {
+    return dequeue("__FX");
+  }
+
+  /**
+   * Removes a queued function from the front of the queue and executes it.
+   */
+  public GQueryQueue dequeue(String type) {
+    for (Element e : elements()) {
+      dequeue(e, type);
+    }
+    return this;
+  }
+
+  /**
+   * Returns a reference to the FX queue.
+   */
+  public Queue<Function> queue() {
+    return queue(elements.getItem(0), "__FX", null);
+  }
+
+  /**
+   * Adds a new function, to be executed, onto the end of the queue of all
+   * matched elements in the FX queue.
+   */
+  public GQueryQueue queue(Function data) {
+    return queue("__FX", data);
+  }
+
+  /**
+   * Returns a reference to the first element's queue (which is an array of
+   * functions).
+   */
+  public Queue<Function> queue(String type) {
+    return queue(elements.getItem(0), type, null);
+  }
+
+  /**
+   * Adds a new function, to be executed, onto the end of the queue of all
+   * matched elements.
+   */
+  public GQueryQueue queue(String type, Function data) {
+    for (Element e : elements()) {
+      queue(e, type, data);
+    }
+    return this;
+  }
+
+  /**
+   * Replaces the current queue with the given queue on all matched elements.
+   */
+  public GQueryQueue queue(String type, Queue<?> data) {
+    for (Element e : elements()) {
+      replacequeue(e, type, data);
+    }
+    return this;
+  }
+
+  private void dequeue(Element elem, String type) {
+    Queue<Function> q = queue(elem, type, null);
+
+    if (q != null) {
+      Function f = q.dequeue();
+
+      if (SelectorEngine.eq(type, "__FX")) {
+        f = q.peek(0);
+      }
+      if (f != null) {
+        f.f(elem);
+      }
+    }
+  }
+
+  @SuppressWarnings("unchecked")
+  private Queue<Function> queue(Element elem, String type, Function data) {
+    if (elem != null) {
+      type = type + "queue";
+      Queue<Function> qq = (Queue<Function>) data(elem, type, null);
+      if (qq == null) {
+        qq = (Queue<Function>) data(elem, type, Queue.newInstance());
+      }
+      if (data != null) {
+        qq.enqueue(data);
+      }
+      if (SelectorEngine.eq(type, "__FXqueue") && qq.length() == 1) {
+        if (data != null) {
+          data.f(elem);
+        }
+      }
+      return qq;
+    }
+    return null;
+  }
+
+  private void replacequeue(Element elem, String type, Queue<?> data) {
+    if (elem != null) {
+      type = type + "queue";
+      data(elem, type, data);
+    }
+  }
+}
index 3ac91232afbd16b4e4a516ed1b21d391b1fa4e23..35ae7b802a23b96cee76d7015b16230c89482660 100644 (file)
@@ -11,24 +11,28 @@ public interface LazyEffects extends LazyGQuery<Effects> {
   LazyEffects animate(Properties properties, int speed, Effects.Easing easing,
       Function complete);
 
+  GQueryQueue dequeue();
+
+  GQueryQueue dequeue(String type);
+
   LazyEffects fadeIn();
 
   LazyEffects fadeIn(Effects.Speed speed);
 
-  LazyEffects fadeIn(int speed);
-
   LazyEffects fadeIn(Effects.Speed speed, Function callback);
 
+  LazyEffects fadeIn(int speed);
+
   LazyEffects fadeIn(int speed, Function callback);
 
   LazyEffects fadeOut();
 
   LazyEffects fadeOut(Effects.Speed speed);
 
-  LazyEffects fadeOut(int speed);
-
   LazyEffects fadeOut(Effects.Speed speed, Function callback);
 
+  LazyEffects fadeOut(int speed);
+
   LazyEffects fadeOut(int speed, Function callback);
 
   LazyEffects fadeTo(Effects.Speed speed, double opacity);
@@ -37,6 +41,10 @@ public interface LazyEffects extends LazyGQuery<Effects> {
 
   LazyEffects hide();
 
+  GQueryQueue queue(Function data);
+
+  GQueryQueue queue(String type, Function data);
+
   LazyEffects show();
 
   LazyEffects slideDown();
index 43129fcff3aeb1131106e7eabddbd01055b7668c..724ac34727815d7a15c163edc64a611c2c6d265e 100644 (file)
@@ -225,16 +225,6 @@ public interface LazyGQuery<T> extends LazyBase<T> {
    */
   LazyGQuery<T> dblclick(Function... f);
 
-  /**
-   * Removes a queued function from the front of the queue and executes it.
-   */
-  LazyGQuery<T> dequeue(String type);
-
-  /**
-   * Removes a queued function from the front of the FX queue and executes it.
-   */
-  LazyGQuery<T> dequeue();
-
   /**
    * Run one or more Functions over each element of the GQuery. You have to
    * override one of these funcions: public void f(Element e) public String
@@ -615,18 +605,6 @@ public interface LazyGQuery<T> extends LazyBase<T> {
    */
   LazyGQuery<T> prevAll();
 
-  /**
-   * Adds a new function, to be executed, onto the end of the queue of all
-   * matched elements.
-   */
-  LazyGQuery<T> queue(String type, Function data);
-
-  /**
-   * Adds a new function, to be executed, onto the end of the queue of all
-   * matched elements in the FX queue.
-   */
-  LazyGQuery<T> queue(Function data);
-
   /**
    * Removes all matched elements from the DOM.
    */