File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,17 @@ var Lib = require('../lib');
1717var xmlnsNamespaces = require ( '../constants/xmlns_namespaces' ) ;
1818var stringMappings = require ( '../constants/string_mappings' ) ;
1919
20+ exports . getDOMParser = function ( ) {
21+ if ( exports . domParser ) {
22+ return exports . domParser ;
23+ } else if ( window . DOMParser ) {
24+ exports . domParser = new window . DOMParser ( ) ;
25+ return exports . domParser ;
26+ } else {
27+ throw new Error ( 'Cannot initialize DOMParser' ) ;
28+ }
29+ } ;
30+
2031// Append SVG
2132
2233d3 . selection . prototype . appendSVG = function ( _svgString ) {
@@ -27,8 +38,9 @@ d3.selection.prototype.appendSVG = function(_svgString) {
2738 '</svg>'
2839 ] . join ( '' ) ;
2940
30- var dom = new DOMParser ( ) . parseFromString ( skeleton , 'application/xml' ) ,
31- childNode = dom . documentElement . firstChild ;
41+ var domParser = exports . getDOMParser ( ) ;
42+ var dom = domParser . parseFromString ( skeleton , 'application/xml' ) ;
43+ var childNode = dom . documentElement . firstChild ;
3244
3345 while ( childNode ) {
3446 this . node ( ) . appendChild ( this . node ( ) . ownerDocument . importNode ( childNode , true ) ) ;
You can’t perform that action at this time.
0 commit comments