diff options
author | wout <wout@impinc.co.uk> | 2013-06-09 11:37:26 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2013-06-09 11:37:26 +0100 |
commit | 8f03d84e43681ecca20ac028071e51a2e2bbc0c8 (patch) | |
tree | f5c11dc6c429e8459c20731ba775fa6ca794400f /src/container.js | |
parent | ec75128ec31aa055aca2ae7f95ad4f5cf38d12e0 (diff) | |
download | svg.js-8f03d84e43681ecca20ac028071e51a2e2bbc0c8.tar.gz svg.js-8f03d84e43681ecca20ac028071e51a2e2bbc0c8.zip |
Added deep traversing, reorganizd modules
Diffstat (limited to 'src/container.js')
-rw-r--r-- | src/container.js | 79 |
1 files changed, 11 insertions, 68 deletions
diff --git a/src/container.js b/src/container.js index 46ebdb1..dbf2205 100644 --- a/src/container.js +++ b/src/container.js @@ -41,13 +41,17 @@ SVG.extend(SVG.Container, { return this.children().indexOf(element) >= 0 } // Iterates over all children and invokes a given block -, each: function(block) { - var index, - children = this.children() - - for (index = 0, length = children.length; index < length; index++) - if (children[index] instanceof SVG.Shape) - block.apply(children[index], [index, children]) +, each: function(block, deep) { + var i, il + , children = this.children() + + for (i = 0, il = children.length; i < il; i++) { + if (children[i] instanceof SVG.Shape) + block.apply(children[i], [i, children]) + + if (deep && (children[i] instanceof SVG.Container)) + children[i].each(block, deep) + } return this } @@ -69,67 +73,6 @@ SVG.extend(SVG.Container, { , level: function() { return this.removeElement(this.defs()).put(this.defs(), 0) } - // Create a group element -, group: function() { - return this.put(new SVG.G) - } - // Create a rect element -, rect: function(width, height) { - return this.put(new SVG.Rect().size(width, height)) - } - // Create circle element, based on ellipse -, circle: function(size) { - return this.ellipse(size, size) - } - // Create an ellipse -, ellipse: function(width, height) { - return this.put(new SVG.Ellipse().size(width, height).move(0, 0)) - } - // Create a line element -, line: function(x1, y1, x2, y2) { - return this.put(new SVG.Line().plot(x1, y1, x2, y2)) - } - // Create a wrapped polyline element -, polyline: function(points, unbiased) { - return this.put(new SVG.Polyline(unbiased)).plot(points) - } - // Create a wrapped polygon element -, polygon: function(points, unbiased) { - return this.put(new SVG.Polygon(unbiased)).plot(points) - } - // Create a wrapped path element -, path: function(data, unbiased) { - return this.put(new SVG.Path(unbiased)).plot(data) - } - // Create image element, load image and set its size -, image: function(source, width, height) { - width = width != null ? width : 100 - return this.put(new SVG.Image().load(source).size(width, height != null ? height : width)) - } - // Create text element -, text: function(text) { - return this.put(new SVG.Text().text(text)) - } - // Create nested svg document -, nested: function() { - return this.put(new SVG.Nested) - } - // Create gradient element in defs -, gradient: function(type, block) { - return this.defs().gradient(type, block) - } - // Create pattern element in defs -, pattern: function(width, height, block) { - return this.defs().pattern(width, height, block) - } - // Create masking element -, mask: function() { - return this.defs().put(new SVG.Mask) - } - // Create clipping element -, clip: function() { - return this.defs().put(new SVG.Clip) - } // Get first child, skipping the defs node , first: function() { return this.children()[0] instanceof SVG.Defs ? this.children()[1] : this.children()[0] |