diff options
author | wout <wout@impinc.co.uk> | 2013-07-01 20:47:33 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2013-07-01 20:47:33 +0100 |
commit | 4a6da20fd312d5ea1d3f98f1bcb3b0763a66870a (patch) | |
tree | 5223b6abf4d8da2d4c4811c53e6c2256e702f425 /src/set.js | |
parent | b9b4af505a8f6abae7167bdff39d88c484d51aa7 (diff) | |
download | svg.js-4a6da20fd312d5ea1d3f98f1bcb3b0763a66870a.tar.gz svg.js-4a6da20fd312d5ea1d3f98f1bcb3b0763a66870a.zip |
Added SVG.Set adn bumped to v0.24
Diffstat (limited to 'src/set.js')
-rw-r--r-- | src/set.js | 92 |
1 files changed, 79 insertions, 13 deletions
@@ -1,37 +1,103 @@ SVG.Set = function() { - this.children = [] + /* set initial state */ + this.clear() } +// Set FX class +SVG.SetFX = function(set) { + /* store reference to set */ + this.set = set +} + +// SVG.extend(SVG.Set, { // Add element to set add: function(element) { - this.children.push(element) + this.members.push(element) return this } // Remove element from set , remove: function(element) { - var i = this.children.indexOf(element) + var i = this.members.indexOf(element) + /* remove given child */ if (i > -1) - this.children.splice(i, 1) + this.members.splice(i, 1) + + return this + } + // Iterate over all members +, each: function(block) { + for (var i = 0, il = this.members.length; i < il; i++) + block.apply(this.members[i], [i, this.members]) return this } - // Move all children -, move: function(x, y) { - return this.x(x).y(y) + // Restore to defaults +, clear: function() { + /* initialize store */ + this.members = [] + + return this + } + // Default value +, valueOf: function() { + return this.members } }) -// Create method aliases -;['attr'].forEach(function(method) { - SVG.Set.prototype[method] = function() { - for (var i = 0, il = this.children.length; i < il; i++) - this.children[i][method](arguments) +// Alias methods +SVG.Set.inherit = function() { + var m + , methods = [] + + /* gather shape methods */ + for(var m in SVG.Shape.prototype) + if (typeof SVG.Shape.prototype[m] == 'function' && typeof SVG.Set.prototype[m] != 'function') + methods.push(m) + + /* apply shape aliasses */ + methods.forEach(function(method) { + SVG.Set.prototype[method] = function() { + for (var i = 0, il = this.members.length; i < il; i++) + if (this.members[i] && typeof this.members[i][method] == 'function') + this.members[i][method].apply(this.members[i], arguments) + + return method == 'animate' ? (this.fx || (this.fx = new SVG.SetFX(this))) : this + } + }) + + /* clear methods for the next round */ + methods = [] + + /* gather fx methods */ + for(var m in SVG.FX.prototype) + if (typeof SVG.FX.prototype[m] == 'function' && typeof SVG.SetFX.prototype[m] != 'function') + methods.push(m) + + /* apply fx aliasses */ + methods.forEach(function(method) { + SVG.SetFX.prototype[method] = function() { + for (var i = 0, il = this.set.members.length; i < il; i++) + this.set.members[i].fx[method].apply(this.set.members[i].fx, arguments) + + return this + } + }) +} + +// +SVG.extend(SVG.Container, { + // Create a new set + set: function() { + return new SVG.Set } -})
\ No newline at end of file +}) + + + |