Skip to content

Commit

Permalink
Polyfill for shadowRoot.styleSheets in Safari (#11267)
Browse files Browse the repository at this point in the history
* Polyfill for shadowRoot.styleSheets in Safari

* Use array instead of adding an index operator
  • Loading branch information
cvializ authored and zhouyx committed Sep 13, 2017
1 parent dbbeb84 commit 970d381
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/shadow-embed.js
Expand Up @@ -17,7 +17,12 @@
import {Services} from './services';
import {ShadowCSS} from '../third_party/webcomponentsjs/ShadowCSS';
import {dev} from './log';
import {closestNode, escapeCssSelectorIdent} from './dom';
import {
childElementsByTag,
closestNode,
escapeCssSelectorIdent,
iterateCursor,
} from './dom';
import {installCssTransformer} from './style-installer';
import {
isShadowDomSupported,
Expand Down Expand Up @@ -61,7 +66,19 @@ export function createShadowRoot(hostElement) {
// Native support.
const shadowDomSupported = getShadowDomSupportedVersion();
if (shadowDomSupported == ShadowDomVersion.V1) {
return hostElement.attachShadow({mode: 'open'});
const shadowRoot = hostElement.attachShadow({mode: 'open'});
if (!shadowRoot.styleSheets) {
Object.defineProperty(shadowRoot, 'styleSheets', {
get: function() {
const items = [];
iterateCursor(childElementsByTag(shadowRoot, 'style'), child => {
items.push(child.sheet);
});
return items;
},
});
}
return shadowRoot;
} else if (shadowDomSupported == ShadowDomVersion.V0) {
return hostElement.createShadowRoot();
}
Expand Down

0 comments on commit 970d381

Please sign in to comment.