diff options
author | wout <wout@impinc.co.uk> | 2012-12-31 14:33:53 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2012-12-31 14:33:53 +0100 |
commit | f210affa28f5ad2a92a12d8ca17c7ae6083b1d98 (patch) | |
tree | a14201741cfc920b9212995388f601bd5a6e5f3d /src | |
parent | 9f622f7b160fb977a4354eb0f775d4b53a2f7443 (diff) | |
download | svg.js-f210affa28f5ad2a92a12d8ca17c7ae6083b1d98.tar.gz svg.js-f210affa28f5ad2a92a12d8ca17c7ae6083b1d98.zip |
Added clone()
Diffstat (limited to 'src')
-rw-r--r-- | src/element.js | 20 | ||||
-rw-r--r-- | src/image.js | 3 |
2 files changed, 21 insertions, 2 deletions
diff --git a/src/element.js b/src/element.js index 6eea786..3f1afa3 100644 --- a/src/element.js +++ b/src/element.js @@ -27,7 +27,7 @@ SVG.extend(SVG.Element, { }, // set element size to given width and height - size: function(w, h) { + size: function(w, h) { return this.attr({ width: w, height: h }); }, @@ -38,6 +38,24 @@ SVG.extend(SVG.Element, { return this.move(x - b.width / 2, y - b.height / 2); }, + // clone element + clone: function() { + var c, + n = this.node.nodeName; + + c = n == 'rect' ? + this.parent[n](this.attrs.width, this.attrs.height) : + n == 'ellipse' ? + this.parent[n](this.attrs.rx * 2, this.attrs.ry * 2) : + n == 'image' ? + this.parent[n](this.src) : + n == 'text' ? + this.parent[n](this.content) : + this.parent[n](); + + return c.attr(this.attrs); + }, + // remove element remove: function() { return this.parent != null ? this.parent.remove(this) : void 0; diff --git a/src/image.js b/src/image.js index b6e16ef..8ae8ef3 100644 --- a/src/image.js +++ b/src/image.js @@ -11,7 +11,8 @@ SVG.extend(SVG.Image, { // (re)load image load: function(u) { - return this.attr('xlink:href', u, SVG.xlink); + this.src = u; + return (u ? this.attr('xlink:href', u, SVG.xlink) : this); } });
\ No newline at end of file |