From be0e45c7fe64132f5155c8ae06431d768a4e7f0b Mon Sep 17 00:00:00 2001 From: Jean-Christophe Lariviere Date: Thu, 11 Dec 2014 16:37:06 -0500 Subject: Overload parentsUntil() to match a node --- .../java/com/google/gwt/query/client/GQuery.java | 22 ++++++++++++++++++++-- .../com/google/gwt/query/client/LazyGQuery.java | 7 ++++++- 2 files changed, 26 insertions(+), 3 deletions(-) (limited to 'gwtquery-core/src/main/java') 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 b82a2a3c..a589f3d5 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 @@ -3361,7 +3361,7 @@ public class GQuery implements Lazy { * for the root element). */ public GQuery parents() { - return parentsUntil(null); + return parentsUntil((String) null); } /** @@ -3376,7 +3376,6 @@ public class GQuery implements Lazy { /** * Get the ancestors of each element in the current set of matched elements, up to but not * including the element matched by the selector. - * */ public GQuery parentsUntil(String selector) { JsNodeArray result = JsNodeArray.create(); @@ -3393,6 +3392,25 @@ public class GQuery implements Lazy { return new GQuery(unique(result)).setPreviousObject(this); } + /** + * Get the ancestors of each element in the current set of matched elements, up to but not + * including the element matched by the selector. + */ + public GQuery parentsUntil(Node selector) { + JsNodeArray result = JsNodeArray.create(); + for (Element e : elements) { + Node par = e.getParentNode(); + while (par != null && par != document) { + if (selector != null && par == selector) { + break; + } + result.addNode(par); + par = par.getParentNode(); + } + } + return new GQuery(unique(result)).setPreviousObject(this); + } + /** * Gets the top and left position of an element relative to its offset parent. The returned object * contains two Integer properties, top and left. For accurate calculations make sure to use pixel diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java index 7a4ab3ad..46d9d9ee 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java @@ -1728,10 +1728,15 @@ public interface LazyGQuery extends LazyBase{ /** * Get the ancestors of each element in the current set of matched elements, up to but not * including the element matched by the selector. - * */ LazyGQuery parentsUntil(String selector); + /** + * Get the ancestors of each element in the current set of matched elements, up to but not + * including the element matched by the selector. + */ + LazyGQuery parentsUntil(Node selector); + /** * Gets the top and left position of an element relative to its offset parent. The returned object * contains two Integer properties, top and left. For accurate calculations make sure to use pixel -- cgit v1.2.3