aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2013-07-01 20:47:33 +0100
committerwout <wout@impinc.co.uk>2013-07-01 20:47:33 +0100
commit4a6da20fd312d5ea1d3f98f1bcb3b0763a66870a (patch)
tree5223b6abf4d8da2d4c4811c53e6c2256e702f425 /src
parentb9b4af505a8f6abae7167bdff39d88c484d51aa7 (diff)
downloadsvg.js-4a6da20fd312d5ea1d3f98f1bcb3b0763a66870a.tar.gz
svg.js-4a6da20fd312d5ea1d3f98f1bcb3b0763a66870a.zip
Added SVG.Set adn bumped to v0.24
Diffstat (limited to 'src')
-rw-r--r--src/event.js22
-rw-r--r--src/fx.js1
-rw-r--r--src/pattern.js48
-rw-r--r--src/set.js92
-rw-r--r--src/svg.js4
5 files changed, 93 insertions, 74 deletions
diff --git a/src/event.js b/src/event.js
index 84022c7..2fc14bb 100644
--- a/src/event.js
+++ b/src/event.js
@@ -3,19 +3,15 @@
// rect.click(function() {
// this.fill({ color: '#f06' })
// })
-;[ 'click'
-, 'dblclick'
-, 'mousedown'
-, 'mouseup'
-, 'mouseover'
-, 'mouseout'
-, 'mousemove'
-, 'mouseenter'
-, 'mouseleave'
-, 'touchstart'
-, 'touchend'
-, 'touchmove'
-, 'touchcancel' ].forEach(function(event) {
+;[ 'click'
+ , 'dblclick'
+ , 'mousedown'
+ , 'mouseup'
+ , 'mouseover'
+ , 'mouseout'
+ , 'mousemove'
+ , 'mouseenter'
+ , 'mouseleave' ].forEach(function(event) {
/* add event to SVG.Element */
SVG.Element.prototype[event] = function(f) {
diff --git a/src/fx.js b/src/fx.js
index eb563fa..d5632b7 100644
--- a/src/fx.js
+++ b/src/fx.js
@@ -335,6 +335,7 @@ SVG.extend(SVG.FX, {
}
})
+
//
SVG.extend(SVG.Element, {
// Get fx module or create a new one, then animate with given duration and ease
diff --git a/src/pattern.js b/src/pattern.js
deleted file mode 100644
index 4807049..0000000
--- a/src/pattern.js
+++ /dev/null
@@ -1,48 +0,0 @@
-SVG.Pattern = function(type) {
- this.constructor.call(this, SVG.create('pattern'))
-}
-
-// Inherit from SVG.Container
-SVG.Pattern.prototype = new SVG.Container
-
-//
-SVG.extend(SVG.Pattern, {
- // Return the fill id
- fill: function() {
- return 'url(#' + this.attr('id') + ')'
- }
- // Alias string convertion to fill
-, toString: function() {
- return this.fill()
- }
-
-})
-
-//
-SVG.extend(SVG.Defs, {
- // Define gradient
- pattern: function(width, height, block) {
- var element = this.put(new SVG.Pattern)
-
- /* invoke passed block */
- block(element)
-
- return element.attr({
- x: 0
- , y: 0
- , width: width
- , height: height
- , patternUnits: 'userSpaceOnUse'
- })
- }
-
-})
-
-//
-SVG.extend(SVG.Container, {
- // Create pattern element in defs
- pattern: function(width, height, block) {
- return this.defs().pattern(width, height, block)
- }
-
-}) \ No newline at end of file
diff --git a/src/set.js b/src/set.js
index c518c37..fe71237 100644
--- a/src/set.js
+++ b/src/set.js
@@ -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
+})
+
+
+
diff --git a/src/svg.js b/src/svg.js
index 1b82053..89c23e4 100644
--- a/src/svg.js
+++ b/src/svg.js
@@ -49,6 +49,10 @@ SVG.extend = function() {
if (modules[i])
for (key in methods)
modules[i].prototype[key] = methods[key]
+
+ /* make sure SVG.Set inherits any newly added methods */
+ if (SVG.Set && SVG.Set.inherit)
+ SVG.Set.inherit()
}
// Method for getting an eleemnt by id