Comparing version 0.0.1 to 0.0.2
29
index.js
module.exports = svg; | ||
svg.compile = require('./lib/compile'); | ||
var compileTemplate = svg.compileTemplate = require('./lib/compileTemplate'); | ||
var domEvents = require('add-event-listener'); | ||
var svgns = "http://www.w3.org/2000/svg"; | ||
@@ -16,2 +21,4 @@ var xlinkns = "http://www.w3.org/1999/xlink"; | ||
var compiledTempalte; | ||
svgElement.simplesvg = true; // this is not good, since we are monkey patching svg | ||
@@ -21,4 +28,26 @@ svgElement.attr = attr; | ||
// add easy eventing | ||
svgElement.on = on; | ||
svgElement.off = off; | ||
// data binding: | ||
svgElement.dataSource = dataSource; | ||
return svgElement; | ||
function dataSource(model) { | ||
if (!compiledTempalte) compiledTempalte = compileTemplate(svgElement); | ||
compiledTempalte.link(model); | ||
} | ||
function on(name, cb, useCapture) { | ||
domEvents.addEventListener(svgElement, name, cb, useCapture); | ||
return svgElement; | ||
} | ||
function off(name, cb, useCapture) { | ||
domEvents.removeEventListener(svgElement, name, cb, useCapture); | ||
return svgElement; | ||
} | ||
function append(child) { | ||
@@ -25,0 +54,0 @@ svgElement.appendChild(svg(child)); |
@@ -8,5 +8,4 @@ var parser = new DOMParser(); | ||
try { | ||
return svg(parser.parseFromString( | ||
'<g xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg">' + | ||
svgText + '</g>', "text/xml").documentElement); | ||
svgText = addNamespaces(svgText); | ||
return svg(parser.parseFromString(svgText, "text/xml").documentElement); | ||
} catch (e) { | ||
@@ -16,1 +15,14 @@ throw e; | ||
} | ||
function addNamespaces(text) { | ||
if (!text) return; | ||
var namespaces = 'xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"'; | ||
var match = text.match(/^<\w+/); | ||
if (match) { | ||
var tagLength = match[0].length; | ||
return text.substr(0, tagLength) + ' ' + namespaces + ' ' + text.substr(tagLength); | ||
} else { | ||
throw new Error('Cannot parse input text: invalid xml?'); | ||
} | ||
} |
{ | ||
"name": "simplesvg", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A very simple svg wrapper, inspired by original vivagraph", | ||
@@ -18,3 +18,6 @@ "main": "index.js", | ||
"url": "https://github.com/anvaka/simplesvg" | ||
}, | ||
"dependencies": { | ||
"add-event-listener": "0.0.1" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6392
7
136
1
+ Addedadd-event-listener@0.0.1
+ Addedadd-event-listener@0.0.1(transitive)