aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManolo Carrasco <manolo@apache.org>2015-01-13 08:14:49 +0100
committerManolo Carrasco <manolo@apache.org>2015-02-25 16:36:36 +0100
commit3174d5ba98027c8d106d252747f5c1e1205f8fe2 (patch)
tree4a0b7ae54bcb85ada9f6ef89a7a9419226eb04ca
parent525c70c19c62b8b0b0a9e67ca464dc09c580f3d2 (diff)
downloadgwtquery-3174d5ba98027c8d106d252747f5c1e1205f8fe2.tar.gz
gwtquery-3174d5ba98027c8d106d252747f5c1e1205f8fe2.zip
Remove most of $ constructors in favour of $(Object) to avoid java8 disambiguation. Fixes issue 335
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java107
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java2
2 files changed, 33 insertions, 76 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 92641bf8..367d956a 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
@@ -207,59 +207,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.
*
@@ -268,7 +215,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.
*/
@@ -281,20 +228,44 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
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));
}
+ 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());
+ }
console
.log("Error: GQuery.$(Object o) could not wrap the type : ", o.getClass().getName(), o);
}
@@ -320,20 +291,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.
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..e4acf8ee 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
@@ -410,7 +410,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;
}-*/;
/**