diff --git a/src/lib/style-util.html b/src/lib/style-util.html
index 1fd3845f42..82c6eeec41 100644
--- a/src/lib/style-util.html
+++ b/src/lib/style-util.html
@@ -17,6 +17,8 @@
var settings = Polymer.Settings;
return {
+ unscopedStyleImports: new WeakMap(),
+ SHADY_UNSCOPED_ATTR: 'shady-unscoped',
// chrome 49 has semi-working css vars, check if box-shadow works
// safari 9.1 has a recalc bug: https://bugs.webkit.org/show_bug.cgi?id=155782
NATIVE_VARIABLES: Polymer.Settings.useNativeCSSProperties,
@@ -211,12 +213,34 @@
// get style element applied to main doc via HTMLImports polyfill
e = e.__appliedElement || e;
e.parentNode.removeChild(e);
- cssText += this.resolveCss(e.textContent, element.ownerDocument);
+ var css = this.resolveCss(e.textContent, element.ownerDocument);
+ // support: unscoped styles
+ if (!settings.useNativeShadow &&
+ e.hasAttribute(this.SHADY_UNSCOPED_ATTR)) {
+ e.textContent = css;
+ document.head.insertBefore(e, document.head.firstChild);
+ } else {
+ cssText += css;
+ }
// it's an import, assume this is a text file of css content.
// TODO(sorvell): plan is to deprecate this way to get styles;
// remember to add deprecation warning when this is done.
} else if (e.import && e.import.body) {
- cssText += this.resolveCss(e.import.body.textContent, e.import);
+ var importCss = this.resolveCss(e.import.body.textContent, e.import);
+ // support: unscoped styles
+ // record imports in a WeakMap so they are de-duped if unscoped > 1x.
+ if (!settings.useNativeShadow &&
+ e.hasAttribute(this.SHADY_UNSCOPED_ATTR)) {
+ if (!this.unscopedStyleImports.has(e.import)) {
+ this.unscopedStyleImports.set(e.import, true);
+ var importStyle = document.createElement('style');
+ importStyle.setAttribute(this.SHADY_UNSCOPED_ATTR, '');
+ importStyle.textContent = importCss;
+ document.head.insertBefore(importStyle, document.head.firstChild);
+ }
+ } else {
+ cssText += importCss;
+ }
}
}
}
diff --git a/test/runner.html b/test/runner.html
index d18d6ba6ca..d72fbfcfc7 100644
--- a/test/runner.html
+++ b/test/runner.html
@@ -102,7 +102,11 @@
'unit/custom-style-transformed.html',
'unit/custom-style-transformed.html?dom=shadow',
'unit/custom-style-transformed.html?lazyRegister=true&useNativeCSSProperties=true',
- 'unit/custom-style-transformed.html?lazyRegister=true&useNativeCSSProperties=true&dom=shadow'
+ 'unit/custom-style-transformed.html?lazyRegister=true&useNativeCSSProperties=true&dom=shadow',
+ 'unit/shady-unscoped-style.html',
+ 'unit/shady-unscoped-style.html?dom=shadow',
+ 'unit/shady-unscoped-style.html?lazyRegister=true&useNativeCSSProperties=true',
+ 'unit/shady-unscoped-style.html?lazyRegister=true&useNativeCSSProperties=true&dom=shadow'
];
if ('import' in document.createElement('link') && (window.customElements || document.registerElement)) {
diff --git a/test/unit/shady-unscoped-style-import-css.html b/test/unit/shady-unscoped-style-import-css.html
new file mode 100644
index 0000000000..3e99a3189c
--- /dev/null
+++ b/test/unit/shady-unscoped-style-import-css.html
@@ -0,0 +1,3 @@
+.import {
+ border: 2px solid yellow;
+}
\ No newline at end of file
diff --git a/test/unit/shady-unscoped-style-import.html b/test/unit/shady-unscoped-style-import.html
new file mode 100644
index 0000000000..5fe5c6ae4f
--- /dev/null
+++ b/test/unit/shady-unscoped-style-import.html
@@ -0,0 +1,26 @@
+