* filters at once.\r
*/\r
public GQuery filter(String... filters) {\r
-\r
JsNodeArray array = JsNodeArray.create();\r
-\r
for (String f : filters) {\r
for (Element e : elements) {\r
boolean ghostParent = false;\r
public GQuery gt(int pos) {\r
return $(slice(pos + 1, -1));\r
}\r
+ \r
+\r
+ /**\r
+ * Reduce the set of matched elements to those that have a descendant \r
+ * that matches the selector.\r
+ */\r
+ public GQuery has(final String selector) {\r
+ return filter(new Predicate(){\r
+ public boolean f(Element e, int index) {\r
+ return !$(selector, e).isEmpty();\r
+ }\r
+ });\r
+ }\r
+\r
+ /**\r
+ * Reduce the set of matched elements to those that have a descendant \r
+ * that matches the Element.\r
+ */\r
+ public GQuery has(final Element elem) {\r
+ return filter(new Predicate(){\r
+ public boolean f(Element e, int index) {\r
+ return engine.contains(e, elem);\r
+ }\r
+ });\r
+ }\r
\r
/**\r
* Returns true any of the specified classes are present on any of the matched\r
*/
LazyGQuery<T> gt(int pos);
+ /**
+ * Reduce the set of matched elements to those that have a descendant
+ * that matches the selector.
+ */
+ LazyGQuery<T> has(String selector);
+
+ /**
+ * Reduce the set of matched elements to those that have a descendant
+ * that matches the Element.
+ */
+ LazyGQuery<T> has(Element elem);
+
/**
* Returns true any of the specified classes are present on any of the matched
* elements.
}\r
}\r
\r
+ public native boolean contains(Element a, Element b) /*-{\r
+ return a.contains ? a != b && a.contains(b) : !!(a.compareDocumentPosition(b) & 16)\r
+ }-*/;\r
+ \r
public void setRoot(Node root) {\r
assert root != null;\r
this.root = root;\r
test.addClass("test");
test.removeClass("test");
}
+
+ public void testHas() {
+ $(e).html("<ul>"
+ +"<li>list item 1</li>"
+ +"<li id='l2'>list item 2"
+ +" <ul>"
+ +" <li>list item 2-a</li>"
+ +" <li>list item 2-b</li>"
+ +" </ul>"
+ +"</li>"
+ +"<li id='l3'>list item 3 <span>span</span>"
+ +"</li>"
+ +"<li>list item 4</li>"
+ +"</ul>");
+ assertEquals("", $("#l2").css("background-color"));
+ $("li", e).has("ul").css("background-color", "red");
+ assertEquals("red", $("#l2").css("background-color"));
+
+ Element span = $("span", e).get(0);
+ assertEquals("l3", $("li", e).has(span).id());
+ }
}