diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2020-04-05 20:51:35 +1000 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2020-04-05 20:51:35 +1000 |
commit | 099bf6efad9c9971d805c8496a63314d91a71692 (patch) | |
tree | 515abd93a158e69d2ebfed726797c3a0af9206d0 /src | |
parent | 8a6b109353d1e3ff24b996ffa3f412fb2f94de90 (diff) | |
download | svg.js-099bf6efad9c9971d805c8496a63314d91a71692.tar.gz svg.js-099bf6efad9c9971d805c8496a63314d91a71692.zip |
added second parameter to `addTo` and `putIn`. Added deep clone parameter to `clone`. Tests for Dom
Diffstat (limited to 'src')
-rw-r--r-- | src/elements/Dom.js | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/elements/Dom.js b/src/elements/Dom.js index c523687..0180c78 100644 --- a/src/elements/Dom.js +++ b/src/elements/Dom.js @@ -45,8 +45,8 @@ export default class Dom extends EventTarget { } // Add element to given container and return self - addTo (parent) { - return makeInstance(parent).put(this) + addTo (parent, i) { + return makeInstance(parent).put(this, i) } // Returns all child elements @@ -67,12 +67,12 @@ export default class Dom extends EventTarget { } // Clone element - clone () { + clone (deep = true) { // write dom data to the dom so the clone can pickup the data this.writeDataToDom() // clone element and assign new id - return assignNewId(this.node.cloneNode(true)) + return assignNewId(this.node.cloneNode(deep)) } // Iterates over all children and invokes a given block @@ -91,8 +91,8 @@ export default class Dom extends EventTarget { return this } - element (nodeName) { - return this.put(new Dom(create(nodeName))) + element (nodeName, attrs) { + return this.put(new Dom(create(nodeName), attrs)) } // Get first child @@ -125,7 +125,7 @@ export default class Dom extends EventTarget { this.node.id = eid(this.type) } - // dont't set directly width this.node.id to make `null` work correctly + // dont't set directly with this.node.id to make `null` work correctly return this.attr('id', id) } @@ -174,8 +174,8 @@ export default class Dom extends EventTarget { } // Add element to given container and return container - putIn (parent) { - return makeInstance(parent).add(this) + putIn (parent, i) { + return makeInstance(parent).add(this, i) } // Remove element @@ -213,11 +213,6 @@ export default class Dom extends EventTarget { return this } - // Return id on string conversion - toString () { - return this.id() - } - // Import raw svg svg (svgOrFn, outerHTML) { var well, len, fragment @@ -296,6 +291,11 @@ export default class Dom extends EventTarget { : this.add(fragment) } + // Return id on string conversion + toString () { + return this.id() + } + words (text) { // This is faster than removing all children and adding a new one this.node.textContent = text |