diff options
author | wout <wout@impinc.co.uk> | 2013-01-06 16:03:33 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2013-01-06 16:03:33 +0100 |
commit | 50e1e48708d86ac0392348190f36d6c0c557a1d6 (patch) | |
tree | e848b79ff78fe34cb27075591beaf33cc7ae0fc6 /src/pattern.js | |
parent | 5ff480264d9a62a77dde9568c8a5576b23b0298e (diff) | |
download | svg.js-50e1e48708d86ac0392348190f36d6c0c557a1d6.tar.gz svg.js-50e1e48708d86ac0392348190f36d6c0c557a1d6.zip |
Added patterns
Diffstat (limited to 'src/pattern.js')
-rw-r--r-- | src/pattern.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/pattern.js b/src/pattern.js new file mode 100644 index 0000000..80985c8 --- /dev/null +++ b/src/pattern.js @@ -0,0 +1,43 @@ +SVG.Pattern = function Pattern(type) { + this.constructor.call(this, SVG.create('pattern')); + + /* set unique id */ + this.id = 'svgjs_' + (SVG.did++); + this.attr('id', this.id); +}; + +// Inherit from SVG.Element +SVG.Pattern.prototype = new SVG.Element(); + +// Include the container object +SVG.extend(SVG.Pattern, SVG.Container); + +// +SVG.extend(SVG.Pattern, { + // Return the fill id + fill: function() { + return 'url(#' + this.id + ')'; + } + +}); + +// +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' + }); + } + +});
\ No newline at end of file |