aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMorgan Harris <gormster@me.com>2021-11-23 13:12:44 +1100
committerMorgan Harris <gormster@me.com>2021-11-23 13:12:44 +1100
commite0be375fc57930306999f15c7a7266edb0ba3432 (patch)
treef18fb403ea0e374c44fe565f1521978dd6178af6 /src
parent180b292968f7b1491757ea9195cb12bf6c12bba9 (diff)
downloadsvg.js-e0be375fc57930306999f15c7a7266edb0ba3432.tar.gz
svg.js-e0be375fc57930306999f15c7a7266edb0ba3432.zip
Return null if `until` not in parent chain
Diffstat (limited to 'src')
-rw-r--r--src/elements/Element.js15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/elements/Element.js b/src/elements/Element.js
index a1e7236..2aaeab5 100644
--- a/src/elements/Element.js
+++ b/src/elements/Element.js
@@ -87,11 +87,8 @@ export default class Element extends Dom {
// return array of all ancestors of given type up to the root svg
parents (until = this.root()) {
- let selector = null
- if (typeof until === 'string') {
- selector = until
- until = this.root()
- } else {
+ const isSelector = typeof until === 'string'
+ if (!isSelector) {
until = makeInstance(until)
}
const parents = new List()
@@ -104,12 +101,16 @@ export default class Element extends Dom {
parents.push(parent)
- if (parent.node === until.node) {
+ if (!isSelector && (parent.node === until.node)) {
break
}
- if (selector && parent.matches(selector)) {
+ if (isSelector && parent.matches(until)) {
break
}
+ if (parent.node === this.root().node) {
+ // We worked our way to the root and didn't match `until`
+ return null
+ }
}
return parents