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

Unified Diff: include.preload.js

Issue 29348917: Issue 4191 - Restore rules for reinjected stylesheets (Closed)
Patch Set: Created July 29, 2016, 9:34 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 0c8935a745eb8fc7ce9d07111c34bc0f6befd3e9..bb6b97a01c6d5cc7bff5dc9ab8ca8285880f89bc 100644
--- a/include.preload.js
+++ b/include.preload.js
@@ -339,11 +339,32 @@ function reinjectStyleSheetWhenRemoved(document, style)
if (!MutationObserver)
return null;
+ var rules = style.sheet.rules;
var parentNode = style.parentNode;
var observer = new MutationObserver(function()
{
if (style.parentNode != parentNode)
+ {
parentNode.appendChild(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.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
+ );
+ }
+ }
});
observer.observe(parentNode, {childList: true});
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld