diff options
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 |