| Index: third_party/polymer/v0_8/components/polymer/src/lib/expr/style-protector.html
|
| diff --git a/third_party/polymer/v0_8/components/polymer/src/lib/expr/style-protector.html b/third_party/polymer/v0_8/components/polymer/src/lib/expr/style-protector.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3a72b4a53b6c34baa9bb62ed361b2723f7c82882
|
| --- /dev/null
|
| +++ b/third_party/polymer/v0_8/components/polymer/src/lib/expr/style-protector.html
|
| @@ -0,0 +1,52 @@
|
| +<link rel="import" href="../lib/x-style.html">
|
| +<script>
|
| +(function() {
|
| +
|
| + var transformer = document.createElement('style', 'x-style');
|
| +
|
| + var styleProtector = {
|
| +
|
| + scopeDocumentSheets: function() {
|
| + this.scopeSheets(this.getSheetsToScope());
|
| + },
|
| +
|
| + getSheetsToScope: function() {
|
| + var s$ = document.styleSheets;
|
| + return Array.prototype.filter.call(s$, function(s) {
|
| + return s.ownerNode.hasAttribute(this.SCOPE_ATTR);
|
| + }, this);
|
| + },
|
| +
|
| + scopeSheets: function(sheets) {
|
| + for (var i=0, l=sheets.length, s; (i<l) && (s=sheets[i]); i++) {
|
| + this.scopeSheet(s);
|
| + }
|
| + },
|
| +
|
| + scopeSheet: function(sheet) {
|
| + var owner = sheet.ownerNode;
|
| + var cssText = transformer.scopeCssText(this.rulesToCss(sheet.cssRules));
|
| + if (owner.localName === 'link') {
|
| + var style = document.createElement('style');
|
| + style.textContent = cssText;
|
| + owner.parentNode.insertBefore(style, owner);
|
| + owner.parentNode.removeChild(owner);
|
| + } else {
|
| + owner.textContent = cssText;
|
| + }
|
| + },
|
| +
|
| + rulesToCss: function(cssRules) {
|
| + for (var i=0, css=[]; i < cssRules.length; i++) {
|
| + css.push(cssRules[i].cssText);
|
| + }
|
| + return css.join('\n\n');
|
| + },
|
| +
|
| + SCOPE_ATTR: 'needs-scoping'
|
| + };
|
| +
|
| + addEventListener('DOMContentLoaded', styleProtector.scopeDocumentSheets());
|
| +
|
| +})();
|
| +</script>
|
|
|