}\r
\r
private void allNextSiblingElements(Element firstChildElement,\r
- JsNodeArray result, Element elem, String untilSelector) {\r
- while (firstChildElement != null) {\r
+ JsNodeArray result, Element elem, GQuery until, String filterSelector) {\r
+ \r
+ while (firstChildElement != null) {\r
\r
- if (untilSelector != null && $(firstChildElement).is(untilSelector)){\r
+ if (until != null && until.index(firstChildElement) != -1){\r
return;\r
}\r
\r
- if (firstChildElement != elem) {\r
- result.addNode(firstChildElement);\r
+ if (firstChildElement != elem\r
+ && (filterSelector == null || $(firstChildElement).is(filterSelector))) {\r
+ result.addNode(firstChildElement);\r
}\r
firstChildElement = firstChildElement.getNextSiblingElement();\r
}\r
public GQuery children() {\r
JsNodeArray result = JsNodeArray.create();\r
for (Element e : elements) {\r
- allNextSiblingElements(e.getFirstChildElement(), result, null, null);\r
+ allNextSiblingElements(e.getFirstChildElement(), result, null, null, null);\r
}\r
return new GQuery(unique(result));\r
}\r
}\r
\r
/**\r
- * Find all sibling elements after the current element.\r
+ * Get all following siblings of each element in the set of matched\r
+ * elements.\r
*/\r
public GQuery nextAll() {\r
+ return nextAll(null);\r
+ }\r
+ \r
+ /**\r
+ * Get all following siblings of each element in the set of matched\r
+ * elements, filtered by a selector.\r
+ */\r
+ public GQuery nextAll(String filter) {\r
JsNodeArray result = JsNodeArray.create();\r
for (Element e : elements) {\r
- allNextSiblingElements(e.getNextSiblingElement(), result, null, null);\r
+ allNextSiblingElements(e.getNextSiblingElement(), result, null, null, filter);\r
}\r
return pushStack(unique(result), "nextAll", getSelector());\r
}\r
* @return\r
*/\r
public GQuery nextUntil(String selector) {\r
+ return nextUntil($(selector), null);\r
+ }\r
+ \r
+ /**\r
+ * Get all following siblings of each element up to but not including the\r
+ * element matched by the selector, filtered by a selector.\r
+ * \r
+ * @param selector\r
+ * @return\r
+ */\r
+ public GQuery nextUntil(String selector, String filter) {\r
+ return nextUntil($(selector), filter);\r
+ }\r
+\r
+ /**\r
+ * Get all following siblings of each element up to but not including the\r
+ * element matched by the DOM node.\r
+ * \r
+ * @param selector\r
+ * @return\r
+ */\r
+ public GQuery nextUntil(Element until) {\r
+ return nextUntil($(until), null);\r
+ }\r
+\r
+ \r
+ /**\r
+ * Get all following siblings of each element up to but not including the\r
+ * element matched by the DOM node, filtered by a selector.\r
+ * \r
+ * @param selector\r
+ * @return\r
+ */\r
+ public GQuery nextUntil(Element until, String filter) {\r
+ return nextUntil($(until), filter);\r
+ }\r
+ \r
+ \r
+ /**\r
+ * Get all following siblings of each element up to but not including the\r
+ * element matched by the GQuery object.\r
+ * \r
+ * @param selector\r
+ * @return\r
+ */\r
+ public GQuery nextUntil(GQuery until) {\r
+ return nextUntil(until, null);\r
+ }\r
+\r
+ \r
+ /**\r
+ * Get all following siblings of each element up to but not including the\r
+ * element matched by the GQuery object, filtered by a selector\r
+ * \r
+ * @param selector\r
+ * @return\r
+ */\r
+ public GQuery nextUntil(GQuery until, String filter) {\r
JsNodeArray result = JsNodeArray.create();\r
for (Element e : elements) {\r
- allNextSiblingElements(e.getNextSiblingElement(), result, null, selector);\r
+ allNextSiblingElements(e.getNextSiblingElement(), result, null, until, filter);\r
}\r
return pushStack(unique(result), "nextUntil", getSelector());\r
}\r
\r
+ \r
/**\r
* Removes the specified Element from the set of matched elements. This method\r
* is used to remove a single Element from a jQuery object.\r
JsNodeArray result = JsNodeArray.create();\r
for (Element e : elements) {\r
allNextSiblingElements(e.getParentElement().getFirstChildElement(),\r
- result, e, null);\r
+ result, e, null, null);\r
}\r
return new GQuery(unique(result));\r
}\r
assertHtmlEquals(expected, $("p", e).next(".selected").get(0).getString());
// nextAll()
- content = "<ul><li>i1</li><li>i2</li><li class='third-item'>i3</li><li>i4</li><li>i5</li></ul>";
- expected = "<li>i4</li><li>i5</li>";
+ content = "<ul><li>i1</li><li>i2</li><li class='third-item'>i3</li><li>i4</li><li class=\"last-item\">i5</li></ul>";
+ expected = "<li>i4</li><li class=\"last-item\">i5</li>";
$(e).html(content);
assertEquals(2, $("li.third-item", e).nextAll().size());
assertHtmlEquals(expected, $("li.third-item", e).nextAll());
+
+ expected = "<li class=\"last-item\">i5</li>";
+ assertEquals(1, $("li.third-item", e).nextAll(".last-item").size());
+ assertHtmlEquals(expected, $("li.third-item", e).nextAll(".last-item"));
// nextUntil()
- content = "<ul><li>i1</li><li>i2</li><li class='third-item'>i3</li><li>i4</li><li class='five-item'>i5</li></ul>";
+ content = "<ul><li class='first-item'>i1</li><li>i2</li><li class='third-item'>i3</li><li>i4</li><li class='five-item'>i5</li></ul>";
expected = "<li>i4</li>";
$(e).html(content);
assertEquals(1, $("li.third-item", e).nextUntil(".five-item").size());
assertHtmlEquals(expected, $("li.third-item", e).nextUntil(".five-item"));
+
+ GQuery nextUntil = $("li.five-item");
+ assertEquals(1, $("li.third-item", e).nextUntil(nextUntil).size());
+ assertHtmlEquals(expected, $("li.third-item", e).nextUntil(nextUntil));
+
+ Element nextUntilElement = nextUntil.get(0);
+ assertEquals(1, $("li.third-item", e).nextUntil(nextUntilElement).size());
+ assertHtmlEquals(expected, $("li.third-item", e).nextUntil(nextUntilElement));
+
+
+ expected = "<li class='third-item'>i3</li>";
+ $(e).html(content);
+ assertEquals(1, $("li.first-item", e).nextUntil(".five-item", "li.third-item").size());
+ assertHtmlEquals(expected, $("li.first-item", e).nextUntil(".five-item", "li.third-item"));
+
+ assertEquals(1, $("li.first-item", e).nextUntil(nextUntil, "li.third-item").size());
+ assertHtmlEquals(expected, $("li.first-item", e).nextUntil(nextUntil, "li.third-item"));
+
+ assertEquals(1, $("li.first-item", e).nextUntil(nextUntilElement, "li.third-item").size());
+ assertHtmlEquals(expected, $("li.first-item", e).nextUntil(nextUntilElement, "li.third-item"));
+
+
// andSelf()