| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 1 function splitSelector(selector) | |
|
Sebastian Noack
2016/02/15 17:19:08
This logic has been copied (with some minor change
kzar
2016/02/15 17:30:14
Acknowledged. (Mind filing an issue for that?)
Sebastian Noack
2016/02/15 17:49:31
I attached the patch the same issue: https://coder
| |
| 2 { | |
| 3 if (selector.indexOf(",") == -1) | |
| 4 return [selector]; | |
| 5 | |
| 6 var selectors = []; | |
| 7 var start = 0; | |
| 8 var level = 0; | |
| 9 var sep = ""; | |
| 10 | |
| 11 for (var i = 0; i < selector.length; i++) | |
| 12 { | |
| 13 var chr = selector[i]; | |
| 14 | |
| 15 if (chr == "\\") // ignore escaped characters | |
| 16 i++; | |
| 17 else if (chr == sep) // don't split within quoted text | |
| 18 sep = ""; // e.g. [attr=","] | |
| 19 else if (sep == "") | |
| 20 { | |
| 21 if (chr == '"' || chr == "'") | |
| 22 sep = chr; | |
| 23 else if (chr == "(") // don't split between parentheses | |
| 24 level++; // e.g. :matches(div,span) | |
| 25 else if (chr == ")") | |
| 26 level = Math.max(0, level - 1); | |
| 27 else if (chr == "," && level == 0) | |
| 28 { | |
| 29 selectors.push(selector.substring(start, i)); | |
| 30 start = i + 1; | |
| 31 } | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 selectors.push(selector.substring(start)); | |
| 36 return selectors; | |
| 37 } | |
| 38 | |
| 1 function CSSPropertyFilters(window, addSelectorsFunc) { | 39 function CSSPropertyFilters(window, addSelectorsFunc) { |
| 2 this.window = window; | 40 this.window = window; |
| 3 this.addSelectorsFunc = addSelectorsFunc; | 41 this.addSelectorsFunc = addSelectorsFunc; |
| 4 } | 42 } |
| 5 | |
| 6 CSSPropertyFilters.prototype = { | 43 CSSPropertyFilters.prototype = { |
| 7 stringifyStyle: function(style) | 44 stringifyStyle: function(style) |
| 8 { | 45 { |
| 9 var styles = []; | 46 var styles = []; |
| 10 for (var i = 0; i < style.length; i++) | 47 for (var i = 0; i < style.length; i++) |
| 11 { | 48 { |
| 12 var property = style.item(i); | 49 var property = style.item(i); |
| 13 var value = style.getPropertyValue(property); | 50 var value = style.getPropertyValue(property); |
| 14 var priority = style.getPropertyPriority(property); | 51 var priority = style.getPropertyPriority(property); |
| 15 styles.push(property + ": " + value + (priority ? " !" + priority : "") + ";"); | 52 styles.push(property + ": " + value + (priority ? " !" + priority : "") + ";"); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 33 var style = this.stringifyStyle(rule.style); | 70 var style = this.stringifyStyle(rule.style); |
| 34 for (var j = 0; j < this.patterns.length; j++) | 71 for (var j = 0; j < this.patterns.length; j++) |
| 35 { | 72 { |
| 36 var pattern = this.patterns[j]; | 73 var pattern = this.patterns[j]; |
| 37 var regexp = pattern.regexp; | 74 var regexp = pattern.regexp; |
| 38 | 75 |
| 39 if (typeof regexp == "string") | 76 if (typeof regexp == "string") |
| 40 regexp = pattern.regexp = new RegExp(regexp); | 77 regexp = pattern.regexp = new RegExp(regexp); |
| 41 | 78 |
| 42 if (regexp.test(style)) | 79 if (regexp.test(style)) |
| 43 selectors.push(pattern.prefix + rule.selectorText + pattern.suffix); | 80 { |
| 81 var subSelectors = splitSelector(rule.selectorText); | |
| 82 for (var k = 0; k < subSelectors.length; k++) | |
| 83 selectors.push(pattern.prefix + subSelectors[k] + pattern.suffix); | |
| 84 } | |
| 44 } | 85 } |
| 45 } | 86 } |
| 46 }, | 87 }, |
| 47 | 88 |
| 48 addSelectors: function(stylesheets) | 89 addSelectors: function(stylesheets) |
| 49 { | 90 { |
| 50 var selectors = []; | 91 var selectors = []; |
| 51 for (var i = 0; i < stylesheets.length; i++) | 92 for (var i = 0; i < stylesheets.length; i++) |
| 52 this.findSelectors(stylesheets[i], selectors); | 93 this.findSelectors(stylesheets[i], selectors); |
| 53 this.addSelectorsFunc(selectors); | 94 this.addSelectorsFunc(selectors); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 78 apply: function() | 119 apply: function() |
| 79 { | 120 { |
| 80 if (this.patterns.length > 0) | 121 if (this.patterns.length > 0) |
| 81 { | 122 { |
| 82 var document = this.window.document; | 123 var document = this.window.document; |
| 83 this.addSelectors(document.styleSheets); | 124 this.addSelectors(document.styleSheets); |
| 84 document.addEventListener("load", this.onLoad.bind(this), true); | 125 document.addEventListener("load", this.onLoad.bind(this), true); |
| 85 } | 126 } |
| 86 } | 127 } |
| 87 }; | 128 }; |
| OLD | NEW |