diff options
author | wout <wout@impinc.co.uk> | 2012-12-31 16:16:05 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2012-12-31 16:16:05 +0100 |
commit | 5e7c26e9423f3c543e04bc9a11656125ec7bf8ca (patch) | |
tree | 5e568b9a8083aa23b1bf830b7f4a42a3c8c1a1c0 /dist/svg.js | |
parent | 8dbe3599dd9b80738c4124f7e71bc12e763c50dc (diff) | |
download | svg.js-5e7c26e9423f3c543e04bc9a11656125ec7bf8ca.tar.gz svg.js-5e7c26e9423f3c543e04bc9a11656125ec7bf8ca.zip |
Added each(), next(), previous() and more
Diffstat (limited to 'dist/svg.js')
-rw-r--r-- | dist/svg.js | 87 |
1 files changed, 77 insertions, 10 deletions
diff --git a/dist/svg.js b/dist/svg.js index 95464c6..288751f 100644 --- a/dist/svg.js +++ b/dist/svg.js @@ -1,4 +1,4 @@ -/* svg.js v0.1-50-g9f622f7 - svg container element event group arrange defs clip mask gradient doc shape rect ellipse poly path image text sugar - svgjs.com/license */ +/* svg.js v0.1-52-g8dbe359 - svg container element event group arrange defs clip mask gradient doc shape rect ellipse poly path image text sugar - svgjs.com/license */ (function() { this.SVG = { @@ -52,6 +52,19 @@ 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)); @@ -130,6 +143,26 @@ 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. @@ -196,6 +229,7 @@ var c, n = this.node.nodeName; + // invoke shape method with shape-specific arguments c = n == 'rect' ? this.parent[n](this.attrs.width, this.attrs.height) : n == 'ellipse' ? @@ -206,7 +240,11 @@ this.parent[n](this.content) : this.parent[n](); - return c.attr(this.attrs); + // copy translations + c.trans = this.trans; + + // apply attributes and translations + return c.attr(this.attrs).transform({}); }, // remove element @@ -330,6 +368,16 @@ }; }, + // 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 = ''; @@ -404,6 +452,14 @@ // include the container object SVG.extend(SVG.G, SVG.Container); + + SVG.extend(SVG.G, { + + defs: function() { + return this.parentDoc().defs(); + } + + }); SVG.extend(SVG.Element, { @@ -412,18 +468,31 @@ return this.parent.children(); }, + // get the curent position siblings + position: function() { + 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 backward: function() { var i, p = this.parent.level(); - i = this.siblings().indexOf(this); + i = this.position(); if (i > 1) p.remove(this).add(this, i - 1); @@ -438,11 +507,9 @@ // send given element all the way to the back back: function() { - var i, p = this.parent.level(); + var p = this.parent.level(); - i = this.siblings().indexOf(this); - - if (i > 1) + if (this.position() > 1) p.remove(this).add(this, 0); return this; |