From 6fcb9d79430778590f178f6e715c86f2cae5391e Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Wed, 19 Oct 2011 16:55:20 +0000 Subject: Remove GQ class --- .../main/java/com/google/gwt/query/client/GQ.java | 112 -------------- .../java/com/google/gwt/query/client/GQuery.java | 165 +++++++++++++++++---- 2 files changed, 137 insertions(+), 140 deletions(-) delete mode 100644 gwtquery-core/src/main/java/com/google/gwt/query/client/GQ.java (limited to 'gwtquery-core') diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQ.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQ.java deleted file mode 100644 index 9df57c2d..00000000 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQ.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.google.gwt.query.client; - -import java.util.ArrayList; -import java.util.List; - -import com.google.gwt.core.client.JsArrayMixed; -import com.google.gwt.dom.client.Element; -import com.google.gwt.query.client.plugins.ajax.Ajax; -import com.google.gwt.query.client.plugins.ajax.Ajax.Settings; - -/** - * Class to implement the GQuery API static methods. - * - * NOTE: This class should be named $ but gwtc does not support the Dollar char - * in class names. If gwtc fixed this someday, this class would be renamed to $ - * but we would maintain a copy of this in order not to break apps. - * - * This class is abstract because is thought to contain only static methods and - * it extends GQuery so as static methods and attributes defined in GQuery are - * available here when statically importing this class. - * - * Code example: - *
-  GQ.$("div").css("background", "red");
- * 
- *
-  import static com.google.gwt.query.client.GQ.*;
-  ...
-  $("div").css("background", "red");
- * 
- * - */ -public abstract class GQ extends GQuery { - - /** - * Non instantiable class. - * - * TODO: move all public static GQuery methods here. - */ - private GQ(GQuery gq) { - super(gq); - } - - public static void ajax(Properties p) { - ajax(p); - } - - public static void ajax(String url, Settings settings) { - Ajax.ajax(url, settings); - } - - public GQuery load(String url, Properties data, final Function onSuccess) { - return as(Ajax.Ajax).load(url, data, onSuccess); - } - - public GQuery load(String url) { - return as(Ajax.Ajax).load(url, null, null); - } - - public static void get(String url, Properties data, final Function onSuccess) { - Ajax.get(url, data, onSuccess); - } - - public static void post(String url, Properties data, final Function onSuccess) { - Ajax.post(url, data, onSuccess); - } - - public static void getJSON(String url, Properties data, final Function onSuccess) { - Ajax.getJSON(url, data, onSuccess); - } - - public static boolean contains(Element a, Element b) { - return engine.contains(a, b); - } - - public static Object data(Element e, String key) { - return GQuery.data(e, key, null); - } - - public static Object data(Element e, String key, String value) { - return GQuery.data(e, key, value); - } - - public static void each(List objects, Function f) { - for (int i = 0, l = objects.size(); i < l; i++) { - f.f(i, objects.get(i)); - } - } - - public static void each(T[] objects, Function f) { - for (int i = 0, l = objects.length; i < l; i++) { - f.f(i, objects[i]); - } - } - - public static void each(JsArrayMixed objects, Function f) { - for (int i = 0, l = objects.length(); i < l; i++) { - f.f(i, objects.getObject(i)); - } - } - - @SuppressWarnings("unchecked") - public static T[] grep(T[] objects, Predicate f) { - ArrayList ret = new ArrayList(); - for (int i = 0, l = objects.length; i < l; i++) { - if (f.f(objects[i], i)) { - ret.add(objects[i]); - } - } - return (T[]) ret.toArray(new Object[0]); - } -} 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 199869ce..b7937ba8 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 @@ -22,6 +22,7 @@ import java.util.List; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.JsArray; +import com.google.gwt.core.client.JsArrayMixed; import com.google.gwt.core.client.JsArrayString; import com.google.gwt.dom.client.BodyElement; import com.google.gwt.dom.client.ButtonElement; @@ -52,6 +53,7 @@ import com.google.gwt.query.client.plugins.Events; import com.google.gwt.query.client.plugins.Plugin; import com.google.gwt.query.client.plugins.Widgets; import com.google.gwt.query.client.plugins.ajax.Ajax; +import com.google.gwt.query.client.plugins.ajax.Ajax.Settings; import com.google.gwt.query.client.plugins.effects.PropertiesAnimation.Easing; import com.google.gwt.query.client.plugins.events.EventsListener; import com.google.gwt.user.client.DOM; @@ -215,7 +217,7 @@ public class GQuery implements Lazy { JsUtils.isNodeList(e) ? GQuery.$(e.>cast()) : $(); } - + /** * Create a new GQuery given a list of nodes, elements or widgets */ @@ -288,8 +290,8 @@ public class GQuery implements Lazy { } return new GQuery().select(selectorOrHtml, ctx); } - - /** + + /** * 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 @@ -312,7 +314,7 @@ public class GQuery implements Lazy { } } - /** + /** * 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 @@ -338,7 +340,7 @@ public class GQuery implements Lazy { return $(selector, context.getElement(), plugin); } - /** + /** * wraps a GQuery or a plugin object */ public static T $(T gq) { @@ -359,6 +361,27 @@ public class GQuery implements Lazy { return Properties.create(properties); } + /** + * Perform an ajax request to the server. + */ + public static void ajax(Properties p) { + ajax(p); + } + + /** + * Perform an ajax request to the server. + */ + public static void ajax(Settings settings) { + Ajax.ajax(settings); + } + + /** + * Perform an ajax request to the server. + */ + public static void ajax(String url, Settings settings) { + Ajax.ajax(url, settings); + } + @SuppressWarnings("unchecked") protected static GQuery cleanHtmlString(String elem, Document doc) { @@ -391,6 +414,20 @@ public class GQuery implements Lazy { return $((NodeList) n.getChildNodes().cast()); } + /** + * Return true if the element b is contained in a. + */ + public static boolean contains(Element a, Element b) { + return engine.contains(a, b); + } + + /** + * Get the element data matching the key. + */ + public static Object data(Element e, String key) { + return GQuery.data(e, key, null); + } + protected static Object data(Element item, String name, S value) { if (dataCache == null) { windowData = JavaScriptObject.createObject().cast(); @@ -412,26 +449,53 @@ public class GQuery implements Lazy { return name != null ? d.get(name) : id; } - protected static DocumentStyleImpl getStyleImpl(){ - if (styleImpl == null){ - styleImpl = GWT.create(DocumentStyleImpl.class); - } - return styleImpl; - } - - private static AttributeImpl getAttributeImpl(){ - if (attributeImpl == null){ - attributeImpl = GWT.create(AttributeImpl.class); - } - return attributeImpl; - } - + /** + * Set element data. + */ + public static Object data(Element e, String key, String value) { + return GQuery.data(e, key, value); + } + + /** + * Execute a function around each object + */ + public static void each(JsArrayMixed objects, Function f) { + for (int i = 0, l = objects.length(); i < l; i++) { + f.f(i, objects.getObject(i)); + } + } + + /** + * Execute a function around each object + */ + public static void each(List objects, Function f) { + for (int i = 0, l = objects.size(); i < l; i++) { + f.f(i, objects.get(i)); + } + } + + /** + * Execute a function around each object + */ + public static void each(T[] objects, Function f) { + for (int i = 0, l = objects.length; i < l; i++) { + f.f(i, objects[i]); + } + } + private static native void emptyDocument(Document d) /*-{ d.open(); d.write(""); d.close(); }-*/; + /** + * Perform an ajax request to the server using GET. + */ + public static void get(String url, Properties data, final Function onSuccess) { + Ajax.get(url, data, onSuccess); + } + /** * We will use the fact as GWT use the widget itself as EventListener ! If no * Widget associated with the element, this method returns null. @@ -456,21 +520,54 @@ public class GQuery implements Lazy { return null; } + private static AttributeImpl getAttributeImpl(){ + if (attributeImpl == null){ + attributeImpl = GWT.create(AttributeImpl.class); + } + return attributeImpl; + } + private native static Document getContentDocument(Node n) /*-{ var d = n.contentDocument || n.document || n.contentWindow.document; if (!d.body) @com.google.gwt.query.client.GQuery::emptyDocument(Lcom/google/gwt/dom/client/Document;)(d); return d; }-*/; + + /** + * Perform an ajax request to the server using POST and + * parsing the json response. + */ + public static void getJSON(String url, Properties data, + final Function onSuccess) { + Ajax.getJSON(url, data, onSuccess); + } + + protected static DocumentStyleImpl getStyleImpl(){ + if (styleImpl == null){ + styleImpl = GWT.create(DocumentStyleImpl.class); + } + return styleImpl; + } + + /** + * Return only the set of objects with match the predicate. + */ + @SuppressWarnings("unchecked") + public static T[] grep(T[] objects, Predicate f) { + ArrayList ret = new ArrayList(); + for (int i = 0, l = objects.length; i < l; i++) { + if (f.f(objects[i], i)) { + ret.add(objects[i]); + } + } + return (T[]) ret.toArray(new Object[0]); + } private static boolean hasClass(Element e, String clz) { return e.getClassName().matches("(^|.*\\s)" + clz + "(\\s.*|$)"); } - private static GQuery innerHtml(String html, Document doc) { - return $(cleanHtmlString(html, doc)); - } - private static void initWrapperMap(){ TagWrapper tableWrapper = new TagWrapper(1, "", "
"); @@ -493,6 +590,10 @@ public class GQuery implements Lazy { wrapperMap.put("area", new TagWrapper(1, "", "")); } + + private static GQuery innerHtml(String html, Document doc) { + return $(cleanHtmlString(html, doc)); + } protected static String[] jsArrayToString(JsArrayString array) { if (GWT.isScript()) { @@ -505,7 +606,7 @@ public class GQuery implements Lazy { return result; } } - + private static native String[] jsArrayToString0(JsArrayString array) /*-{ return array; }-*/; @@ -518,6 +619,14 @@ public class GQuery implements Lazy { return $().createLazy(); } + /** + * Perform an ajax request to the server using POST. + */ + public static void post(String url, Properties data, + final Function onSuccess) { + Ajax.post(url, data, onSuccess); + } + public static Class registerPlugin(Class plugin, Plugin pluginFactory) { if (plugins == null) { @@ -2589,8 +2698,8 @@ public class GQuery implements Lazy { * determines the content to be loaded. * */ - public GQuery load(String url, Properties data, final Function onSuccess) { - return as(Ajax.Ajax).load(url, data, onSuccess); + public GQuery load(String url) { + return load(url, null, null); } /** @@ -2603,8 +2712,8 @@ public class GQuery implements Lazy { * determines the content to be loaded. * */ - public GQuery load(String url) { - return load(url, null, null); + public GQuery load(String url, Properties data, final Function onSuccess) { + return as(Ajax.Ajax).load(url, data, onSuccess); } /** -- cgit v1.2.3