aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Carrasco Moñino <manolo@apache.org>2015-07-20 10:59:16 +0200
committerManuel Carrasco Moñino <manolo@apache.org>2015-07-20 10:59:16 +0200
commit454b3ea3cad3b40b9e3f9f4d853bc101e80ec1e2 (patch)
tree5dcfa3e12e08458ea99e4945aa4d5204980ff78e
parentb1728c2e9d0de9aedd8e837cee87386b71cf1d24 (diff)
parenteeb63fc6b289e9b6c016b21a086fdc389973f34e (diff)
downloadgwtquery-454b3ea3cad3b40b9e3f9f4d853bc101e80ec1e2.tar.gz
gwtquery-454b3ea3cad3b40b9e3f9f4d853bc101e80ec1e2.zip
Merge pull request #349 from manolo/mcm_fix
Some fixes needed to run gquery with gwt-2.8.0-SNAPSHOT
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java122
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java68
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilderBase.java14
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java12
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsonBuilderGenerator.java15
-rw-r--r--gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryJsInteropTestGwt.java8
-rw-r--r--gwtquery-core/src/test/java/com/google/gwt/query/client/dbinding/DataBindingTestJre.java5
-rw-r--r--pom.xml10
8 files changed, 149 insertions, 105 deletions
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 47bee852..736f024a 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
@@ -208,59 +208,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Wrap a GQuery around an existing element.
- */
- public static GQuery $(Element element) {
- return new GQuery(element);
- }
-
- /**
- * Wrap a GQuery around an event's target element.
- */
- public static GQuery $(Event event) {
- return event == null ? $() : $((Element) event.getCurrentEventTarget().cast());
- }
-
- /**
- * Wrap a GQuery around the element of a Function callback.
- */
- public static GQuery $(Function f) {
- return $(f.getElement());
- }
-
- /**
- * Wrap a GQuery around an existing javascript element, event, node, nodelist, function or array.
- */
- public static GQuery $(JavaScriptObject jso) {
- if (jso == null) {
- return $();
- }
- // Execute a native javascript function like jquery does
- if (JsUtils.isFunction(jso)) {
- new JsUtils.JsFunction(jso).fe();
- return $();
- }
- // Wraps a native array like jquery does
- if (!JsUtils.isWindow(jso) && !JsUtils.isElement(jso) && JsUtils.isArray(jso)) {
- JsArrayMixed c = jso.cast();
- JsNodeArray elms = JsNodeArray.create();
- for (int i = 0; i < c.length(); i++) {
- Object obj = c.getObject(i);
- if (obj instanceof Node) {
- elms.addNode((Node) obj);
- }
- }
- return $(elms);
- }
-
- return JsUtils.isWindow(jso) ? $(jso.<Element> cast()) :
- JsUtils.isElement(jso) ? $(jso.<Element> cast()) :
- JsUtils.isEvent(jso) ? $(jso.<Event> cast()) :
- JsUtils.isNodeList(jso) ? $(jso.<NodeList<Element>> cast()) :
- $(jso.<Element> cast());
- }
-
- /**
* Wrap a GQuery around any object, supported objects are:
* String, GQuery, Function, Widget, JavaScriptObject.
*
@@ -269,7 +216,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* selector is supported in browsers with native xpath engine.
*
* In the case of a JavaScriptObject we handle:
- * Element, Event, Node, Nodelist and native functions or arrays.
+ * Element, Event, Node, Nodelist, Function, and native functions or arrays.
*
* If the case of a native function, we execute it and return empty.
*/
@@ -278,26 +225,52 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
if (o instanceof String) {
return $((String) o);
}
+ if (o instanceof SafeHtml) {
+ return $(((SafeHtml) o).asString());
+ }
if (o instanceof GQuery) {
return (GQuery) o;
}
if (o instanceof Function) {
- return $((Function) o);
- }
- if (JsUtils.isElement(o)) {
- return $(JsUtils.<Element> cast(o));
+ return new GQuery(((Function) o).getElement());
}
if (o instanceof JsonBuilder) {
return new GQuery(((JsonBuilder) o).<Element>getDataImpl());
}
- if (o instanceof JavaScriptObject) {
- return $((JavaScriptObject) o);
- }
if (o instanceof IsWidget) {
return $(Arrays.asList(o));
}
- console
- .log("Error: GQuery.$(Object o) could not wrap the type : ", o.getClass().getName(), o);
+ if (o instanceof JavaScriptObject) {
+ JavaScriptObject jso = (JavaScriptObject) o;
+ // Execute a native javascript function like jquery does
+ if (JsUtils.isFunction(jso)) {
+ new JsUtils.JsFunction(jso).fe();
+ return $();
+ }
+ // Wraps a native array like jquery does
+ if (!JsUtils.isWindow(jso) && !JsUtils.isElement(jso) && JsUtils.isArray(jso)) {
+ JsArrayMixed c = jso.cast();
+ JsNodeArray elms = JsNodeArray.create();
+ for (int i = 0; i < c.length(); i++) {
+ Object obj = c.getObject(i);
+ if (obj instanceof Node) {
+ elms.addNode((Node) obj);
+ }
+ }
+ return new GQuery(elms);
+ }
+ // Wraps a native NodeList
+ if (JsUtils.isNodeList(jso)) {
+ return new GQuery(jso.<NodeList<Element>> cast());
+ }
+ // Wraps an event
+ if (JsUtils.isEvent(jso)) {
+ jso = jso.<Event>cast().getCurrentEventTarget();
+ }
+ // Otherwise we wrap it as an element
+ return new GQuery(jso.<Element> cast());
+ }
+ throw new RuntimeException("Error: GQuery.$(Object o) could not wrap the type : " + o.getClass().getName() + " " + o);
}
return $();
}
@@ -321,20 +294,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * Wrap a GQuery around an existing node.
- */
- public static GQuery $(Node n) {
- return $((Element) n);
- }
-
- /**
- * Wrap a GQuery around existing Elements.
- */
- public static GQuery $(NodeList<Element> elms) {
- return new GQuery(elms);
- }
-
- /**
* 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. Xpath
* selector is supported in browsers with native xpath engine.
@@ -344,13 +303,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
- * This function accepts a SafeHtml creating a GQuery element containing those elements.
- */
- public static GQuery $(SafeHtml safeHtml) {
- return $(safeHtml.asString());
- }
-
- /**
* 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.
@@ -4984,7 +4936,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
* its structure -- it is that element that will enwrap everything else.
*/
public GQuery wrap(SafeHtml safeHtml) {
- return wrap(safeHtml.asString());
+ return wrap($(safeHtml));
}
/**
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java
index df766f9a..c9f43345 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java
@@ -25,6 +25,7 @@ import com.google.gwt.query.client.js.JsNamedArray;
import com.google.gwt.query.client.js.JsNodeArray;
import com.google.gwt.query.client.plugins.Effects;
import com.google.gwt.query.client.plugins.effects.PropertiesAnimation.Easing;
+import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.user.client.ui.Widget;
import java.util.List;
@@ -79,6 +80,12 @@ public interface LazyGQuery<T> extends LazyBase<T> {
LazyGQuery<T> after(String html);
/**
+ * Insert content after each of the matched elements. The elements must already be inserted into
+ * the document (you can't insert an element after another if it's not in the page).
+ */
+ LazyGQuery<T> after(SafeHtml safeHtml);
+
+ /**
*
* The animate() method allows you to create animation effects on any numeric HTML Attribute,
* CSS property, or color CSS property.
@@ -265,6 +272,12 @@ public interface LazyGQuery<T> extends LazyBase<T> {
LazyGQuery<T> append(String html);
/**
+ * Append content to the inside of every matched element. This operation is similar to doing an
+ * appendChild to all the specified elements, adding them into the document.
+ */
+ LazyGQuery<T> append(SafeHtml safeHtml);
+
+ /**
* All of the matched set of elements will be inserted at the end of the element(s) specified by
* the parameter other.
*
@@ -292,6 +305,15 @@ public interface LazyGQuery<T> extends LazyBase<T> {
LazyGQuery<T> appendTo(String html);
/**
+ * All of the matched set of elements will be inserted at the end of the element(s) specified by
+ * the parameter other.
+ *
+ * The operation $(A).appendTo(B) is, essentially, the reverse of doing a regular $(A).append(B),
+ * instead of appending B to A, you're appending A to B.
+ */
+ LazyGQuery<T> appendTo(SafeHtml safeHtml);
+
+ /**
* Convert to Plugin interface provided by Class literal.
*/
<T extends GQuery> T as(Class<T> plugin);
@@ -1123,6 +1145,11 @@ public interface LazyGQuery<T> extends LazyBase<T> {
LazyGQuery<T> html(String html);
/**
+ * Set the innerHTML of every matched element.
+ */
+ LazyGQuery<T> html(SafeHtml safeHtml);
+
+ /**
* Get the id of the first matched element.
*/
String id();
@@ -1941,6 +1968,16 @@ public interface LazyGQuery<T> extends LazyBase<T> {
LazyGQuery<T> queue(String queueName, Function... f);
/**
+ * Specify a function to execute when the DOM is fully loaded.
+ *
+ * While JavaScript provides the load event for executing code when a page is rendered, this event
+ * is not seen if we attach an event listener after the document has been loaded.
+ * This guarantees that our gwt code will be executed either it's executed synchronously before the
+ * DOM has been rendered (ie: single script linker in header) or asynchronously.
+ */
+ Promise ready(Function... fncs);
+
+ /**
* Removes all matched elements from the DOM.
*/
LazyGQuery<T> remove();
@@ -2490,6 +2527,15 @@ public interface LazyGQuery<T> extends LazyBase<T> {
LazyGQuery<T> wrap(String html);
/**
+ * Wrap each matched element with the specified SafeHtml content. This wrapping process is most useful
+ * for injecting additional structure into a document, without ruining the original semantic
+ * qualities of a document. This works by going through the first element provided (which is
+ * generated, on the fly, from the provided SafeHtml) and finds the deepest descendant element within
+ * its structure -- it is that element that will enwrap everything else.
+ */
+ LazyGQuery<T> wrap(SafeHtml safeHtml);
+
+ /**
* Wrap all the elements in the matched set into a single wrapper element. This is different from
* .wrap() where each element in the matched set would get wrapped with an element. This wrapping
* process is most useful for injecting additional structure into a document, without ruining the
@@ -2526,6 +2572,18 @@ public interface LazyGQuery<T> extends LazyBase<T> {
LazyGQuery<T> wrapAll(String html);
/**
+ * Wrap all the elements in the matched set into a single wrapper element. This is different from
+ * .wrap() where each element in the matched set would get wrapped with an element. This wrapping
+ * process is most useful for injecting additional structure into a document, without ruining the
+ * original semantic qualities of a document.
+ *
+ * This works by going through the first element provided (which is generated, on the fly, from
+ * the provided SafeHtml) and finds the deepest descendant element within its structure -- it is that
+ * element that will enwrap everything else.
+ */
+ LazyGQuery<T> wrapAll(SafeHtml safeHtml);
+
+ /**
* Wrap the inner child contents of each matched element (including text nodes) with an HTML
* structure. This wrapping process is most useful for injecting additional structure into a
* document, without ruining the original semantic qualities of a document. This works by going
@@ -2555,4 +2613,14 @@ public interface LazyGQuery<T> extends LazyBase<T> {
*/
LazyGQuery<T> wrapInner(String html);
+ /**
+ * Wrap the inner child contents of each matched element (including text nodes) with an SafeHtml
+ * structure. This wrapping process is most useful for injecting additional structure into a
+ * document, without ruining the original semantic qualities of a document. This works by going
+ * through the first element provided (which is generated, on the fly, from the provided SafeHtml) and
+ * finds the deepest ancestor element within its structure -- it is that element that will enwrap
+ * everything else.
+ */
+ LazyGQuery<T> wrapInner(SafeHtml safeHtml);
+
}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilderBase.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilderBase.java
index f0c46931..996f245c 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilderBase.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilderBase.java
@@ -17,6 +17,8 @@ package com.google.gwt.query.client.builders;
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.query.client.GQ;
import com.google.gwt.query.client.IsProperties;
import com.google.gwt.query.client.Properties;
import com.google.gwt.query.client.js.JsCache;
@@ -107,6 +109,18 @@ public abstract class JsonBuilderBase<J extends JsonBuilderBase<?>> implements J
return r;
}
+ protected final <T extends JsonBuilder> T[] getIsPropertiesArrayBase(JsArrayMixed js, T[] r, Class<T> clazz) {
+ JsObjectArray<?> a1 = js.cast();
+ for (int i = 0; i < r.length; i++) {
+ r[i] = getIsPropertiesBase(a1.get(i), clazz);
+ }
+ return r;
+ }
+
+ protected final <T extends JsonBuilder> T getIsPropertiesBase(Object o, Class<T> clazz) {
+ return GQ.create(clazz).load(o);
+ }
+
protected Properties getPropertiesBase(String n) {
if (p.getJavaScriptObject(n) == null) {
p.set(n, Properties.create());
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java
index 1012a8dc..a8e54995 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java
@@ -229,6 +229,14 @@ public class JsUtils {
}
/**
+ * Execute a native javascript function.
+ */
+ public static <T> T exec(JavaScriptObject jsFunction, Object... args) {
+ assert isFunction(jsFunction);
+ return jsni(jsFunction, "call", jsFunction, args);
+ }
+
+ /**
* Assign a function to a property of the window object.
*/
public static void export(String name, Function f) {
@@ -334,7 +342,7 @@ public class JsUtils {
* present.
*/
public static native boolean hasAttribute(Element o, String name) /*-{
- return !!(o && o.getAttribute(name));
+ return !!(o && o.getAttribute(name) !== null);
}-*/;
/**
@@ -410,7 +418,7 @@ public class JsUtils {
public static native boolean isNodeList(JavaScriptObject o) /*-{
var r = Object.prototype.toString.call(o);
return r == '[object HTMLCollection]' || r == '[object NodeList]'
- || (typeof o == 'object' && o.length && o[0].tagName) ? true : false;
+ || (typeof o == 'object' && o.length && o[0] && o[0].tagName) ? true : false;
}-*/;
/**
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsonBuilderGenerator.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsonBuilderGenerator.java
index 08e40c24..e30b7588 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsonBuilderGenerator.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsonBuilderGenerator.java
@@ -183,8 +183,7 @@ public class JsonBuilderGenerator extends Generator {
sw.println("return p.getStr(\"" + name + "\");");
} else if (isTypeAssignableTo(method.getReturnType(), jsonBuilderType)) {
String q = method.getReturnType().getQualifiedSourceName();
- sw.println("return " + "((" + q + ")GWT.create(" + q + ".class))"
- + ".load(getPropertiesBase(\"" + name + "\"));");
+ sw.println("return " + "getIsPropertiesBase(getPropertiesBase(\"" + name + "\")," + q + ".class);");
} else if (isTypeAssignableTo(method.getReturnType(), settingsType)) {
String q = method.getReturnType().getQualifiedSourceName();
sw.println("return " + "((" + q + ")getPropertiesBase(\"" + name + "\"));");
@@ -203,16 +202,7 @@ public class JsonBuilderGenerator extends Generator {
sw.println("int l = a == null ? 0 : a.length();");
String ret;
if (buildType) {
- sw.println(t + "[] r = new " + t + "[l];");
- sw.println("JsObjectArray<?> a1 = p.getArray(\"" + name
- + "\").cast();");
- sw.println("int l1 = r.length;");
- sw.println("for (int i = 0 ; i < l1 ; i++) {");
- sw.println(" Object w = a1.get(i);");
- sw.println(" " + t + " instance = GWT.create(" + t + ".class);");
- sw.println(" r[i] = instance.load(w);");
- sw.println("}");
- ret = "r";
+ ret = "getIsPropertiesArrayBase(a, new " + t + "[l], " + t + ".class)";
} else {
ret = "getArrayBase(\"" + name + "\", new " + t + "[l], " + t + ".class)";
}
@@ -326,6 +316,7 @@ public class JsonBuilderGenerator extends Generator {
types.add(t);
}
}
+ sw.println("GQuery.console.error(\"GQ.create: not registered class :\" + clz);");
sw.println("return null;");
sw.outdent();
sw.println("}");
diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryJsInteropTestGwt.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryJsInteropTestGwt.java
index 1a3ebf68..a01a9923 100644
--- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryJsInteropTestGwt.java
+++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryJsInteropTestGwt.java
@@ -58,23 +58,23 @@ public class GQueryJsInteropTestGwt extends GWTTestCase {
}
}
- @JsType(prototype = "Window", isNative = true)
+ @JsType(prototype = "Window")
public interface HTMLWindow {
@JsProperty String getName();
@JsProperty void setName(String name);
}
- @JsType(prototype = "Window", isNative = true)
+ @JsType(prototype = "Window")
public interface HWindow {
@JsProperty HDocument document();
}
- @JsType(prototype = "HTMLDocument", isNative = false)
+ @JsType(prototype = "HTMLDocument")
public interface HDocument {
HElement createElement(String tag);
}
- @JsType(prototype = "HTMLElement", isNative = false)
+ @JsType(prototype = "HTMLElement")
public interface HElement {
@JsProperty void id(String s);
}
diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/dbinding/DataBindingTestJre.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/dbinding/DataBindingTestJre.java
index f276f034..1767da99 100644
--- a/gwtquery-core/src/test/java/com/google/gwt/query/client/dbinding/DataBindingTestJre.java
+++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/dbinding/DataBindingTestJre.java
@@ -82,6 +82,8 @@ public class DataBindingTestJre extends GWTTestCase {
Boolean getZ();
String[] getT();
JsonExample setT(String[] strings);
+ Item[] getIt();
+ JsonExample setIt(Item[] items);
JsonExample setZ(Boolean b);
JsonExample setD(long l);
List<Item> getItems();
@@ -140,6 +142,9 @@ public class DataBindingTestJre extends GWTTestCase {
Item i2 = GQ.create(Item.class);
i2.setDate(new Date(3000));
Item[] items = new Item[]{i1, i2};
+ c.setIt(items);
+ assertEquals(2000l, c.getIt()[0].getDate().getTime());
+ assertEquals(3000l, c.getIt()[1].getDate().getTime());
c.setItems(Arrays.asList(items));
assertEquals(2000l, c.getItems().get(0).getDate().getTime());
assertEquals(3000l, c.getItems().get(1).getDate().getTime());
diff --git a/pom.xml b/pom.xml
index ae507dda..5b4cb5b2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -140,14 +140,20 @@
<releases><enabled>false</enabled></releases>
</repository>
<repository>
+ <id>google-snapshots</id>
+ <url>http://oss.sonatype.org/content/repositories/google-snapshots</url>
+ <snapshots><enabled>true</enabled></snapshots>
+ <releases><enabled>true</enabled></releases>
+ </repository>
+ <repository>
<id>gwtquery-plugins</id>
<url>http://gwtquery-plugins.googlecode.com/svn/mavenrepo</url>
</repository>
</repositories>
<properties>
- <gwtversion>2.7.0</gwtversion>
- <gwtmaven>2.7.0</gwtmaven>
+ <gwtversion>2.8.0-SNAPSHOT</gwtversion>
+ <gwtmaven>2.8.0-SNAPSHOT</gwtmaven>
<gqueryclassifier />
<gwt.loglevel>INFO</gwt.loglevel>
<gwt.outputstyle>OBF</gwt.outputstyle>