diff options
Diffstat (limited to 'src/sugar.js')
-rw-r--r-- | src/sugar.js | 63 |
1 files changed, 31 insertions, 32 deletions
diff --git a/src/sugar.js b/src/sugar.js index f8a5660..14868e3 100644 --- a/src/sugar.js +++ b/src/sugar.js @@ -10,9 +10,9 @@ var _colorPrefix = function(type, attr) { /* Add sugar for fill and stroke */ ;['fill', 'stroke'].forEach(function(method) { + var extension = {} - // Set fill color and opacity - SVG.Shape.prototype[method] = function(o) { + extension[method] = function(o) { var indexOf if (typeof o == 'string' || SVG.Color.isRgb(o) || SVG.Color.isHsb(o)) @@ -27,42 +27,41 @@ var _colorPrefix = function(type, attr) { return this } + SVG.extend(SVG.Shape, SVG.FX, extension) + }) -;[SVG.Element, SVG.FX].forEach(function(module) { - if (module) { - SVG.extend(module, { - // Rotation - rotate: function(deg, cx, cy) { - return this.transform({ - rotation: deg || 0 - , cx: cx - , cy: cy - }) - } - // Skew - , skew: function(x, y) { - return this.transform({ - skewX: x || 0 - , skewY: y || 0 - }) - } - // Scale - , scale: function(x, y) { - return this.transform({ - scaleX: x, - scaleY: y == null ? x : y - }) - } - // Opacity - , opacity: function(value) { - return this.attr('opacity', value) - } - +SVG.extend(SVG.Element, SVG.FX, { + // Rotation + rotate: function(deg, cx, cy) { + return this.transform({ + rotation: deg || 0 + , cx: cx + , cy: cy }) } + // Skew +, skew: function(x, y) { + return this.transform({ + skewX: x || 0 + , skewY: y || 0 + }) + } + // Scale +, scale: function(x, y) { + return this.transform({ + scaleX: x, + scaleY: y == null ? x : y + }) + } + // Opacity +, opacity: function(value) { + return this.attr('opacity', value) + } + }) + if (SVG.Text) { SVG.extend(SVG.Text, { // Set font |