diff options
author | Morgan Harris <gormster@me.com> | 2021-11-23 13:12:44 +1100 |
---|---|---|
committer | Morgan Harris <gormster@me.com> | 2021-11-23 13:12:44 +1100 |
commit | e0be375fc57930306999f15c7a7266edb0ba3432 (patch) | |
tree | f18fb403ea0e374c44fe565f1521978dd6178af6 /src/elements/Element.js | |
parent | 180b292968f7b1491757ea9195cb12bf6c12bba9 (diff) | |
download | svg.js-e0be375fc57930306999f15c7a7266edb0ba3432.tar.gz svg.js-e0be375fc57930306999f15c7a7266edb0ba3432.zip |
Return null if `until` not in parent chain
Diffstat (limited to 'src/elements/Element.js')
-rw-r--r-- | src/elements/Element.js | 15 |
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 |