diff options
author | Jean-Christophe Lariviere <jclariviere@arcbees.com> | 2014-12-11 16:37:06 -0500 |
---|---|---|
committer | Jean-Christophe Lariviere <jclariviere@arcbees.com> | 2014-12-11 16:37:06 -0500 |
commit | be0e45c7fe64132f5155c8ae06431d768a4e7f0b (patch) | |
tree | a2a590c737fc6267cc3ba13b0bc8e617417fec73 /gwtquery-core/src/main/java | |
parent | 09516bca8bb56a7393ad6cc4aa776ee275d298e1 (diff) | |
download | gwtquery-be0e45c7fe64132f5155c8ae06431d768a4e7f0b.tar.gz gwtquery-be0e45c7fe64132f5155c8ae06431d768a4e7f0b.zip |
Overload parentsUntil() to match a node
Diffstat (limited to 'gwtquery-core/src/main/java')
-rw-r--r-- | gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java | 22 | ||||
-rw-r--r-- | gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java | 7 |
2 files changed, 26 insertions, 3 deletions
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<GQuery, LazyGQuery> { * for the root element). */ public GQuery parents() { - return parentsUntil(null); + return parentsUntil((String) null); } /** @@ -3376,7 +3376,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { /** * 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(); @@ -3394,6 +3393,25 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { } /** + * 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 * values for margins, borders and padding. This method only works with visible elements. 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,11 +1728,16 @@ public interface LazyGQuery<T> extends LazyBase<T>{ /** * 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<T> 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<T> 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 * values for margins, borders and padding. This method only works with visible elements. |