* Returns the owner document element of an element.
*/
public static Document getOwnerDocument(Node n) {
- return n == null ? null : n.getNodeType() == Node.DOCUMENT_NODE
+ return n == null || !isElement(n) ? null : n.getNodeType() == Node.DOCUMENT_NODE
? n.<Document> cast() : n.getOwnerDocument();
}
* Check is a javascript object can be cast to an Element
*/
public static boolean isElement(JavaScriptObject o) {
- return hasProperty(o, "nodeName");
+ return hasProperty(o, "nodeType") && hasProperty(o, "nodeName");
}
/**
/**
* Load an external javascript library. The inserted script replaces the
* element with the given id in the document.
- *
+ *
* @deprecated use {@link com.google.gwt.query.client.plugins.ajax.Ajax#loadScript(String)}
*/
@Deprecated
/**
* 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
* facilitate the writing of js wrappers.
- *
+ *
* Example
* <pre>
* // Create a svg node in our document.
* // Append it to the dom
* $(svg).appendTo(document);
* </pre>
- *
+ *
* @param o the javascript object where the function is.
* @param meth the literal name of the function to call.
* @param args an array with the arguments to pass to the function.
* Don't apply events on text and comment nodes !!
*/
private static boolean isEventCapable(Node n) {
- return JsUtils.isWindow(n) || n.getNodeType() != 3 && n.getNodeType() != 8;
+ return JsUtils.isWindow(n) || JsUtils.isElement(n) && n.getNodeType() != 3 && n.getNodeType() != 8;
}
public Events(GQuery gq) {