summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2012-12-31 16:16:05 +0100
committerwout <wout@impinc.co.uk>2012-12-31 16:16:05 +0100
commit5e7c26e9423f3c543e04bc9a11656125ec7bf8ca (patch)
tree5e568b9a8083aa23b1bf830b7f4a42a3c8c1a1c0 /src
parent8dbe3599dd9b80738c4124f7e71bc12e763c50dc (diff)
downloadsvg.js-5e7c26e9423f3c543e04bc9a11656125ec7bf8ca.tar.gz
svg.js-5e7c26e9423f3c543e04bc9a11656125ec7bf8ca.zip
Added each(), next(), previous() and more
Diffstat (limited to 'src')
-rw-r--r--src/arrange.js14
-rw-r--r--src/container.js33
-rw-r--r--src/element.js10
-rw-r--r--src/group.js10
4 files changed, 63 insertions, 4 deletions
diff --git a/src/arrange.js b/src/arrange.js
index ff255be..ec06591 100644
--- a/src/arrange.js
+++ b/src/arrange.js
@@ -12,11 +12,19 @@ SVG.extend(SVG.Element, {
return this.siblings().indexOf(this);
},
+ // get the next element
+ next: function() {
+ return this.siblings()[this.position() + 1];
+ },
+
+ // get the next element
+ previous: function() {
+ return this.siblings()[this.position() - 1];
+ },
+
// send given element one step forwards
forward: function() {
- var i = this.siblings().indexOf(this);
-
- return this.parent.remove(this).put(this, i + 1);
+ return this.parent.remove(this).put(this, this.position() + 1);
},
// send given element one step backwards
diff --git a/src/container.js b/src/container.js
index 6482450..3656892 100644
--- a/src/container.js
+++ b/src/container.js
@@ -30,6 +30,19 @@ SVG.Container = {
return this._children || (this._children = []);
},
+ // iterates over all children
+ each: function(b) {
+ var i,
+ c = this.children();
+
+ // iteralte all shapes
+ for (i = 1, l = c.length; i < l; i++)
+ if (c[i] instanceof SVG.Shape)
+ b.apply(c[i], [i, c]);
+
+ return this;
+ },
+
// remove a given child element
remove: function(e) {
return this.removeAt(this.children().indexOf(e));
@@ -108,6 +121,26 @@ SVG.Container = {
return this.defs().gradient(t, b);
},
+ // get first child, skipping the defs node
+ first: function() {
+ return this.children()[1];
+ },
+
+ // let the last child
+ last: function() {
+ return this.children()[this.children().length - 1];
+ },
+
+ // clears all elements of this container
+ clear: function() {
+ this._children = [];
+
+ while (this.node.hasChildNodes())
+ this.node.removeChild(this.node.lastChild);
+
+ return this;
+ },
+
// hack for safari preventing text to be rendered in one line,
// basically it sets the position of the svg node to absolute
// when the dom is loaded, and resets it to relative a few ms later.
diff --git a/src/element.js b/src/element.js
index a9cd7cd..5db42b3 100644
--- a/src/element.js
+++ b/src/element.js
@@ -182,6 +182,16 @@ SVG.extend(SVG.Element, {
};
},
+ // is a given point inside the bounding box of the element
+ inside: function(x, y) {
+ var b = this.bbox();
+
+ return x > b.x &&
+ y > b.y &&
+ x < b.x + b.width &&
+ y < b.y + b.height;
+ },
+
// show element
show: function() {
this.node.style.display = '';
diff --git a/src/group.js b/src/group.js
index e3cb6a8..1007a32 100644
--- a/src/group.js
+++ b/src/group.js
@@ -7,4 +7,12 @@ SVG.G = function G() {
SVG.G.prototype = new SVG.Element();
// include the container object
-SVG.extend(SVG.G, SVG.Container); \ No newline at end of file
+SVG.extend(SVG.G, SVG.Container);
+
+SVG.extend(SVG.G, {
+
+ defs: function() {
+ return this.parentDoc().defs();
+ }
+
+}); \ No newline at end of file