File tree 1 file changed +14
-2
lines changed
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');
17
17
var xmlnsNamespaces = require ( '../constants/xmlns_namespaces' ) ;
18
18
var stringMappings = require ( '../constants/string_mappings' ) ;
19
19
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
+
20
31
// Append SVG
21
32
22
33
d3 . selection . prototype . appendSVG = function ( _svgString ) {
@@ -27,8 +38,9 @@ d3.selection.prototype.appendSVG = function(_svgString) {
27
38
'</svg>'
28
39
] . join ( '' ) ;
29
40
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 ;
32
44
33
45
while ( childNode ) {
34
46
this . node ( ) . appendChild ( this . node ( ) . ownerDocument . importNode ( childNode , true ) ) ;
You can’t perform that action at this time.
0 commit comments