aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2013-02-02 11:14:21 +0100
committerwout <wout@impinc.co.uk>2013-02-02 11:14:21 +0100
commit7323d05f9d09141ec81dcd78d09bdba714c1c5dd (patch)
tree191d1a1e74f8f6b2ab5b7e473897e5daf8759dde /src
parent4a7588695a1b385f41acd6cbbfaf76b38b2a1439 (diff)
downloadsvg.js-7323d05f9d09141ec81dcd78d09bdba714c1c5dd.tar.gz
svg.js-7323d05f9d09141ec81dcd78d09bdba714c1c5dd.zip
Reworked SVG.Container inheritance
Diffstat (limited to 'src')
-rw-r--r--src/container.js11
-rw-r--r--src/defs.js7
-rw-r--r--src/doc.js7
-rw-r--r--src/gradient.js7
-rw-r--r--src/group.js7
-rw-r--r--src/mask.js7
-rw-r--r--src/nested.js7
-rw-r--r--src/pattern.js7
-rw-r--r--src/sugar.js15
-rw-r--r--src/svg.js12
10 files changed, 35 insertions, 52 deletions
diff --git a/src/container.js b/src/container.js
index d828371..1f0998a 100644
--- a/src/container.js
+++ b/src/container.js
@@ -1,7 +1,12 @@
-// ### A module used for container elements like SVG.Doc, SVG.Group, SVG.Defs, ...
+SVG.Container = function Container(element) {
+ this.constructor.call(this, element);
+};
+
+// Inherit from SVG.Element
+SVG.Container.prototype = new SVG.Element();
//
-SVG.Container = {
+SVG.extend(SVG.Container, {
// Add given element at a position
add: function(element, index) {
if (!this.has(element)) {
@@ -131,4 +136,4 @@ SVG.Container = {
return this;
}
-}; \ No newline at end of file
+}); \ No newline at end of file
diff --git a/src/defs.js b/src/defs.js
index 875013b..8714663 100644
--- a/src/defs.js
+++ b/src/defs.js
@@ -5,8 +5,5 @@ SVG.Defs = function Defs() {
this.constructor.call(this, SVG.create('defs'));
};
-// Inherits from SVG.Element
-SVG.Defs.prototype = new SVG.Element();
-
-// Include the container object
-SVG.extend(SVG.Defs, SVG.Container); \ No newline at end of file
+// Inherits from SVG.Container
+SVG.Defs.prototype = new SVG.Container(); \ No newline at end of file
diff --git a/src/doc.js b/src/doc.js
index 7afea7a..ce67b1c 100644
--- a/src/doc.js
+++ b/src/doc.js
@@ -19,11 +19,8 @@ SVG.Doc = function Doc(element) {
this.stage();
};
-// Inherits from SVG.Element
-SVG.Doc.prototype = new SVG.Element();
-
-// Include the container object
-SVG.extend(SVG.Doc, SVG.Container);
+// Inherits from SVG.Container
+SVG.Doc.prototype = new SVG.Container();
// Hack for safari preventing text to be rendered in one line.
// Basically it sets the position of the svg node to absolute
diff --git a/src/gradient.js b/src/gradient.js
index 6554c92..07bb748 100644
--- a/src/gradient.js
+++ b/src/gradient.js
@@ -8,11 +8,8 @@ SVG.Gradient = function Gradient(type) {
this.type = type;
};
-// Inherit from SVG.Element
-SVG.Gradient.prototype = new SVG.Element();
-
-// Include the container object
-SVG.extend(SVG.Gradient, SVG.Container);
+// Inherit from SVG.Container
+SVG.Gradient.prototype = new SVG.Container();
//
SVG.extend(SVG.Gradient, {
diff --git a/src/group.js b/src/group.js
index df97c3e..cbb635f 100644
--- a/src/group.js
+++ b/src/group.js
@@ -2,11 +2,8 @@ SVG.G = function G() {
this.constructor.call(this, SVG.create('g'));
};
-// Inherit from SVG.Element
-SVG.G.prototype = new SVG.Element();
-
-// Include the container object
-SVG.extend(SVG.G, SVG.Container);
+// Inherit from SVG.Container
+SVG.G.prototype = new SVG.Container();
SVG.extend(SVG.G, {
diff --git a/src/mask.js b/src/mask.js
index e7e94a4..5ffd790 100644
--- a/src/mask.js
+++ b/src/mask.js
@@ -5,11 +5,8 @@ SVG.Mask = function Mask() {
this.attr('id', (this.id = 'svgjs_element_' + (SVG.did++)));
};
-// Inherit from SVG.Element
-SVG.Mask.prototype = new SVG.Element();
-
-// Include the container object
-SVG.extend(SVG.Mask, SVG.Container);
+// Inherit from SVG.Container
+SVG.Mask.prototype = new SVG.Container();
SVG.extend(SVG.Element, {
diff --git a/src/nested.js b/src/nested.js
index 9cf54a9..d2aafdb 100644
--- a/src/nested.js
+++ b/src/nested.js
@@ -3,8 +3,5 @@ SVG.Nested = function Nested() {
this.attr('overflow', 'visible');
};
-// Inherit from SVG.Element
-SVG.Nested.prototype = new SVG.Element();
-
-// Include the container object
-SVG.extend(SVG.Nested, SVG.Container); \ No newline at end of file
+// Inherit from SVG.Container
+SVG.Nested.prototype = new SVG.Container(); \ No newline at end of file
diff --git a/src/pattern.js b/src/pattern.js
index 9b37297..c12978e 100644
--- a/src/pattern.js
+++ b/src/pattern.js
@@ -5,11 +5,8 @@ SVG.Pattern = function Pattern(type) {
this.attr('id', (this.id = 'svgjs_element_' + (SVG.did++)));
};
-// Inherit from SVG.Element
-SVG.Pattern.prototype = new SVG.Element();
-
-// Include the container object
-SVG.extend(SVG.Pattern, SVG.Container);
+// Inherit from SVG.Container
+SVG.Pattern.prototype = new SVG.Container();
//
SVG.extend(SVG.Pattern, {
diff --git a/src/sugar.js b/src/sugar.js
index bd8930e..d53054e 100644
--- a/src/sugar.js
+++ b/src/sugar.js
@@ -54,10 +54,17 @@ var _colorPrefix = function(type, attr) {
},
// Opacity
opacity: function(value) {
- if (['rect', 'ellipse', 'polygon', 'path', 'polyline', 'line', 'text'].indexOf(this.type) > -1)
- this.attr({ 'fill-opacity': value, 'stroke-opacity': value });
- else
- this.attr('opacity', value);
+ if (['rect', 'ellipse', 'polygon', 'path', 'polyline', 'line', 'text'].indexOf(this.type) > -1) {
+ if (value == null)
+ return this.attr('fill-opacity');
+ else
+ this.attr({ 'fill-opacity': value, 'stroke-opacity': value });
+ } else {
+ if (value == null)
+ return this.attr('opacity');
+ else
+ this.attr('opacity', value);
+ }
return this;
}
diff --git a/src/svg.js b/src/svg.js
index 409aa37..9306232 100644
--- a/src/svg.js
+++ b/src/svg.js
@@ -26,16 +26,8 @@ this.SVG = {
},
// Method for extending objects
extend: function(object, module) {
- /* extend all container modules */
- if (object == SVG.Container)
- ('Clip Defs Doc Gradient Group Mask Nested Pattern').split(' ').forEach(function(m) {
- if (SVG[m])
- SVG.extend(SVG[m], module);
- });
- /* extend given module */
- else
- for (var key in module)
- object.prototype[key] = module[key];
+ for (var key in module)
+ object.prototype[key] = module[key];
}
}; \ No newline at end of file