diff options
author | wout <wout@impinc.co.uk> | 2014-02-05 00:06:36 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-02-05 00:06:36 +0100 |
commit | 9995944cb253ba93441e2d65cef415daa3541a52 (patch) | |
tree | 9d69d943841bec9a25039ee417d58a3125249723 /src/pattern.js | |
parent | 43fd91ccce8f9bce60ed7c566e32152be42f9774 (diff) | |
download | svg.js-9995944cb253ba93441e2d65cef415daa3541a52.tar.gz svg.js-9995944cb253ba93441e2d65cef415daa3541a52.zip |
Added loader on SVG.Image and included svg.pattern.js to the core
Diffstat (limited to 'src/pattern.js')
-rw-r--r-- | src/pattern.js | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/pattern.js b/src/pattern.js new file mode 100644 index 0000000..e5398d2 --- /dev/null +++ b/src/pattern.js @@ -0,0 +1,52 @@ +SVG.Pattern = SVG.invent({ + // Initialize node + create: 'pattern' + + // Inherit from +, inherit: SVG.Container + + // Add class methods +, extend: { + // Return the fill id + fill: function() { + return 'url(#' + this.attr('id') + ')' + } + // Update pattern by rebuilding + , update: function(block) { + /* remove content */ + this.clear() + + /* invoke passed block */ + if (typeof block == 'function') + block.call(this, this) + + return this + } + // Alias string convertion to fill + , toString: function() { + return this.fill() + } + } + + // Add parent method +, construct: { + // Create pattern element in defs + pattern: function(width, height, block) { + return this.defs().pattern(width, height, block) + } + } +}) + +SVG.extend(SVG.Defs, { + // Define gradient + pattern: function(width, height, block) { + return this.put(new SVG.Pattern).update(block).attr({ + x: 0 + , y: 0 + , width: width + , height: height + , patternUnits: 'userSpaceOnUse' + }) + } + +})
\ No newline at end of file |