aboutsummaryrefslogtreecommitdiffstats
path: root/src/pattern.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/pattern.js')
-rw-r--r--src/pattern.js43
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