Explorar el Código

Remove most of $ constructors in favour of $(Object) to avoid java8 disambiguation. Fixes issue 335

pull/336/head
Manolo Carrasco hace 9 años
padre
commit
d31880f147

+ 32
- 75
gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java Ver fichero

@@ -205,59 +205,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
return new GQuery(JsNodeArray.create());
}

/**
* 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.
@@ -267,7 +214,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.
*/
@@ -280,17 +227,41 @@ 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));
}
if (o instanceof JavaScriptObject) {
return $((JavaScriptObject) o);
return $(((Function) o).getElement());
}
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);
}
@@ -315,20 +286,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
return new GQuery(elms);
}

/**
* 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

+ 1
- 1
gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java Ver fichero

@@ -396,7 +396,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;
}-*/;

/**

Cargando…
Cancelar
Guardar