diff options
author | wout <wout@impinc.co.uk> | 2014-08-01 20:40:49 +0200 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-08-01 20:40:49 +0200 |
commit | f0dc4d5ee03add261242743aa583c19d918f317c (patch) | |
tree | 2d480aed288eb180e53c3c0fba8623029478db8b /src/bare.js | |
parent | c2d1b2916b38d111d8672826c1219ab891567798 (diff) | |
download | svg.js-f0dc4d5ee03add261242743aa583c19d918f317c.tar.gz svg.js-f0dc4d5ee03add261242743aa583c19d918f317c.zip |
Added SVG.Bare for creation of non-described elements
Diffstat (limited to 'src/bare.js')
-rw-r--r-- | src/bare.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/bare.js b/src/bare.js new file mode 100644 index 0000000..a0b1ee3 --- /dev/null +++ b/src/bare.js @@ -0,0 +1,45 @@ + +SVG.Bare = SVG.invent({ + // Initialize + create: function(element, inherit) { + // construct element + this.constructor.call(this, SVG.create(element)) + + // inherit custom methods + if (inherit) + for (var method in inherit.prototype) + if (typeof inherit.prototype[method] === 'function') + element[method] = inherit.prototype[method] + } + + // Inherit from +, inherit: SVG.Element + + // Add methods +, extend: { + // Insert some plain text + words: function(text) { + // remove contents + while (this.node.hasChildNodes()) + this.node.removeChild(this.node.lastChild) + + // create text node + this.node.appendChild(document.createTextNode(text)) + + return this + } + } +}) + + +SVG.extend(SVG.Parent, { + // Create an element that is not described by SVG.js + element: function(element, inherit) { + return this.put(new SVG.Bare(element, inherit)) + } + // Add symbol element +, symbol: function() { + return this.defs().element('symbol', SVG.Container) + } + +})
\ No newline at end of file |