Commit b87db710ef9905d93352690bd026eaa770a58911

Authored by hitier
1 parent cfc5bded

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 38  
39 39 // Add Parent element Id and Classes to the list
40 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 43 selectorTextArr.push('.' + parentElement.classList[c]);
  44 + }
  45 + }
44 46  
45 47 // Add Children element Ids and Classes to the list
46 48 var nodes = parentElement.getElementsByTagName("*");
... ... @@ -50,9 +52,10 @@ function getSVGString(svgNode) {
50 52 selectorTextArr.push('#' + id);
51 53  
52 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 56 if (!contains('.' + classes[c], selectorTextArr))
55 57 selectorTextArr.push('.' + classes[c]);
  58 + }
56 59 }
57 60  
58 61 // Extract CSS Rules
... ... @@ -69,8 +72,13 @@ function getSVGString(svgNode) {
69 72  
70 73 var cssRules = s.cssRules;
71 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  
... ...