@@ -16,7 +16,7 @@ var enableSVGDownload = function (classView) {
1616 function getSources ( doc , emptySvgDeclarationComputed ) {
1717
1818 var svgInfo = [ ] ,
19- svgs = doc . querySelectorAll ( "svg" ) ;
19+ svgs = doc . querySelectorAll ( "#svgContainer > svg" ) ;
2020
2121 [ ] . forEach . call ( svgs , function ( svg ) {
2222
@@ -67,17 +67,15 @@ var enableSVGDownload = function (classView) {
6767
6868 document . getElementById ( "button.downloadSVG" ) . addEventListener ( "click" , function ( ) {
6969
70- var emptySvg = window . document . createElementNS ( prefix . svg , 'svg' ) ,
71- emptySvgDeclarationComputed = getComputedStyle ( emptySvg ) ,
72- source = getSources ( document , emptySvgDeclarationComputed ) [ 0 ] ;
73-
70+ var emptySvg = document . createElementNS ( prefix . svg , 'svg' ) ;
71+ document . body . appendChild ( emptySvg ) ;
72+ var emptySvgDeclarationComputed = getComputedStyle ( emptySvg ) ;
73+ var source = getSources ( document , emptySvgDeclarationComputed ) [ 0 ] ;
7474 var filename = ( classView || { } ) . SELECTED_NAME || "classDiagram" ;
75-
7675 var img = new Image ( ) ;
77- var url = window . URL . createObjectURL ( new Blob ( source . source , { "type" : 'image/svg+xml;charset=utf-8' /*"text\/xml"*/ } ) ) ;
78-
79- var canvas = document . createElement ( 'canvas' ) ;
80- var ctx = canvas . getContext ( '2d' ) ;
76+ var url = window . URL . createObjectURL ( new Blob ( source . source , { "type" : 'image/svg+xml;charset=utf-8' } ) ) ;
77+ var canvas = document . createElement ( "canvas" ) ;
78+ var ctx = canvas . getContext ( "2d" ) ;
8179 canvas . setAttribute ( "width" , source . width ) ;
8280 canvas . setAttribute ( "height" , source . height ) ;
8381 document . body . appendChild ( canvas ) ;
@@ -92,6 +90,7 @@ var enableSVGDownload = function (classView) {
9290 a . click ( ) ;
9391 setTimeout ( function ( ) {
9492 a . parentNode . removeChild ( a ) ;
93+ document . body . removeChild ( emptySvg ) ;
9594 canvas . parentNode . removeChild ( canvas ) ;
9695 window . URL . revokeObjectURL ( url ) ;
9796 } , 10 ) ;
@@ -110,6 +109,10 @@ var enableSVGDownload = function (classView) {
110109 for ( i = 0 , len = cSSStyleDeclarationComputed . length ; i < len ; i ++ ) {
111110 key = cSSStyleDeclarationComputed [ i ] ;
112111 value = cSSStyleDeclarationComputed . getPropertyValue ( key ) ;
112+
113+ // weird fix for weird bug in chrome: css rewrites w/h tag attributes!
114+ if ( value === "auto" && ( key === "width" || key === "height" ) ) continue ;
115+
113116 if ( value !== emptySvgDeclarationComputed . getPropertyValue ( key ) ) {
114117 computedStyleStr += key + ":" + value + ";" ;
115118 }
0 commit comments