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 | |
parent | 5ff480264d9a62a77dde9568c8a5576b23b0298e (diff) | |
download | svg.js-50e1e48708d86ac0392348190f36d6c0c557a1d6.tar.gz svg.js-50e1e48708d86ac0392348190f36d6c0c557a1d6.zip |
Added patterns
Diffstat (limited to 'src')
-rw-r--r-- | src/container.js | 6 | ||||
-rw-r--r-- | src/gradient.js | 2 | ||||
-rw-r--r-- | src/pattern.js | 43 |
3 files changed, 49 insertions, 2 deletions
diff --git a/src/container.js b/src/container.js index 14ad570..a43ce75 100644 --- a/src/container.js +++ b/src/container.js @@ -101,10 +101,14 @@ SVG.Container = { nested: function() { return this.put(new SVG.Nested()); }, - // create element in defs + // Create gradient element in defs gradient: function(type, block) { return this.defs().gradient(type, block); }, + // Create pattern element in defs + pattern: function(width, height, block) { + return this.defs().pattern(width, height, block); + }, // Create masking element mask: function() { return this.defs().put(new SVG.Mask()); diff --git a/src/gradient.js b/src/gradient.js index b34200e..0414d72 100644 --- a/src/gradient.js +++ b/src/gradient.js @@ -60,7 +60,7 @@ SVG.extend(SVG.Gradient, { // SVG.extend(SVG.Defs, { - /* define clippath */ + /* define gradient */ gradient: function(type, block) { var element = this.put(new SVG.Gradient(type)); 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 |