Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: include.preload.js

Issue 5504296699297792: Issue 1802 - Fix element hiding filters with multiple CSS selectors when using shadow DOM (Closed)
Patch Set: Replaced regex with state machine Created Jan. 22, 2015, 7:33 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include.preload.js
===================================================================
--- a/include.preload.js
+++ b/include.preload.js
@@ -152,6 +152,47 @@
observer.observe(style.parentNode, {childList: true});
}
+function convertSelectorsForShadowDOM(selectors)
+{
+ var result = [];
+ var prefix = "::content ";
+
+ for (var i = 0; i < selectors.length; i++)
+ {
+ var selector = selectors[i];
+ var start = 0;
+ var sep = "";
+
+ for (var j = 0; j < selector.length; j++)
+ {
+ var chr = selector[j];
+ switch (chr)
+ {
+ case "\\":
+ j++;
+ break;
+ case sep:
+ sep = "";
+ break;
+ case '"':
+ case "'":
+ sep = chr;
+ break;
Wladimir Palant 2015/01/22 08:15:52 Note that technically there might be more separato
+ case ",":
+ if (sep == "")
+ {
+ result.push(prefix + selector.substring(start, j));
+ start = j + 1;
+ }
Wladimir Palant 2015/01/22 08:15:52 Nit: please add a break statement here, for consis
Sebastian Noack 2015/01/22 09:40:59 Ah, let's go with if/else then. It's more compact,
+ }
+ }
+
+ result.push(prefix + selector.substring(start, j));
Wladimir Palant 2015/01/22 08:15:52 The second parameter is unnecessary here, can be s
Sebastian Noack 2015/01/22 09:40:59 Oh, you are right.
+ }
+
+ return result;
+}
+
function init(document)
{
// Use Shadow DOM if available to don't mess with web pages that rely on
@@ -181,9 +222,7 @@
if (shadow)
{
shadow.appendChild(style);
-
- for (var i = 0; i < selectors.length; i++)
- selectors[i] = "::content " + selectors[i];
+ selectors = convertSelectorsForShadowDOM(selectors);
}
else
{
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld