Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Unified Diff: third_party/polymer/v0_8/components-chromium/polymer/src/lib/expr/style-protector-extracted.js

Issue 1082403004: Import Polymer 0.8 and several key elements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Also remove polymer/explainer Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/polymer/v0_8/components-chromium/polymer/src/lib/expr/style-protector-extracted.js
diff --git a/third_party/polymer/v0_8/components-chromium/polymer/src/lib/expr/style-protector-extracted.js b/third_party/polymer/v0_8/components-chromium/polymer/src/lib/expr/style-protector-extracted.js
new file mode 100644
index 0000000000000000000000000000000000000000..c47726f148cbb7c194c8d73883d91da519aa937a
--- /dev/null
+++ b/third_party/polymer/v0_8/components-chromium/polymer/src/lib/expr/style-protector-extracted.js
@@ -0,0 +1,50 @@
+
+(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());
+
+})();

Powered by Google App Engine
This is Rietveld 408576698