diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-10-25 23:26:38 +0200 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-10-25 23:26:38 +0200 |
commit | 464af8b747389b7fdb569a933591c863b9be0f6b (patch) | |
tree | a23da0d70a26c142616207b0a0a489affd2f3ac6 /src/Pattern.js | |
parent | f46aedf58fbc93483cb21017ffed10e439830108 (diff) | |
download | svg.js-464af8b747389b7fdb569a933591c863b9be0f6b.tar.gz svg.js-464af8b747389b7fdb569a933591c863b9be0f6b.zip |
Rename files so that they reflect their exported classes (see next commit)
Diffstat (limited to 'src/Pattern.js')
-rw-r--r-- | src/Pattern.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/Pattern.js b/src/Pattern.js new file mode 100644 index 0000000..d4c4116 --- /dev/null +++ b/src/Pattern.js @@ -0,0 +1,59 @@ +SVG.Pattern = SVG.invent({ + // Initialize node + create: 'pattern', + + // Inherit from + inherit: SVG.Container, + + // Add class methods + extend: { + // Return the fill id + url: function () { + return 'url(#' + this.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.url() + }, + // custom attr to handle transform + attr: function (a, b, c) { + if (a === 'transform') a = 'patternTransform' + return SVG.Container.prototype.attr.call(this, a, b, c) + } + + }, + + // 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' + }) + } + +}) |