// 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)
, 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)
})
}
// 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)
}
// 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
// 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
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]))
// 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