diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2015-06-28 21:24:20 +0200 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2015-06-28 21:24:20 +0200 |
commit | 7125c6417479216808469e5c4016ec8b1dc515c6 (patch) | |
tree | fbb54e5b47e67b5804f090692ee594e50c422d35 | |
parent | c6026fb0051177ded9cfc9b462ec80123f490467 (diff) | |
download | svg.js-7125c6417479216808469e5c4016ec8b1dc515c6.tar.gz svg.js-7125c6417479216808469e5c4016ec8b1dc515c6.zip |
Fixed few bugs with doc() and problems with textNodes (#357)
-rw-r--r-- | src/image.js | 2 | ||||
-rw-r--r-- | src/parent.js | 2 | ||||
-rw-r--r-- | src/text.js | 17 | ||||
-rw-r--r-- | src/utilities.js | 19 |
4 files changed, 18 insertions, 22 deletions
diff --git a/src/image.js b/src/image.js index ed44752..ed803d6 100644 --- a/src/image.js +++ b/src/image.js @@ -16,7 +16,7 @@ SVG.Image = SVG.invent({ // preload image img.onload = function() { - var p = self.doc(SVG.Pattern) + var p = self.parent(SVG.Pattern) // ensure image size if (self.width() == 0 && self.height() == 0) diff --git a/src/parent.js b/src/parent.js index c4476c6..86c7db8 100644 --- a/src/parent.js +++ b/src/parent.js @@ -11,7 +11,7 @@ SVG.Parent = SVG.invent({ , extend: { // Returns all child elements children: function() { - return SVG.utils.map(this.node.childNodes, function(node) { + return SVG.utils.map(SVG.utils.filterSVGElements(this.node.childNodes), function(node) { return SVG.adopt(node) }) } diff --git a/src/text.js b/src/text.js index 389a670..14f2137 100644 --- a/src/text.js +++ b/src/text.js @@ -89,10 +89,10 @@ SVG.Text = SVG.invent({ // Get all the first level lines , lines: function() { // filter tspans and map them to SVG.js instances - for (var i = 0, il = this.node.childNodes.length, lines = []; i < il; i++) - if (this.node.childNodes[i] instanceof SVGElement) - lines.push(SVG.adopt(this.node.childNodes[i])) - + var lines = SVG.utils.map(SVG.utils.filterSVGElements(this.node.childNodes), function(el){ + return SVG.adopt(el) + }) + // return an instance of SVG.set return new SVG.Set(lines) } @@ -167,7 +167,7 @@ SVG.Tspan = SVG.invent({ // Create new line , newLine: function() { // fetch text parent - var t = this.doc(SVG.Text) + var t = this.parent(SVG.Text) // mark new line this.newLined = true @@ -203,13 +203,6 @@ SVG.extend(SVG.Text, SVG.Tspan, { // add new tspan node.appendChild(tspan.node) - // only first level tspans are considered to be "lines" - // that doenst make sence. A line is added to a SVG.Set which is never used or returned. - // So why bother adding it? - // Also: lines() reads all children so it already has this tspan in it because we added it before - if (this instanceof SVG.Text) - this.lines().add(tspan) - return tspan.text(text) } // Clear all lines diff --git a/src/utilities.js b/src/utilities.js index 0c1a0a3..70495cd 100644 --- a/src/utilities.js +++ b/src/utilities.js @@ -1,10 +1,10 @@ SVG.utils = { - // Map function - map: function(array, block) { + // Map function + map: function(array, block) { var i , il = array.length , result = [] - + for (i = 0; i < il; i++) result.push(block(array[i])) @@ -13,11 +13,14 @@ SVG.utils = { // Degrees to radians , radians: function(d) { - return d % 360 * Math.PI / 180 - } - // Radians to degrees + return d % 360 * Math.PI / 180 + } + // Radians to degrees , degrees: function(r) { - return r * 180 / Math.PI % 360 - } + return r * 180 / Math.PI % 360 + } +, filterSVGElements: function(p) { + return [].filter.call(p, function(el){ return el instanceof SVGElement }) + } }
\ No newline at end of file |