]> source.dussan.org Git - gwtquery.git/commitdiff
interrim commit
authorRay Cromwell <cromwellian@gmail.com>
Wed, 22 Apr 2009 23:27:30 +0000 (23:27 +0000)
committerRay Cromwell <cromwellian@gmail.com>
Wed, 22 Apr 2009 23:27:30 +0000 (23:27 +0000)
gwtquery-core/pom.xml
gwtquery-core/src/main/java/gwtquery/GwtQuery.gwt.xml
gwtquery-core/src/main/java/gwtquery/client/$.java [new file with mode: 0644]
gwtquery-core/src/main/java/gwtquery/client/Function.java
gwtquery-core/src/main/java/gwtquery/client/GQuery.java
gwtquery-core/src/main/java/gwtquery/client/Predicate.java [new file with mode: 0644]
gwtquery-core/src/main/java/gwtquery/client/SelectorEngine.java
gwtquery-core/src/main/java/gwtquery/client/impl/DocumentStyleImpl.java [new file with mode: 0644]
gwtquery-core/src/main/java/gwtquery/client/impl/DocumentStyleImplIE.java [new file with mode: 0644]
pom.xml
samples/pom.xml

index 8a5c45a69b7bd320e45c9c90e23a1e632855c9cc..5af705a856f50848093e444218611ccfb4266f53 100644 (file)
@@ -3,7 +3,7 @@
   <parent>
     <groupId>gwtquery</groupId>
     <artifactId>gwtquery-project</artifactId>
-    <version>0.31-SNAPSHOT</version>
+    <version>1.0-SNAPSHOT</version>
   </parent>
 
   <artifactId>gwtquery</artifactId>
index aa236dfbd1b6ca33a6e0462ab47f6c8c306ff0ab..8cfabdb0b099ae75d89fcc11c495e97ee2f30f76 100644 (file)
@@ -19,7 +19,7 @@
     <generate-with class="gwtquery.rebind.SelectorGeneratorJS">\r
         <when-type-assignable class="gwtquery.client.Selectors"/>\r
         <any>\r
-           <when-property-is name="user.agent" value="gecko"/>\r
+            <when-property-is name="user.agent" value="gecko"/>\r
             <when-property-is name="user.agent" value="ie6"/>\r
         </any>\r
 \r
@@ -40,8 +40,8 @@
     <generate-with class="gwtquery.rebind.gebcn.SelectorGeneratorNativeGEBCN">\r
         <when-type-assignable class="gwtquery.client.Selectors"/>\r
         <all>\r
-          <when-property-is name="selectorCapability" value="native"/>\r
-          <when-property-is name="user.agent" value="safari"/>\r
+            <when-property-is name="selectorCapability" value="native"/>\r
+            <when-property-is name="user.agent" value="safari"/>\r
         </all>\r
     </generate-with>\r
 \r
     <!--<when-property-is name="selectorCapability" value="native_gebcn"/>-->\r
     <!--</generate-with>-->\r
 \r
+\r
+    <replace-with class="gwtquery.client.impl.DocumentStyleImpl">\r
+        <when-type-assignable class="gwtquery.client.impl.DocumentStyleImpl"/>\r
+    </replace-with>\r
+\r
+    <replace-with class="gwtquery.client.impl.DocumentStyleImplIE">\r
+        <when-type-assignable class="gwtquery.client.impl.DocumentStyleImpl"/>\r
+        <when-property-is name="user.agent" value="ie6"/>\r
+    </replace-with>\r
+\r
+\r
     <replace-with class="gwtquery.client.impl.SelectorEngineJS">\r
         <when-type-assignable class="gwtquery.client.impl.SelectorEngineImpl"/>\r
         <when-property-is name="user.agent" value="gecko"/>\r
         </all>\r
     </replace-with>\r
 \r
-  </module>
\ No newline at end of file
+</module>
\ No newline at end of file
diff --git a/gwtquery-core/src/main/java/gwtquery/client/$.java b/gwtquery-core/src/main/java/gwtquery/client/$.java
new file mode 100644 (file)
index 0000000..273c951
--- /dev/null
@@ -0,0 +1,81 @@
+package gwtquery.client;
+
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.Node;
+import com.google.gwt.dom.client.NodeList;
+
+/**
+ *
+ */
+public class $ {
+
+  public static GQuery $(String selectorOrHtml) {
+    return GQuery.$(selectorOrHtml);
+  }
+
+  public static <T extends GQuery> T $(T gq) {
+    return GQuery.$(gq);
+  }
+
+  /**
+   * This function accepts a string containing a CSS selector which is then used
+   * to match a set of elements, or it accepts raw HTML creating a GQuery
+   * element containing those elements. The second parameter is is a class
+   * reference to a plugin to be used.
+   */
+  public static <T extends GQuery> T $(String selector, Class<T> plugin) {
+    return GQuery.$(selector, plugin);
+  }
+
+  /**
+   * This function accepts a string containing a CSS selector which is then used
+   * to match a set of elements, or it accepts raw HTML creating a GQuery
+   * element containing those elements. The second parameter is the context to
+   * use for the selector.
+   */
+  public static GQuery $(String selector, Node context) {
+    return GQuery.$(selector, context);
+  }
+
+  /**
+   * This function accepts a string containing a CSS selector which is then used
+   * to match a set of elements, or it accepts raw HTML creating a GQuery
+   * element containing those elements. The second parameter is the context to
+   * use for the selector. The third parameter is the class plugin to use.
+   */
+  public static <T extends GQuery> GQuery $(String selector, Node context,
+      Class<T> plugin) {
+    return GQuery.$(selector, context, plugin);
+  }
+
+  /**
+   * Wrap a GQuery around  existing Elements.
+   */
+  public static GQuery $(NodeList<Element> elements) {
+    return GQuery.$(elements);
+  }
+
+  /**
+   * Wrap a GQuery around an existing Element.
+   */
+  public static GQuery $(Element element) {
+    return GQuery.$(element);
+  }
+
+  /**
+   * Wrap a JSON object
+   */
+  public static Properties $$(String properties) {
+    return GQuery.$$(properties);
+  }
+
+  /**
+   * Registers a GQuery plugin
+   * @param plugin
+   * @param pluginFactory
+   */
+  public static void registerPlugin(Class<? extends GQuery> plugin,
+      Plugin<? extends GQuery> pluginFactory) {
+    GQuery.registerPlugin(plugin, pluginFactory);
+  }
+}
index a30bd8ea5050c3384a8df8035c5b241246b0c1f6..f9d70a4f8e29bc33caf06b79dd0aeb43a9d97f3c 100644 (file)
@@ -8,6 +8,10 @@ import com.google.gwt.user.client.Event;
  */
 public abstract class Function {
 
+  public String f(Element e,  int i) {
+    return "";  
+  }
+  
   public void f(Element e) {
   }
 
index 1fa9bba3f72a4f04526937b5a39b0bc5779e28f7..e5598598c73298ed59ae3c7ae44596d67fe43f85 100644 (file)
@@ -1,14 +1,17 @@
 package gwtquery.client;\r
 \r
 import com.google.gwt.core.client.GWT;\r
+import com.google.gwt.core.client.JavaScriptObject;\r
 import com.google.gwt.dom.client.ButtonElement;\r
 import com.google.gwt.dom.client.Document;\r
 import com.google.gwt.dom.client.Element;\r
 import com.google.gwt.dom.client.InputElement;\r
+import com.google.gwt.dom.client.NativeEvent;\r
 import com.google.gwt.dom.client.Node;\r
 import com.google.gwt.dom.client.NodeList;\r
 import com.google.gwt.dom.client.OptionElement;\r
 import com.google.gwt.dom.client.SelectElement;\r
+import com.google.gwt.dom.client.Style;\r
 import com.google.gwt.dom.client.TextAreaElement;\r
 import com.google.gwt.user.client.DOM;\r
 import com.google.gwt.user.client.Event;\r
@@ -17,6 +20,8 @@ import com.google.gwt.user.client.EventListener;
 import java.util.HashMap;\r
 import java.util.Map;\r
 \r
+import gwtquery.client.impl.DocumentStyleImpl;\r
+\r
 /**\r
  *\r
  */\r
@@ -34,8 +39,144 @@ public class GQuery {
     }\r
   }\r
 \r
+  private static class DataCache extends JavaScriptObject {\r
+\r
+    protected DataCache() {\r
+    }\r
+\r
+    public native void delete(String name) /*-{\r
+      delete this[name];\r
+    }-*/;\r
+\r
+    public native void delete(int name) /*-{\r
+      delete this[name];\r
+    }-*/;\r
+\r
+    public native boolean exists(int id) /*-{\r
+      return !!this[id];\r
+    }-*/;\r
+\r
+    public native JavaScriptObject get(String id) /*-{\r
+      return this[id];\r
+    }-*/;\r
+\r
+    public native JavaScriptObject get(int id) /*-{\r
+      return this[id];\r
+    }-*/; /*-{\r
+      delete this[name];\r
+    }-*/\r
+\r
+    public DataCache getCache(int id) {\r
+      return get(id).cast();\r
+    }\r
+\r
+    public native double getDouble(String id) /*-{\r
+      return this[id];\r
+    }-*/;\r
+\r
+    public native double getDouble(int id) /*-{\r
+      return this[id];\r
+    }-*/;\r
+\r
+    public native int getInt(String id) /*-{\r
+      return this[id];\r
+    }-*/;\r
+\r
+    public native int getInt(int id) /*-{\r
+      return this[id];\r
+    }-*/;\r
+\r
+    public native String getString(String id) /*-{\r
+      return this[id];\r
+    }-*/;\r
+\r
+    public native String getString(int id) /*-{\r
+      return this[id];\r
+    }-*/;\r
+\r
+    public native boolean isEmpty() /*-{\r
+        var foo = "";\r
+        for(foo in this) break;\r
+        return !foo;\r
+    }-*/;\r
+\r
+    public native void put(String id, Object obj) /*-{\r
+      return this[id]=obj;\r
+    }-*/;\r
+\r
+    public native void put(int id, Object obj) /*-{\r
+      return this[id]=obj;\r
+    }-*/;\r
+  }\r
+\r
+  private static class FastSet extends JavaScriptObject {\r
+\r
+    public static FastSet create() {\r
+      return JavaScriptObject.createObject().cast();\r
+    }\r
+\r
+    protected FastSet() {\r
+    }\r
+\r
+    public void add(Object o) {\r
+      add0(o.hashCode());\r
+    }\r
+\r
+    public boolean contains(Object o) {\r
+      return contains0(o.hashCode());\r
+    }\r
+\r
+    public void remove(Object o) {\r
+      remove0(o.hashCode());\r
+    }\r
+\r
+    private native void add0(int hc) /*-{\r
+      this[hc]=true;\r
+    }-*/;\r
+\r
+    private native boolean contains0(int hc) /*-{\r
+      return this[hc];\r
+    }-*/;\r
+\r
+    private native void remove0(int hc) /*-{\r
+      delete this[hc];\r
+    }-*/;\r
+  }\r
+\r
+  private static 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
   private static Map<Class<? extends GQuery>, Plugin<? extends GQuery>> plugins;\r
 \r
+  private static Element windowData = null;\r
+\r
+  private static DataCache dataCache = null;\r
+\r
+  private static DocumentStyleImpl styleImpl;\r
+\r
   /**\r
    * This function accepts a string containing a CSS selector which is then used\r
    * to match a set of elements, or it accepts raw HTML creating a GQuery\r
@@ -49,6 +190,7 @@ public class GQuery {
   }\r
 \r
   public static <T extends GQuery> T $(T gq) {\r
+\r
     return gq;\r
   }\r
 \r
@@ -216,6 +358,14 @@ public class GQuery {
 \r
   protected NodeList<Element> elements = null;\r
 \r
+  private String selector;\r
+\r
+  private GQuery previousObject;\r
+\r
+  public GQuery() {\r
+    elements = JavaScriptObject.createArray().cast();\r
+  }\r
+\r
   public GQuery(NodeList<Element> list) {\r
     elements = list;\r
   }\r
@@ -250,10 +400,19 @@ public class GQuery {
     throw new RuntimeException("No plugin registered for class " + plugin);\r
   }\r
 \r
+  /**\r
+   * Access a property on the first matched element. This method makes it easy\r
+   * to retrieve a property value from the first matched element. If the element\r
+   * does not have an attribute with such a name, undefined is returned.\r
+   * Attributes include title, alt, src, href, width, style, etc.\r
+   */\r
   public String attr(String name) {\r
     return elements.getItem(0).getAttribute(name);\r
   }\r
 \r
+  /**\r
+   * Set a single property to a value, on all matched elements.\r
+   */\r
   public GQuery attr(String key, String value) {\r
     for (Element e : elements()) {\r
       e.setAttribute(key, value);\r
@@ -261,6 +420,9 @@ public class GQuery {
     return this;\r
   }\r
 \r
+  /**\r
+   * Set a key/value object as properties to all matched elements.\r
+   */\r
   public GQuery attr(Properties properties) {\r
     for (Element e : elements()) {\r
       for (String name : properties.keys()) {\r
@@ -270,6 +432,21 @@ public class GQuery {
     return this;\r
   }\r
 \r
+  /**\r
+   * Set a single property to a computed value, on all matched elements.\r
+   */\r
+  public GQuery attr(String key, Function closure) {\r
+    for (int i = 0; i < elements.getLength(); i++) {\r
+      Element e = elements.getItem(i);\r
+      e.setAttribute(key, closure.f(e, i));\r
+    }\r
+    return this;\r
+  }\r
+\r
+  /**\r
+   * Binds a handler to one or more events (like click) for each matched\r
+   * element.\r
+   */\r
   public GQuery bind(int eventbits, final Object data, final Function f) {\r
     EventListener listener = new EventListener() {\r
       public void onBrowserEvent(Event event) {\r
@@ -290,18 +467,62 @@ public class GQuery {
     return bind(Event.ONBLUR, null, f);\r
   }\r
 \r
+  public GQuery blur() {\r
+    return trigger(Document.get().createBlurEvent(), null);\r
+  }\r
+\r
   public GQuery change(Function f) {\r
     return bind(Event.ONCHANGE, null, f);\r
   }\r
 \r
+  public GQuery change() {\r
+    return trigger(Document.get().createChangeEvent(), null);\r
+  }\r
+\r
+  /**\r
+   * Get a set of elements containing all of the unique immediate children of\r
+   * each of the matched set of elements. Also note: while parents() will look\r
+   * at all ancestors, children() will only consider immediate child elements.\r
+   */\r
+  public GQuery children() {\r
+    JSArray result = JSArray.create();\r
+    for (Element e : elements()) {\r
+      allNextSiblingElements(e.getFirstChildElement(), result);\r
+    }\r
+    return new GQuery(unique(result));\r
+  }\r
+\r
+  public GQuery click() {\r
+    return trigger(\r
+        Document.get().createClickEvent(0, 0, 0, 0, 0, false, false, false,\r
+            false), null);\r
+  }\r
+\r
+  /**\r
+   * Triggers the click event of each matched element. Causes all of the\r
+   * functions that have been bound to that click event to be executed.\r
+   */\r
   public GQuery click(final Function f) {\r
     return bind(Event.ONCLICK, null, f);\r
   }\r
 \r
+  /**\r
+   * Return a style property on the first matched element.\r
+   */\r
   public String css(String name) {\r
     return elements.getItem(0).getStyle().getProperty(name);\r
   }\r
 \r
+  /**\r
+   * Set a key/value object as style properties to all matched elements. This is\r
+   * the best way to set several style properties on all matched elements. Be\r
+   * aware, however, that when the key contains a hyphen, such as\r
+   * "background-color," it must either be placed within quotation marks or be\r
+   * written in camel case like so: backgroundColor. As "float" and "class" are\r
+   * reserved words in JavaScript, it's recommended to always surround those\r
+   * terms with quotes. gQuery normalizes the "opacity" property in Internet\r
+   * Explorer.\r
+   */\r
   public GQuery css(Properties properties) {\r
     for (String property : properties.keys()) {\r
       css(property, properties.get(property));\r
@@ -309,6 +530,10 @@ public class GQuery {
     return this;\r
   }\r
 \r
+  /**\r
+   * Set a single style property to a value on all matched elements. If a number\r
+   * is provided, it is automatically converted into a pixel value.\r
+   */\r
   public GQuery css(String prop, String val) {\r
     for (Element e : elements()) {\r
       e.getStyle().setProperty(prop, val);\r
@@ -316,10 +541,60 @@ public class GQuery {
     return this;\r
   }\r
 \r
+  /**\r
+   * Returns value at named data store for the element, as set by data(name,\r
+   * value).\r
+   */\r
+  public Object data(String name) {\r
+    return data(elements.getItem(0), name, null);\r
+  }\r
+\r
+  /**\r
+   * Returns value at named data store for the element, as set by data(name,\r
+   * value) with desired return type.\r
+   *\r
+   * @param clz return type class literal\r
+   */\r
+  public <T> T data(String name, Class<T> clz) {\r
+    return (T) data(elements.getItem(0), name, null);\r
+  }\r
+\r
+  /**\r
+   * Stores the value in the named spot with desired return type.\r
+   */\r
+  public void data(String name, String value) {\r
+    for (Element e : elements()) {\r
+      data(e, name, value);\r
+    }\r
+  }\r
+\r
+  public GQuery dblclick() {\r
+    return trigger(\r
+        Document.get().createDblClickEvent(0, 0, 0, 0, 0, false, false, false,\r
+            false), null);\r
+  }\r
+\r
   public GQuery dblclick(Function f) {\r
     return bind(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
    */\r
@@ -340,6 +615,14 @@ public class GQuery {
     return asArray(elements);\r
   }\r
 \r
+  /**\r
+   * Revert the most recent 'destructive' operation, changing the set of matched\r
+   * elements to its previous state (right before the destructive operation).\r
+   */\r
+  public GQuery end() {\r
+    return previousObject != null ? previousObject : new GQuery();\r
+  }\r
+\r
   /**\r
    * Reduce GQuery to element in the specified position.\r
    */\r
@@ -347,10 +630,35 @@ public class GQuery {
     return $(elements.getItem(pos));\r
   }\r
 \r
+  public GQuery error() {\r
+    return trigger(Document.get().createErrorEvent(), null);\r
+  }\r
+\r
   public GQuery error(Function f) {\r
     return bind(Event.ONERROR, null, f);\r
   }\r
 \r
+  /**\r
+   * Removes all elements from the set of matched elements that do not match the\r
+   * specified function. The function is called with a context equal to the\r
+   * current element. If the function returns false, then the element is removed\r
+   * - anything else and the element is kept.\r
+   */\r
+  public GQuery filter(Predicate filterFn) {\r
+    JSArray result = JSArray.create();\r
+    for (int i = 0; i < elements.getLength(); i++) {\r
+      Element e = elements.getItem(i);\r
+      if (filterFn.f(e, i)) {\r
+        result.addNode(e);\r
+      }\r
+    }\r
+    return pushStack(result, "filter", selector);\r
+  }\r
+\r
+  public GQuery focus() {\r
+    return trigger(Document.get().createFocusEvent(), null);\r
+  }\r
+\r
   public GQuery focus(Function f) {\r
     return bind(Event.ONFOCUS, null, f);\r
   }\r
@@ -370,6 +678,14 @@ public class GQuery {
     return elements.getItem(i);\r
   }\r
 \r
+  public GQuery getPreviousObject() {\r
+    return previousObject;\r
+  }\r
+\r
+  public String getSelector() {\r
+    return selector;\r
+  }\r
+\r
   /**\r
    * Returns true any of the specified classes are present on any of the matched\r
    * elements.\r
@@ -424,14 +740,32 @@ public class GQuery {
     return -1;\r
   }\r
 \r
+  public GQuery keydown() {\r
+    return trigger(\r
+        Document.get().createKeyDownEvent(false, false, false, false, 0, 0),\r
+        null);\r
+  }\r
+\r
   public GQuery keydown(Function f) {\r
     return bind(Event.ONKEYDOWN, null, f);\r
   }\r
 \r
+  public GQuery keypress() {\r
+    return trigger(\r
+        Document.get().createKeyPressEvent(false, false, false, false, 0, 0),\r
+        null);\r
+  }\r
+\r
   public GQuery keypressed(Function f) {\r
     return bind(Event.ONKEYPRESS, null, f);\r
   }\r
 \r
+  public GQuery keyup() {\r
+    return trigger(\r
+        Document.get().createKeyUpEvent(false, false, false, false, 0, 0),\r
+        null);\r
+  }\r
+\r
   public GQuery keyup(Function f) {\r
     return bind(Event.ONKEYUP, null, f);\r
   }\r
@@ -460,10 +794,152 @@ public class GQuery {
     return bind(Event.ONMOUSEUP, null, f);\r
   }\r
 \r
+  /**\r
+   * Get a set of elements containing the unique next siblings of each of the\r
+   * given set of elements. next only returns the very next sibling for each\r
+   * element, not all next siblings see {#nextAll}.\r
+   */\r
+  public GQuery next() {\r
+    JSArray result = JSArray.create();\r
+    for (Element e : elements()) {\r
+      Element next = e.getNextSiblingElement();\r
+      if (next != null) {\r
+        result.addNode(next);\r
+      }\r
+    }\r
+    return new GQuery(unique(result));\r
+  }\r
+\r
+  /**\r
+   * Find all sibling elements after the current element.\r
+   */\r
+  public GQuery nextAll() {\r
+    JSArray result = JSArray.create();\r
+    for (Element e : elements()) {\r
+      allNextSiblingElements(e.getNextSiblingElement(), result);\r
+    }\r
+    return new GQuery(unique(result));\r
+  }\r
+\r
   public Offset offset() {\r
     return new Offset(get(0).getOffsetLeft(), get(0).getOffsetTop());\r
   }\r
 \r
+  /**\r
+   * Returns a jQuery collection with the positioned parent of the first matched\r
+   * element. This is the first parent of the element that has position (as in\r
+   * relative or absolute). This method only works with visible elements.\r
+   */\r
+  public GQuery offsetParent() {\r
+    Element offParent = SelectorEngine\r
+        .or(elements.getItem(0).getOffsetParent(), Document.get().getBody());\r
+    while (offParent != null && !"body".equalsIgnoreCase(offParent.getTagName())\r
+        && !"html".equalsIgnoreCase(offParent.getTagName()) && "static"\r
+        .equals(curCSS(offParent, "position"))) {\r
+      offParent = offParent.getOffsetParent();\r
+    }\r
+    return new GQuery(offParent);\r
+  }\r
+\r
+  /**\r
+   * Get a set of elements containing the unique parents of the matched set of\r
+   * elements.\r
+   */\r
+  public GQuery parent() {\r
+    JSArray result = JSArray.create();\r
+    for (Element e : elements()) {\r
+      result.addNode(e.getParentElement());\r
+    }\r
+    return new GQuery(unique(result));\r
+  }\r
+\r
+  /**\r
+   * Get a set of elements containing the unique ancestors of the matched set of\r
+   * elements (except for the root element).\r
+   */\r
+  public GQuery parents() {\r
+    JSArray result = JSArray.create();\r
+    for (Element e : elements()) {\r
+      Node par = e.getParentNode();\r
+      while (par != null && par != Document.get()) {\r
+        result.addNode(par);\r
+        par = par.getParentNode();\r
+      }\r
+    }\r
+    return new GQuery(unique(result));\r
+  }\r
+\r
+  /**\r
+   * Get a set of elements containing the unique previous siblings of each of\r
+   * the matched set of elements. Only the immediately previous sibling is\r
+   * returned, not all previous siblings.\r
+   */\r
+  public GQuery prev() {\r
+    JSArray result = JSArray.create();\r
+    for (Element e : elements()) {\r
+      Element next = getPreviousSiblingElement(e);\r
+      if (next != null) {\r
+        result.addNode(next);\r
+      }\r
+    }\r
+    return new GQuery(unique(result));\r
+  }\r
+\r
+  /**\r
+   * Find all sibling elements in front of the current element.\r
+   */\r
+  public GQuery prevAll() {\r
+    JSArray result = JSArray.create();\r
+    for (Element e : elements()) {\r
+      allPreviousSiblingElements(getPreviousSiblingElement(e), result);\r
+    }\r
+    return new GQuery(unique(result));\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
    * Remove the named attribute from every element in the matched set.\r
    */\r
@@ -486,10 +962,46 @@ public class GQuery {
     return this;\r
   }\r
 \r
+  /**\r
+   * Removes named data store from an element.\r
+   */\r
+  public GQuery removeData(String name) {\r
+    for (Element e : elements()) {\r
+      removeData(e, name);\r
+    }\r
+    return this;\r
+  }\r
+\r
   public GQuery scroll(Function f) {\r
     return bind(Event.ONSCROLL, null, f);\r
   }\r
 \r
+  public GQuery select() {\r
+    return trigger(Document.get().createHtmlEvent("select", false, false),\r
+        null);\r
+  }\r
+  \r
+  public void setPreviousObject(GQuery previousObject) {\r
+    this.previousObject = previousObject;\r
+  }\r
+\r
+  public void setSelector(String selector) {\r
+    this.selector = selector;\r
+  }\r
+\r
+  /**\r
+   * Get a set of elements containing all of the unique siblings of each of the\r
+   * matched set of elements.\r
+   */\r
+  public GQuery siblings() {\r
+    JSArray result = JSArray.create();\r
+    for (Element e : elements()) {\r
+      allNextSiblingElements(e.getParentElement().getFirstChildElement(),\r
+          result);\r
+    }\r
+    return new GQuery(unique(result));\r
+  }\r
+\r
   /**\r
    * Return the number of elements in the matched set.\r
    */\r
@@ -497,6 +1009,9 @@ public class GQuery {
     return elements.getLength();\r
   }\r
 \r
+  /**\r
+   * Selects a subset of the matched elements.\r
+   */\r
   public GQuery slice(int start, int end) {\r
     JSArray slice = JSArray.create();\r
     if (end == -1 || end > elements.getLength()) {\r
@@ -508,6 +1023,11 @@ public class GQuery {
     return new GQuery(slice);\r
   }\r
 \r
+  public GQuery submit() {\r
+    return trigger(Document.get().createHtmlEvent("submit", false, false),\r
+        null);\r
+  }\r
+\r
   /**\r
    * Return the text contained in the first matched element.\r
    */\r
@@ -541,6 +1061,33 @@ public class GQuery {
     return this;\r
   }\r
 \r
+  /**\r
+   * Adds or removes the specified classes to each matched element.\r
+   */\r
+  public GQuery toggleClass(String clz, boolean sw) {\r
+    for (Element e : elements()) {\r
+      setStyleName(e, clz, sw);\r
+    }\r
+    return this;\r
+  }\r
+\r
+  /**\r
+   * Remove all duplicate elements from an array of elements. Note that this\r
+   * only works on arrays of DOM elements, not strings or numbers.\r
+   */\r
+  public JSArray unique(JSArray result) {\r
+    FastSet f = FastSet.create();\r
+    JSArray ret = JSArray.create();\r
+    for (int i = 0; i < result.getLength(); i++) {\r
+      Element e = result.getElement(i);\r
+      if (!f.contains(e)) {\r
+        f.add(e);\r
+        ret.addNode(e);\r
+      }\r
+    }\r
+    return ret;\r
+  }\r
+\r
   /**\r
    * Get the content of the value attribute of the first matched element,\r
    * returns more than one value if it is a multiple select.\r
@@ -621,9 +1168,143 @@ public class GQuery {
     return this;\r
   }\r
 \r
+  protected GQuery pushStack(JSArray elts, String name, String selector) {\r
+    GQuery g = new GQuery(elts);\r
+    g.setPreviousObject(this);\r
+    g.setSelector(selector);\r
+    return g;\r
+  }\r
+\r
+  private void allNextSiblingElements(Element firstChildElement,\r
+      JSArray result) {\r
+    while (firstChildElement != null) {\r
+      result.addNode(firstChildElement);\r
+      firstChildElement = firstChildElement.getNextSiblingElement();\r
+    }\r
+  }\r
+\r
+  private void allPreviousSiblingElements(Element firstChildElement,\r
+      JSArray result) {\r
+    while (firstChildElement != null) {\r
+      result.addNode(firstChildElement);\r
+      firstChildElement = getPreviousSiblingElement(firstChildElement);\r
+    }\r
+  }\r
+\r
+  private String curCSS(Element elem, String name) {\r
+    Style s = elem.getStyle();\r
+    ensureStyleImpl();\r
+    name = styleImpl.getPropertyName(name);\r
+\r
+    if (SelectorEngine.truth(s.getProperty(name))) {\r
+      return s.getProperty(name);\r
+    }\r
+    return styleImpl.getCurrentStyle(elem, name);\r
+  }\r
+\r
+  private <S> Object data(Element item, String name, S value) {\r
+    if (dataCache == null) {\r
+      windowData = JavaScriptObject.createObject().cast();\r
+      dataCache = JavaScriptObject.createObject().cast();\r
+    }\r
+    item = item == window() ? windowData : item;\r
+    int id = item.hashCode();\r
+    if (name != null && !dataCache.exists(id)) {\r
+      dataCache.put(id, DataCache.createObject().cast());\r
+    }\r
+\r
+    DataCache d = dataCache.get(id).cast();\r
+    if (name != null && value != null) {\r
+      d.put(name, value);\r
+    }\r
+    return name != null ? value : id;\r
+  }\r
+\r
+  private void dequeue(Element elem, String type) {\r
+    Queue<Function> q = queue(elem, type, null);\r
+    Function f = q.dequeue();\r
+\r
+    if (q != null) {\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 void ensureStyleImpl() {\r
+    if (styleImpl != null) {\r
+      styleImpl = GWT.create(DocumentStyleImpl.class);\r
+    }\r
+  }\r
+\r
+  private native Element getPreviousSiblingElement(Element elem)  /*-{\r
+    var sib = elem.previousSibling;\r
+    while (sib && sib.nodeType != 1)\r
+      sib = sib.previousSibling;\r
+    return sib;\r
+  }-*/;\r
+\r
   private void init(GQuery gQuery) {\r
     this.elements = gQuery.elements;\r
   }\r
-  \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, "__FX") && qq.length() == 1) {\r
+        data.f(elem);\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
+      dataCache = JavaScriptObject.createObject().cast();\r
+    }\r
+    item = item == window() ? windowData : item;\r
+    int id = item.hashCode();\r
+    if (name != null) {\r
+      if (!dataCache.exists(id)) {\r
+        dataCache.getCache(id).delete(name);\r
+      }\r
+      if (dataCache.getCache(id).isEmpty()) {\r
+        removeData(item, null);\r
+      }\r
+    } else {\r
+      dataCache.delete(id);\r
+    }\r
+  }\r
+\r
+  private void replacequeue(Element elem, String type, Queue data) {\r
+    if (elem != null) {\r
+      type = type + "queue";\r
+      Object q = (Queue) data(elem, type, null);\r
+      data(elem, type, data);\r
+    }\r
+  }\r
+\r
+  private GQuery trigger(NativeEvent event, Object o) {\r
+    for (Element e : elements()) {\r
+      e.dispatchEvent(event);\r
+    }\r
+    return this;\r
+  }\r
+\r
+  private native Element window() /*-{\r
+    return $wnd;\r
+  }-*/;\r
 }\r
diff --git a/gwtquery-core/src/main/java/gwtquery/client/Predicate.java b/gwtquery-core/src/main/java/gwtquery/client/Predicate.java
new file mode 100644 (file)
index 0000000..feb7b64
--- /dev/null
@@ -0,0 +1,10 @@
+package gwtquery.client;
+
+import com.google.gwt.dom.client.Element;
+
+/**
+ * A predicate function used by some GQuery methods.
+ */
+public interface Predicate {
+    boolean f(Element e, int index);
+}
index 63c246ecd5002ae05ebe6823872e93bde339c373..167a67586cf1f00051e173b9e1ce433a552703c0 100644 (file)
@@ -13,53 +13,53 @@ import gwtquery.client.impl.SelectorEngineImpl;
  *\r
  */\r
 public class SelectorEngine {\r
-    private SelectorEngineImpl impl;\r
 \r
+  private SelectorEngineImpl impl;\r
 \r
-    public SelectorEngine() {\r
-      impl = (SelectorEngineImpl) GWT\r
-                .create(SelectorEngineImpl.class);  \r
-    }\r
+  public SelectorEngine() {\r
+    impl = (SelectorEngineImpl) GWT.create(SelectorEngineImpl.class);\r
+  }\r
 \r
-    public static native boolean eq(String s1, String s2) /*-{\r
+  public static native boolean eq(String s1, String s2) /*-{\r
        return s1 == s2;\r
     }-*/;\r
 \r
-    public static native NodeList<Element> getElementsByClassName(String clazz,\r
-                                                                  Node ctx) /*-{\r
+  public static native NodeList<Element> getElementsByClassName(String clazz,\r
+      Node ctx) /*-{\r
         return ctx.getElementsByClassName(clazz);\r
     }-*/;\r
 \r
-    public static native String or(String s1, String s2) /*-{\r
+  public  static native <T> T or(T s1, T s2) /*-{\r
        return s1 || s2;\r
     }-*/;\r
 \r
-    public static native NodeList<Element> querySelectorAll(String selector) /*-{\r
+  public static native NodeList<Element> querySelectorAll(String selector) /*-{\r
       return $doc.querySelectorAll(selector);\r
   }-*/;\r
 \r
-    public static native NodeList<Element> querySelectorAll(String selector,\r
-                                                            Node ctx) /*-{\r
+  public static native NodeList<Element> querySelectorAll(String selector,\r
+      Node ctx) /*-{\r
       return ctx.querySelectorAll(selector);\r
   }-*/;\r
 \r
-    public NodeList<Element> select(String selector, Node ctx) {\r
-        return impl.select(selector, ctx);\r
-    }\r
-    public static boolean truth(String a) {\r
-        return GWT.isScript() ? truth0(a) : a != null && !"".equals(a);\r
-    }\r
+  public NodeList<Element> select(String selector, Node ctx) {\r
+    return impl.select(selector, ctx);\r
+  }\r
 \r
-    public static boolean truth(JavaScriptObject a) {\r
-        return GWT.isScript() ? truth0(a) : a != null;\r
-    }\r
+  public static boolean truth(String a) {\r
+    return GWT.isScript() ? truth0(a) : a != null && !"".equals(a);\r
+  }\r
 \r
-    public static NodeList<Element> xpathEvaluate(String selector, Node ctx) {\r
-        return xpathEvaluate(selector, ctx, JSArray.create());\r
-    }\r
+  public static boolean truth(JavaScriptObject a) {\r
+    return GWT.isScript() ? truth0(a) : a != null;\r
+  }\r
+\r
+  public static NodeList<Element> xpathEvaluate(String selector, Node ctx) {\r
+    return xpathEvaluate(selector, ctx, JSArray.create());\r
+  }\r
 \r
-    public static native NodeList<Element> xpathEvaluate(String selector,\r
-                                                         Node ctx, JSArray r) /*-{\r
+  public static native NodeList<Element> xpathEvaluate(String selector,\r
+      Node ctx, JSArray r) /*-{\r
       var node;\r
       var result = $doc.evaluate(selector, ctx, null, 0, null);\r
       while ((node = result.iterateNext())) {\r
@@ -68,30 +68,30 @@ public class SelectorEngine {
       return r;\r
   }-*/;\r
 \r
-    private static native boolean truth0(String a) /*-{\r
+  private static native boolean truth0(String a) /*-{\r
        return a;\r
     }-*/;\r
 \r
-    private static native boolean truth0(JavaScriptObject a) /*-{\r
+  private static native boolean truth0(JavaScriptObject a) /*-{\r
          return a;\r
       }-*/;\r
 \r
-    protected JSArray veryQuickId(Node context, String id) {\r
-        JSArray r = JSArray.create();\r
-        if (context.getNodeType() == Node.DOCUMENT_NODE) {\r
-            r.addNode(((Document) context).getElementById(id));\r
-            return r;\r
-        } else {\r
-            r.addNode(context.getOwnerDocument().getElementById(id));\r
-            return r;\r
-        }\r
+  protected JSArray veryQuickId(Node context, String id) {\r
+    JSArray r = JSArray.create();\r
+    if (context.getNodeType() == Node.DOCUMENT_NODE) {\r
+      r.addNode(((Document) context).getElementById(id));\r
+      return r;\r
+    } else {\r
+      r.addNode(context.getOwnerDocument().getElementById(id));\r
+      return r;\r
     }\r
+  }\r
 \r
-    public static native Node getNextSibling(Node n) /*-{\r
+  public static native Node getNextSibling(Node n) /*-{\r
        return n.nextSibling || null; \r
     }-*/;\r
 \r
-    public static native Node getPreviousSibling(Node n) /*-{\r
+  public static native Node getPreviousSibling(Node n) /*-{\r
        return n.previousSibling || null; \r
     }-*/;\r
 }\r
diff --git a/gwtquery-core/src/main/java/gwtquery/client/impl/DocumentStyleImpl.java b/gwtquery-core/src/main/java/gwtquery/client/impl/DocumentStyleImpl.java
new file mode 100644 (file)
index 0000000..c61a88b
--- /dev/null
@@ -0,0 +1,41 @@
+package gwtquery.client.impl;
+
+import com.google.gwt.dom.client.Element;
+
+import gwtquery.client.SelectorEngine;
+
+/**
+ *
+ */
+public class DocumentStyleImpl {
+
+  public String getPropertyName(String name) {
+    if ("float".equals(name)) {
+      return "cssFloat";
+    } else if ("class".equals(name)) {
+      return "className";
+    } else if ("for".equals(name)) {
+      return "htmlFor";
+    }
+    return name;
+  }
+
+  public String getCurrentStyle(Element elem, String name) {
+    name = hyphenize(name);
+    String propVal = getComputedStyle(elem, name, null);
+    if ("opacity".equals(name)) {
+      propVal = SelectorEngine.or(propVal, "1");
+    }
+    return propVal;
+  }
+
+  protected native String hyphenize(String name) /*-{
+      return name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
+  }-*/;
+
+  private native String getComputedStyle(Element elem, String name,
+      String pseudo) /*-{
+       var cStyle = $doc.defaultView.getComputedStyle( elem, pseudo );
+        return cStyle ? cStyle.getPropertyValue( name ) : null;
+  }-*/;
+}
diff --git a/gwtquery-core/src/main/java/gwtquery/client/impl/DocumentStyleImplIE.java b/gwtquery-core/src/main/java/gwtquery/client/impl/DocumentStyleImplIE.java
new file mode 100644 (file)
index 0000000..b9d95bc
--- /dev/null
@@ -0,0 +1,57 @@
+package gwtquery.client.impl;
+
+import com.google.gwt.dom.client.Element;
+
+import gwtquery.client.SelectorEngine;
+
+/**
+ *
+ */
+public class DocumentStyleImplIE extends DocumentStyleImpl {
+
+  public String getPropertyName(String name) {
+    if ("float".equals(name)) {
+      return "styleFloat";
+    } else if ("class".equals(name)) {
+      return "className";
+    } else if ("for".equals(name)) {
+      return "htmlFor";
+    }
+    return name;
+  }
+
+  public String getCurrentStyle(Element elem, String name) {
+    name = hyphenize(name);
+    String propVal = getComputedStyle(elem, name, null);
+    if ("opacity".equals(name)) {
+      propVal = SelectorEngine.or(propVal, "1");
+    }
+    return propVal;
+  }
+
+  // code lifted from jQuery
+  private native String getComputedStyle(Element elem, String name,
+      String pseudo) /*-{
+    var style = elem.style;
+    var camelCase = name.replace(/\-(\w)/g, function(all, letter){
+                               return letter.toUpperCase();
+                       });
+    var ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
+       // From the awesome hack by Dean Edwards
+        // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
+        // If we're not dealing with a regular pixel number
+       // but a number that has a weird ending, we need to convert it to pixels
+       if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
+               // Remember the original values
+               var left = style.left, rsLeft = elem.runtimeStyle.left;
+               // Put in the new values to get a computed value out
+               elem.runtimeStyle.left = elem.currentStyle.left;
+               style.left = ret || 0;
+               ret = style.pixelLeft + "px";
+                // Revert the changed values
+               style.left = left;
+               elem.runtimeStyle.left = rsLeft;
+    }  
+    return ret;
+  }-*/;
+}
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index c2fb795fd055c7d07ad07abc8183d95aa265eb8a..3ef7bbc1c937b65940b31519f05dadea336c9a5f 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
   <groupId>gwtquery</groupId>
   <artifactId>gwtquery-project</artifactId>
   <packaging>pom</packaging>
-  <version>0.31-SNAPSHOT</version>
+  <version>1.0-SNAPSHOT</version>
   <name>GwtQuery Project</name>
   <url>http://gwtquery.com</url>
   <description>GwtQuery is a jQuery clone written in GWT.</description>
       </activation>
 
       <properties>
-        <gwtversion>1.5.2</gwtversion>
+        <gwtversion>1.6.4</gwtversion>
         <!--           <maven.test.skip>true</maven.test.skip> -->
       </properties>
     </profile>
index ffab1e68bdafa24b7b0befa90734a673e6f17553..a5420be10bd00a4125b50503fef2a8a45143178e 100644 (file)
@@ -3,7 +3,7 @@
   <parent>
     <groupId>gwtquery</groupId>
     <artifactId>gwtquery-project</artifactId>
-    <version>0.31-SNAPSHOT</version>
+    <version>1.0-SNAPSHOT</version>
   </parent>
 
   <name>GwtQuery Samples</name>