@@ -16,7 +16,7 @@ var enableSVGDownload = function (classView) {
16
16
function getSources ( doc , emptySvgDeclarationComputed ) {
17
17
18
18
var svgInfo = [ ] ,
19
- svgs = doc . querySelectorAll ( "svg" ) ;
19
+ svgs = doc . querySelectorAll ( "#svgContainer > svg" ) ;
20
20
21
21
[ ] . forEach . call ( svgs , function ( svg ) {
22
22
@@ -67,17 +67,15 @@ var enableSVGDownload = function (classView) {
67
67
68
68
document . getElementById ( "button.downloadSVG" ) . addEventListener ( "click" , function ( ) {
69
69
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 ] ;
74
74
var filename = ( classView || { } ) . SELECTED_NAME || "classDiagram" ;
75
-
76
75
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" ) ;
81
79
canvas . setAttribute ( "width" , source . width ) ;
82
80
canvas . setAttribute ( "height" , source . height ) ;
83
81
document . body . appendChild ( canvas ) ;
@@ -92,6 +90,7 @@ var enableSVGDownload = function (classView) {
92
90
a . click ( ) ;
93
91
setTimeout ( function ( ) {
94
92
a . parentNode . removeChild ( a ) ;
93
+ document . body . removeChild ( emptySvg ) ;
95
94
canvas . parentNode . removeChild ( canvas ) ;
96
95
window . URL . revokeObjectURL ( url ) ;
97
96
} , 10 ) ;
@@ -110,6 +109,10 @@ var enableSVGDownload = function (classView) {
110
109
for ( i = 0 , len = cSSStyleDeclarationComputed . length ; i < len ; i ++ ) {
111
110
key = cSSStyleDeclarationComputed [ i ] ;
112
111
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
+
113
116
if ( value !== emptySvgDeclarationComputed . getPropertyValue ( key ) ) {
114
117
computedStyleStr += key + ":" + value + ";" ;
115
118
}
0 commit comments