diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2017-03-16 13:40:53 +0100 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2017-03-16 13:40:53 +0100 |
commit | 4cf9fe96c6e03318a3748deb0338681360c57fdd (patch) | |
tree | 14b31a56575a60f347916b80f7f50cc4f93a7045 /src | |
parent | dddf54fa855060e117c5e031f59f5d3b30eb251e (diff) | |
download | svg.js-4cf9fe96c6e03318a3748deb0338681360c57fdd.tar.gz svg.js-4cf9fe96c6e03318a3748deb0338681360c57fdd.zip |
rework import/export method to be more straight forward and without regex magic
Diffstat (limited to 'src')
-rw-r--r-- | src/element.js | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/src/element.js b/src/element.js index 230aa4b..d82b8a1 100644 --- a/src/element.js +++ b/src/element.js @@ -204,31 +204,26 @@ SVG.Element = SVG.invent({ } // Import raw svg , svg: function(svg) { - // create temporary holder - var well = document.createElement('svg') + var well, len // act as a setter if svg is given if (svg && this instanceof SVG.Parent) { + + // create temporary holder + well = document.createElementNS(SVG.ns, 'svg') // dump raw svg - well.innerHTML = '<svg>' + svg.replace(/\n/, '').replace(/<(\w+)([^<]+?)\/>/g, '<$1$2></$1>') + '</svg>' + well.innerHTML = svg // transplant nodes - for (var i = 0, il = well.firstChild.childNodes.length; i < il; i++) - this.node.appendChild(well.firstChild.firstChild) + for (len = well.childNodes.length;len--;) + if(well.firstChild.nodeType != 1) + well.removeChild(well.firstChild) + else + this.node.appendChild(well.firstChild) // otherwise act as a getter } else { - // create a wrapping svg element in case of partial content - well.appendChild(svg = document.createElement('svg')) - - // write svgjs data to the dom - this.writeDataToDom() - - // insert a copy of this node - svg.appendChild(this.node.cloneNode(true)) - - // return target element - return well.innerHTML.replace(/^<svg>/, '').replace(/<\/svg>$/, '') + return this.node.outerHTML } return this |