Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
add shim support for scope styles
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Mar 7, 2014
1 parent a867522 commit 55e5fd7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
3 changes: 3 additions & 0 deletions src/declaration/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@

function applyStyleToScope(style, scope) {
if (style) {
if (window.ShadowDOMPolyfill) {
scope = document.head;
}
// TODO(sorvell): necessary for IE
// see https://connect.microsoft.com/IE/feedback/details/790212/
// cloning-a-style-element-and-adding-to-document-produces
Expand Down
27 changes: 12 additions & 15 deletions src/instance/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
return;
}
if (window.ShadowDOMPolyfill) {
cssText = shimCssText(cssText, scope);
cssText = shimCssText(cssText, scope.host);
}
var style = this.element.cssTextToScopeStyle(cssText,
STYLE_CONTROLLER_SCOPE);
Expand All @@ -66,16 +66,12 @@
scope._scopeStyles[this.localName + name] = true;
},
findStyleScope: function() {
if (window.ShadowDOMPolyfill) {
return wrap(document.head);
} else {
// find the shadow root that contains this element
var n = this;
while (n.parentNode) {
n = n.parentNode;
}
return n === document ? document.head : n;
// find the shadow root that contains this element
var n = this;
while (n.parentNode) {
n = n.parentNode;
}
return n;
},
scopeHasNamedStyle: function(scope, name) {
scope._scopeStyles = scope._scopeStyles || {};
Expand All @@ -89,12 +85,13 @@
return prototype.__proto__;
}

function shimCssText(cssText, scope) {
if (scope === document.head) {
return cssText;
function shimCssText(cssText, host) {
var name = '', is = false;
if (host) {
name = host.localName;
is = host.hasAttribute('is');
}
var selector = Platform.ShadowCSS.makeScopeSelector(scope.localName,
scope.hasAttribute('is'));
var selector = Platform.ShadowCSS.makeScopeSelector(name, is);
return Platform.ShadowCSS.shimCssText(cssText, selector);
}

Expand Down

0 comments on commit 55e5fd7

Please sign in to comment.