summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2020-04-03 18:42:19 +1000
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2020-04-03 18:42:19 +1000
commit7547a6a45818bcfefd545da4697196b81bd8da5b (patch)
tree0f62eb9f98b81c6fe20536d5437c9acf39e08b01 /src
parent28e74482b8cc7b7f2e4aca099ceea9f7d7a888d5 (diff)
downloadsvg.js-7547a6a45818bcfefd545da4697196b81bd8da5b.tar.gz
svg.js-7547a6a45818bcfefd545da4697196b81bd8da5b.zip
- fixed `put()` which correctly creates an svgjs object from the passed element now before returning
- fixed `parent()` which correctly returns null if direct parent is the document or a document-fragment - fixed `add()` which correctly removes namespaces of non-root svg elements now when added to another svg element (#1086) - fixed `isRoot()` which correctly returns false, if the element is in a document-fragment
Diffstat (limited to 'src')
-rw-r--r--src/elements/Dom.js6
-rw-r--r--src/elements/Element.js7
-rw-r--r--src/elements/Svg.js55
3 files changed, 32 insertions, 36 deletions
diff --git a/src/elements/Dom.js b/src/elements/Dom.js
index 2e081a8..ef51ad6 100644
--- a/src/elements/Dom.js
+++ b/src/elements/Dom.js
@@ -30,6 +30,11 @@ export default class Dom extends EventTarget {
add (element, i) {
element = makeInstance(element)
+ // If non-root svg nodes are added we have to remove their namespaces
+ if (element.removeNamespaces && this.node instanceof globals.window.SVGElement) {
+ element.removeNamespaces()
+ }
+
if (i == null) {
this.node.appendChild(element.node)
} else if (element.node !== this.node.childNodes[i]) {
@@ -146,6 +151,7 @@ export default class Dom extends EventTarget {
// check for parent
if (!parent.node.parentNode) return null
+ if (parent.node.parentNode.nodeName === '#document' || parent.node.parentNode.nodeName === '#document-fragment') return null
// get parent element
parent = adopt(parent.node.parentNode)
diff --git a/src/elements/Element.js b/src/elements/Element.js
index 56dbcf3..d75db17 100644
--- a/src/elements/Element.js
+++ b/src/elements/Element.js
@@ -106,8 +106,13 @@ export default class Element extends Dom {
const parents = new List()
let parent = this
- while ((parent = parent.parent()) && parent.node !== globals.document) {
+ while (
+ (parent = parent.parent())
+ && parent.node !== globals.document
+ && parent.nodeName !== '#document-fragment') {
+
parents.push(parent)
+
if (parent.node === until.node) {
break
}
diff --git a/src/elements/Svg.js b/src/elements/Svg.js
index 7cec826..6672919 100644
--- a/src/elements/Svg.js
+++ b/src/elements/Svg.js
@@ -16,17 +16,19 @@ export default class Svg extends Container {
this.namespace()
}
- isRoot () {
- return !this.node.parentNode
- || !(this.node.parentNode instanceof globals.window.SVGElement)
- || this.node.parentNode.nodeName === '#document'
+ // Creates and returns defs element
+ defs () {
+ if (!this.isRoot()) return this.root().defs()
+
+ return adopt(this.node.querySelector('defs'))
+ || this.put(new Defs())
}
- // Check if this is a root svg
- // If not, call docs from this element
- root () {
- if (this.isRoot()) return this
- return super.root()
+ isRoot () {
+
+ return !this.node.parentNode
+ || (!(this.node.parentNode instanceof globals.window.SVGElement) && this.node.parentNode.nodeName !== '#document-fragment')
+ // || this.node.parentNode.nodeName === '#document'
}
// Add namespaces
@@ -38,36 +40,19 @@ export default class Svg extends Container {
.attr('xmlns:svgjs', svgjs, xmlns)
}
- // Creates and returns defs element
- defs () {
- if (!this.isRoot()) return this.root().defs()
-
- return adopt(this.node.querySelector('defs'))
- || this.put(new Defs())
+ removeNamespaces () {
+ return this.attr({ xmlns: null, version: null })
+ .attr('xmlns:xlink', null, xmlns)
+ .attr('xmlns:svgjs', null, xmlns)
}
- // custom parent method
- parent (type) {
- if (this.isRoot()) {
- return this.node.parentNode.nodeName === '#document'
- ? null
- : adopt(this.node.parentNode)
- }
-
- return super.parent(type)
+ // Check if this is a root svg
+ // If not, call root() from this element
+ root () {
+ if (this.isRoot()) return this
+ return super.root()
}
- clear () {
- // remove children
- while (this.node.hasChildNodes()) {
- this.node.removeChild(this.node.lastChild)
- }
-
- // remove defs reference
- delete this._defs
-
- return this
- }
}
registerMethods({