aboutsummaryrefslogtreecommitdiffstats
path: root/src/parent.js
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2017-07-25 09:14:48 +0200
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2017-07-25 09:14:48 +0200
commitd6d389133409b315bc1b74752f58ef2647033bb9 (patch)
treec64c68abeef515ed1dc20a402d304b4609d8767e /src/parent.js
parentbc9bfb6025e826b0ee6c827f1a356995d7f05d4c (diff)
downloadsvg.js-d6d389133409b315bc1b74752f58ef2647033bb9.tar.gz
svg.js-d6d389133409b315bc1b74752f58ef2647033bb9.zip
Lots of breaking changes. Read below! (#646, #716)
- added `SVG.HTMLNode` which is the object wrapped around html nodes to put something in them - moved `defs()` method from `SVG.Parent` to `SVG.Element` - `SVG()` can be called with css selector, node or svg string, now. Without an argument it creates a new `SVG.Doc()` (#646) - `add()`, `put()`, `addTo()`, `putIn()` now excepts all arguments accepted by `SVG()` - `SVG.Nested` is not `overflow:visible` by default - all `SVG.*` objects now can have a node as parameter when constructing - `SVG()` does not set a default size anymore
Diffstat (limited to 'src/parent.js')
-rw-r--r--src/parent.js18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/parent.js b/src/parent.js
index 67d2d73..372c2ca 100644
--- a/src/parent.js
+++ b/src/parent.js
@@ -17,6 +17,8 @@ SVG.Parent = SVG.invent({
}
// Add given element at a position
, add: function(element, i) {
+ element = createElement(element)
+
if (i == null)
this.node.appendChild(element.node)
else if (element.node != this.node.children[i])
@@ -27,7 +29,7 @@ SVG.Parent = SVG.invent({
// Basically does the same as `add()` but returns the added element instead
, put: function(element, i) {
this.add(element, i)
- return element
+ return element.instance || element
}
// Checks if the given element is a child
, has: function(element) {
@@ -53,7 +55,7 @@ SVG.Parent = SVG.invent({
, each: function(block, deep) {
var i, il
, children = this.children()
-
+
for (i = 0, il = children.length; i < il; i++) {
if (children[i] instanceof SVG.Element)
block.apply(children[i], [i, children])
@@ -61,13 +63,13 @@ SVG.Parent = SVG.invent({
if (deep && (children[i] instanceof SVG.Parent))
children[i].each(block, deep)
}
-
+
return this
}
// Remove a given child
, removeElement: function(element) {
this.node.removeChild(element.node)
-
+
return this
}
// Remove all elements in this container
@@ -75,16 +77,12 @@ SVG.Parent = SVG.invent({
// remove children
while(this.node.hasChildNodes())
this.node.removeChild(this.node.lastChild)
-
+
// remove defs reference
delete this._defs
return this
}
- , // Get defs
- defs: function() {
- return this.doc().defs()
- }
}
-
+
})