summaryrefslogtreecommitdiffstats
path: root/src/set.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/set.js')
-rwxr-xr-xsrc/set.js175
1 files changed, 88 insertions, 87 deletions
diff --git a/src/set.js b/src/set.js
index 9a6addc..38251f5 100755
--- a/src/set.js
+++ b/src/set.js
@@ -1,91 +1,102 @@
-SVG.Set = function() {
- /* 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() {
- var i, il, elements = [].slice.call(arguments)
-
- for (i = 0, il = elements.length; i < il; i++)
- this.members.push(elements[i])
-
- return this
+SVG.Set = SVG.invent({
+ // Initialize
+ create: function() {
+ /* set initial state */
+ this.clear()
}
- // Remove element from set
-, remove: function(element) {
- var i = this.index(element)
-
- /* remove given child */
- if (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
- }
- // Restore to defaults
-, clear: function() {
- /* initialize store */
- this.members = []
+ // Add class methods
+, extend: {
+ // Add element to set
+ add: function() {
+ var i, il, elements = [].slice.call(arguments)
- return this
- }
- // Checks if a given element is present in set
-, has: function(element) {
- return this.index(element) >= 0
- }
- // retuns index of given element in set
-, index: function(element) {
- return this.members.indexOf(element)
- }
- // Get member at given index
-, get: function(i) {
- return this.members[i]
- }
- // Default value
-, valueOf: function() {
- return this.members
- }
- // Get the bounding box of all members included or empty box if set has no items
-, bbox: function(){
- var box = new SVG.BBox()
+ for (i = 0, il = elements.length; i < il; i++)
+ this.members.push(elements[i])
+
+ return this
+ }
+ // Remove element from set
+ , remove: function(element) {
+ var i = this.index(element)
+
+ /* remove given child */
+ if (i > -1)
+ this.members.splice(i, 1)
- /* return an empty box of there are no members */
- if (this.members.length == 0)
- return box
+ 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])
- /* get the first rbox and update the target bbox */
- var rbox = this.members[0].rbox()
- box.x = rbox.x
- box.y = rbox.y
- box.width = rbox.width
- box.height = rbox.height
+ return this
+ }
+ // Restore to defaults
+ , clear: function() {
+ /* initialize store */
+ this.members = []
- this.each(function() {
- /* user rbox for correct position and visual representation */
- box = box.merge(this.rbox())
- })
+ return this
+ }
+ // Checks if a given element is present in set
+ , has: function(element) {
+ return this.index(element) >= 0
+ }
+ // retuns index of given element in set
+ , index: function(element) {
+ return this.members.indexOf(element)
+ }
+ // Get member at given index
+ , get: function(i) {
+ return this.members[i]
+ }
+ // Default value
+ , valueOf: function() {
+ return this.members
+ }
+ // Get the bounding box of all members included or empty box if set has no items
+ , bbox: function(){
+ var box = new SVG.BBox()
+
+ /* return an empty box of there are no members */
+ if (this.members.length == 0)
+ return box
+
+ /* get the first rbox and update the target bbox */
+ var rbox = this.members[0].rbox()
+ box.x = rbox.x
+ box.y = rbox.y
+ box.width = rbox.width
+ box.height = rbox.height
+
+ this.each(function() {
+ /* user rbox for correct position and visual representation */
+ box = box.merge(this.rbox())
+ })
- return box
+ return box
+ }
+ }
+
+ // Add parent method
+, construct: {
+ // Create a new set
+ set: function() {
+ return new SVG.Set
+ }
}
-
})
+SVG.SetFX = SVG.invent({
+ // Initialize node
+ create: function(set) {
+ /* store reference to set */
+ this.set = set
+ }
+})
// Alias methods
SVG.Set.inherit = function() {
@@ -127,14 +138,4 @@ SVG.Set.inherit = function() {
})
}
-//
-SVG.extend(SVG.Container, {
- // Create a new set
- set: function() {
- return new SVG.Set
- }
-
-})
-
-