diff options
author | Manuel Carrasco Moñino <manolo@apache.org> | 2014-12-22 12:15:42 +0100 |
---|---|---|
committer | Manuel Carrasco Moñino <manolo@apache.org> | 2014-12-22 12:15:42 +0100 |
commit | 0cb9c0669152eb5d2a5301527a768bcb2e7097c6 (patch) | |
tree | 0c32dcefd735cb41c79c252cfe6f2e4253304ebc /gwtquery-core/src/main/java | |
parent | 9bcbe3908206233b10ccbd641716caab15c1be5c (diff) | |
parent | 8da271599c341f385ae4240f3dd37649aa81b082 (diff) | |
download | gwtquery-0cb9c0669152eb5d2a5301527a768bcb2e7097c6.tar.gz gwtquery-0cb9c0669152eb5d2a5301527a768bcb2e7097c6.zip |
Merge pull request #322 from manolo/mcm_custom_elements
Adding support for custom html elements.
Diffstat (limited to 'gwtquery-core/src/main/java')
-rw-r--r-- | gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java | 13 | ||||
-rw-r--r-- | gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java | 25 |
2 files changed, 26 insertions, 12 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 2953a7d2..098cb2da 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 @@ -282,17 +282,17 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { if (o instanceof Function) { return $((Function)o); } + if (JsUtils.isElement(o)) { + return $(JsUtils.<Element>cast(o)); + } if (o instanceof JavaScriptObject) { return $((JavaScriptObject)o); } if (o instanceof IsWidget) { return $(Arrays.asList(o)); } - if (!GWT.isProdMode()) { - System.err.println("GQuery.$(Object o) could not wrap the type : " + o.getClass()); - } + console.log("Error: GQuery.$(Object o) could not wrap the type : ", o.getClass().getName(), o); } - return $(); } @@ -704,7 +704,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { protected static String[] jsArrayToString(JsArrayString array) { if (GWT.isScript()) { - return jsArrayToString0(array); + return JsUtils.castArrayString(array); } else { String result[] = new String[array.length()]; for (int i = 0, l = result.length; i < l; i++) { @@ -714,9 +714,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { } } - private static native String[] jsArrayToString0(JsArrayString array) /*-{ - return array; - }-*/; /** * Return a lazy version of the GQuery interface. Lazy function calls are simply queued up and not 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 ac01f7ca..65f26cee 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 @@ -19,6 +19,7 @@ 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.Document; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Node; @@ -316,7 +317,7 @@ public class JsUtils { return Object.prototype.toString.call(o) == '[object Array]' || typeof o.length == 'number'; }-*/; - + /** * Check is a javascript object is a FormData */ @@ -349,9 +350,9 @@ public class JsUtils { /** * Check is a javascript object can be cast to an Element */ - public static boolean isElement(JavaScriptObject o) { - return hasProperty(o, "nodeType") && hasProperty(o, "nodeName"); - } + public static native boolean isElement(Object o) /*-{ + return o && o.nodeType && o.nodeName ? true : false; + }-*/; /** * Check is a javascript object can be cast to an Event @@ -451,6 +452,22 @@ public class JsUtils { } /** + * Utility method to cast objects in production. + * Useful for casting native implementations to interfaces like JsInterop + */ + public static native <T> T cast(Object o) /*-{ + return o; + }-*/; + + /** + * Utility method to cast objects to array of string in production. + */ + public static native String[] castArrayString(Object a)/*-{ + return a + }-*/; + + + /** * Call via jsni any arbitrary function present in a Javascript object. * * It's thought for avoiding to create jsni methods to call external functions and |