Commit b87db710ef9905d93352690bd026eaa770a58911
1 parent
cfc5bded
Exists in
master
and in
4 other branches
Fix css extraction when export png
Showing
1 changed file
with
13 additions
and
5 deletions
Show diff stats
app/main/static/js/svg_to_png.js
@@ -38,9 +38,11 @@ function getSVGString(svgNode) { | @@ -38,9 +38,11 @@ function getSVGString(svgNode) { | ||
38 | 38 | ||
39 | // Add Parent element Id and Classes to the list | 39 | // Add Parent element Id and Classes to the list |
40 | selectorTextArr.push('#' + parentElement.id); | 40 | selectorTextArr.push('#' + parentElement.id); |
41 | - for (var c = 0; c < parentElement.classList.length; c++) | ||
42 | - if (!contains('.' + parentElement.classList[c], selectorTextArr)) | 41 | + for (var c = 0; c < parentElement.classList.length; c++){ |
42 | + if (!contains('.' + parentElement.classList[c], selectorTextArr)){ | ||
43 | selectorTextArr.push('.' + parentElement.classList[c]); | 43 | selectorTextArr.push('.' + parentElement.classList[c]); |
44 | + } | ||
45 | + } | ||
44 | 46 | ||
45 | // Add Children element Ids and Classes to the list | 47 | // Add Children element Ids and Classes to the list |
46 | var nodes = parentElement.getElementsByTagName("*"); | 48 | var nodes = parentElement.getElementsByTagName("*"); |
@@ -50,9 +52,10 @@ function getSVGString(svgNode) { | @@ -50,9 +52,10 @@ function getSVGString(svgNode) { | ||
50 | selectorTextArr.push('#' + id); | 52 | selectorTextArr.push('#' + id); |
51 | 53 | ||
52 | var classes = nodes[i].classList; | 54 | var classes = nodes[i].classList; |
53 | - for (var c = 0; c < classes.length; c++) | 55 | + for (var c = 0; c < classes.length; c++){ |
54 | if (!contains('.' + classes[c], selectorTextArr)) | 56 | if (!contains('.' + classes[c], selectorTextArr)) |
55 | selectorTextArr.push('.' + classes[c]); | 57 | selectorTextArr.push('.' + classes[c]); |
58 | + } | ||
56 | } | 59 | } |
57 | 60 | ||
58 | // Extract CSS Rules | 61 | // Extract CSS Rules |
@@ -69,8 +72,13 @@ function getSVGString(svgNode) { | @@ -69,8 +72,13 @@ function getSVGString(svgNode) { | ||
69 | 72 | ||
70 | var cssRules = s.cssRules; | 73 | var cssRules = s.cssRules; |
71 | for (var r = 0; r < cssRules.length; r++) { | 74 | for (var r = 0; r < cssRules.length; r++) { |
72 | - if (contains(cssRules[r].selectorText, selectorTextArr)) | ||
73 | - extractedCSSText += cssRules[r].cssText; | 75 | + var cssRule = cssRules[r] |
76 | + if (typeof cssRule.selectorText === 'undefined') { | ||
77 | + continue; | ||
78 | + } | ||
79 | + var classFromSelector = '.'+cssRule.selectorText.split('.')[1] | ||
80 | + if (contains(classFromSelector, selectorTextArr)) | ||
81 | + extractedCSSText += cssRule.cssText; | ||
74 | } | 82 | } |
75 | } | 83 | } |
76 | 84 |