diff options
author | wout <wout@impinc.co.uk> | 2013-07-22 13:52:20 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2013-07-22 13:52:20 +0100 |
commit | 9773661d9321927b5b86feef007fabba68eccf32 (patch) | |
tree | a45461b0a574017f6b6933b1ae2a73233e711e8f /src | |
parent | f5c28a74a55501982d5c76d4155170f569937465 (diff) | |
download | svg.js-9773661d9321927b5b86feef007fabba68eccf32.tar.gz svg.js-9773661d9321927b5b86feef007fabba68eccf32.zip |
Namespace fixes and added textPath and bumped to v0.270.28
Diffstat (limited to 'src')
-rw-r--r-- | src/image.js | 2 | ||||
-rw-r--r-- | src/path.js | 2 | ||||
-rw-r--r-- | src/textpath.js | 57 | ||||
-rw-r--r-- | src/use.js | 2 |
4 files changed, 60 insertions, 3 deletions
diff --git a/src/image.js b/src/image.js index b01897d..24806ff 100644 --- a/src/image.js +++ b/src/image.js @@ -10,7 +10,7 @@ SVG.extend(SVG.Image, { // (re)load image load: function(url) { - return (url ? this.attr('xlink:href', (this.src = url), SVG.xlink) : this) + return (url ? this.attr('href', (this.src = url), SVG.xlink) : this) } }) diff --git a/src/path.js b/src/path.js index ef6ab03..3a50703 100644 --- a/src/path.js +++ b/src/path.js @@ -1,7 +1,7 @@ SVG.Path = function(unbiased) { this.constructor.call(this, SVG.create('path')) - this.unbiased = unbiased + this.unbiased = !!unbiased } // Inherit from SVG.Shape diff --git a/src/textpath.js b/src/textpath.js new file mode 100644 index 0000000..dfe0152 --- /dev/null +++ b/src/textpath.js @@ -0,0 +1,57 @@ +SVG.TextPath = function() { + this.constructor.call(this, SVG.create('textPath')) +} + +// Inherit from SVG.Element +SVG.TextPath.prototype = new SVG.Path + +// +SVG.extend(SVG.TextPath, { + text: function(text) { + /* remove children */ + while (this.node.firstChild) + this.node.removeChild(this.node.firstChild) + + /* add text */ + this.node.appendChild(document.createTextNode(text)) + + return this.parent + } +}) + +// +SVG.extend(SVG.Text, { + // Create path for text to run on + path: function(d) { + /* create textPath element */ + this.textPath = new SVG.TextPath + + /* remove all child nodes */ + while (this.node.firstChild) + this.node.removeChild(this.node.firstChild) + + /* add textPath element as child node */ + this.node.appendChild(this.textPath.node) + + /* create path in defs */ + this.track = this.doc().defs().path(d, true) + + /* create circular reference */ + this.textPath.parent = this + + /* alias local text() method to textPath's text() method */ + this.text = function(text) { + return this.textPath.text(text) + } + + /* alias plot() method on track */ + this.plot = function(d) { + this.track.plot(d) + return this + } + + /* link textPath to path and add content */ + return this.textPath.attr('href', '#' + this.track, SVG.xlink).text(this.content) + } + +})
\ No newline at end of file @@ -13,7 +13,7 @@ SVG.extend(SVG.Use, { this.target = element /* set lined element */ - return this.attr('xlink:href', '#' + element, SVG.xlink) + return this.attr('href', '#' + element, SVG.xlink) } }) |