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

Unified Diff: include.preload.js

Issue 29349024: Issue 4298 - Enforce 'display: none' for ElemHide (Closed)
Patch Set: Created Aug. 4, 2016, 3:23 p.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
diff --git a/include.preload.js b/include.preload.js
index bb6b97a01c6d5cc7bff5dc9ab8ca8285880f89bc..b144053bbf71a29711ba1c5f052032a17d7895e4 100644
--- a/include.preload.js
+++ b/include.preload.js
@@ -334,6 +334,26 @@ ElementHidingTracer.prototype = {
}
};
+function enforceStyleSheetRules(style)
+{
+ style.id = id;
+ injectJS(
+ function(id)
+ {
+ var style = document.getElementById(id) ||
+ document.documentElement.shadowRoot.getElementById(id);
+ style.removeAttribute("id");
+
+ Object.defineProperty(style.sheet, "disabled",
Sebastian Noack 2016/08/04 20:44:23 Where did the code go, that addressed deleteRule a
kzar 2016/08/05 11:01:57 This review is based upon the changes in a couple
+ {value: false, enumerable: true});
+
+ for (var i = 0; i < style.sheet.rules.length; i += 1)
+ Object.defineProperty(style.sheet.rules[i].style, "display",
Sebastian Noack 2016/08/04 20:44:23 How about overriding style.sheet.rules (and sheet.
kzar 2016/08/05 11:01:57 Cool idea, but I actually had to overwrite the get
+ {value: "none", enumerable: true});
+ }, id
+ );
+}
+
function reinjectStyleSheetWhenRemoved(document, style)
{
if (!MutationObserver)
@@ -350,19 +370,9 @@ function reinjectStyleSheetWhenRemoved(document, style)
if (style.sheet.rules.length == 0)
{
for (var i = 0; i < rules.length; i += 1)
- style.sheet.addRule(rules[i].selectorText, "display: none !important;");
+ style.sheet.addRule(rules[i].selectorText);
- style.id = id;
- injectJS(
- function(id)
- {
- var style = document.getElementById(id) ||
- document.documentElement.shadowRoot.getElementById(id);
- style.removeAttribute("id");
- Object.defineProperty(style.sheet, "disabled",
- {value: false, enumerable: true});
- }, id
- );
+ enforceStyleSheetRules(style);
}
}
});
@@ -595,8 +605,9 @@ function init(document)
for (var i = 0; i < selectors.length; i += SELECTOR_GROUP_SIZE)
{
var selector = selectors.slice(i, i + SELECTOR_GROUP_SIZE).join(", ");
- style.sheet.addRule(selector, "display: none !important;");
+ style.sheet.addRule(selector);
}
+ enforceStyleSheetRules(style);
};
var updateStylesheet = function()
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld