diff options
author | wout <wout@impinc.co.uk> | 2014-09-02 14:47:02 +0200 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-09-02 14:47:02 +0200 |
commit | 826649995f1aae806fb9bf8464a4259c4290c4fb (patch) | |
tree | 9f4fb1585990bec8e1b90963c5932944561f454b /src | |
parent | 5aa85e605368e4e30c4fcb62abb0031543a7d633 (diff) | |
download | svg.js-826649995f1aae806fb9bf8464a4259c4290c4fb.tar.gz svg.js-826649995f1aae806fb9bf8464a4259c4290c4fb.zip |
Fixed bug in clone() method
Diffstat (limited to 'src')
-rwxr-xr-x | src/element.js | 24 | ||||
-rwxr-xr-x | src/fx.js | 5 | ||||
-rwxr-xr-x | src/image.js | 12 | ||||
-rw-r--r-- | src/matrix.js | 6 |
4 files changed, 29 insertions, 18 deletions
diff --git a/src/element.js b/src/element.js index 8db2359..d64872a 100755 --- a/src/element.js +++ b/src/element.js @@ -67,7 +67,13 @@ SVG.Element = SVG.invent({ } // Clone element , clone: function() { - return assignNewId(this.node.cloneNode(true)) + // clone element and assign new id + var clone = assignNewId(this.node.cloneNode(true)) + + // insert the clone after myself + this.after(clone) + + return clone } // Remove element , remove: function() { @@ -159,15 +165,17 @@ SVG.Element = SVG.invent({ } // Returns the parent element instance , parent: function(type) { - // Get parent element - var parent = SVG.adopt(this.node.parentNode) + if (this.node.parentNode) { + // get parent element + var parent = SVG.adopt(this.node.parentNode) - // If a specific type is given, find a parent with that class - if (type) - while (!(parent instanceof type)) - parent = SVG.adopt(parent.node.parentNode) + // if a specific type is given, find a parent with that class + if (type) + while (!(parent instanceof type) && parent.node.parentNode instanceof SVGElement) + parent = SVG.adopt(parent.node.parentNode) - return parent + return parent + } } // Get parent document , doc: function(type) { @@ -237,9 +237,8 @@ SVG.FX = SVG.invent({ // add param this.attrs[a].param = { - from: this.target.param || { rotation: v, cx: this.param.cx, cy: this.param.cy } - , to: this.param - , initial: v + from: this.target.param || { rotation: v, cx: this.param.cx, cy: this.param.cy } + , to: this.param } } diff --git a/src/image.js b/src/image.js index 33f3979..ed44752 100755 --- a/src/image.js +++ b/src/image.js @@ -14,19 +14,19 @@ SVG.Image = SVG.invent({ var self = this , img = document.createElement('img') - /* preload image */ + // preload image img.onload = function() { var p = self.doc(SVG.Pattern) - /* ensure image size */ + // ensure image size if (self.width() == 0 && self.height() == 0) self.size(img.width, img.height) - /* ensure pattern size if not set */ + // ensure pattern size if not set if (p && p.width() == 0 && p.height() == 0) p.size(self.width(), self.height()) - /* callback */ + // callback if (typeof self._loaded === 'function') self._loaded.call(self, { width: img.width @@ -38,7 +38,7 @@ SVG.Image = SVG.invent({ return this.attr('href', (img.src = this.src = url), SVG.xlink) } - // Add loade callback + // Add loaded callback , loaded: function(loaded) { this._loaded = loaded return this @@ -47,7 +47,7 @@ SVG.Image = SVG.invent({ // Add parent method , construct: { - // Create image element, load image and set its size + // create image element, load image and set its size image: function(source, width, height) { return this.put(new SVG.Image).load(source).size(width || 0, height || width || 0) } diff --git a/src/matrix.js b/src/matrix.js index b175860..d1757f3 100644 --- a/src/matrix.js +++ b/src/matrix.js @@ -78,7 +78,11 @@ SVG.Matrix = SVG.invent({ } // rotate matrix - matrix = matrix.rotate(param.rotation - this.param.initial, param.cx, param.cy) + matrix = matrix.rotate( + (this.param.to.rotation - this.param.from.rotation * 2) * pos + , param.cx + , param.cy + ) // store current parametric values matrix.param = param |