aboutsummaryrefslogtreecommitdiffstats
path: root/src/Parent.js
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-11-01 16:59:51 +0100
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-11-01 16:59:51 +0100
commitc40d7ffdfb95cb4db067463bb9259644aacbb876 (patch)
treee6f6c960c747dc90c2dea4b161f8a085894af67f /src/Parent.js
parentac84c9be8051567cfcb28ccd7ea2652524bb8a6f (diff)
downloadsvg.js-c40d7ffdfb95cb4db067463bb9259644aacbb876.tar.gz
svg.js-c40d7ffdfb95cb4db067463bb9259644aacbb876.zip
fix a few mistakes. Make sugar work. Roll back to childNodes because children is 10x slower
Diffstat (limited to 'src/Parent.js')
-rw-r--r--src/Parent.js14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/Parent.js b/src/Parent.js
index 1a1136f..ee8e3b0 100644
--- a/src/Parent.js
+++ b/src/Parent.js
@@ -13,8 +13,10 @@ export function children () {
export function add (element, i) {
element = makeInstance(element)
- if (element.node !== this.node.children[i]) {
- this.node.insertBefore(element.node, this.node.children[i] || null)
+ if (i == null) {
+ this.node.appendChild(element.node)
+ } else if (element.node !== this.node.childNodes[i]) {
+ this.node.insertBefore(element.node, this.node.childNodes[i])
}
return this
@@ -33,22 +35,22 @@ export function has (element) {
// Gets index of given element
export function index (element) {
- return [].slice.call(this.node.children).indexOf(element.node)
+ return [].slice.call(this.node.childNodes).indexOf(element.node)
}
// Get a element at the given index
export function get (i) {
- return adopt(this.node.children[i])
+ return adopt(this.node.childNodes[i])
}
// Get first child
export function first () {
- return this.get(0)
+ return adopt(this.node.firstChild)
}
// Get the last child
export function last () {
- return this.get(this.node.children.length - 1)
+ return adopt(this.node.lastChild)
}
// Iterates over all children and invokes a given block