From c93c9f21fa309128c6e27ab665c87451913c5313 Mon Sep 17 00:00:00 2001 From: Koen Kivits Date: Tue, 8 Dec 2015 21:16:33 +0100 Subject: [PATCH 01/19] Improve README documentation on CSS encapsulation Should fix #451 and #458 to some extent. --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 9cf692f72..7319f7409 100644 --- a/README.md +++ b/README.md @@ -90,11 +90,25 @@ window.addEventListener('WebComponentsReady', function(e) { ## Known Issues + * [Limited CSS encapsulation](#encapsulation) * [Custom element's constructor property is unreliable](#constructor) * [Contenteditable elements do not trigger MutationObserver](#contentedit) * [ShadowCSS: :host-context(...):host(...) doesn't work](#hostcontext) * [execCommand isn't supported under Shadow DOM](#execcommand) +### Limited CSS encapsulation +Under native Shadow DOM, CSS selectors cannot cross the shadow boundary. This means document level styles don't apply to shadow roots, and styles defined within a shadow root don't apply outside of that shadow root. [Several selectors](http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom-201/) are provided to be able to deal with the shadow boundary. + +The Shadow DOM polyfill can't prevent document styles from leaking into shadow roots. It can, however, encapsulate styles within shadow roots to some extent. This behavior isn't automatically emulated by the Shadow DOM polyfill, but it can be achieved by manually using the included ShadowCSS shim: + +``` +WebComponents.ShadowCSS.shimStyling( shadowRoot, scope ); +``` + +... where `shadowRoot` is the shadow root of a DOM element, and `scope` is the name of the scope used to prefix the selectors. This removes all ` + +
+ +
From 3af33f74a2485b7309328248d6f6c472f23896da Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Tue, 9 Feb 2016 18:37:36 -0800 Subject: [PATCH 08/19] Template polypill: (a) support template.cloneNode and (b) document.importNode(template). Supports nested templates. --- src/Template/Template.js | 37 ++++++++++++++++ tests/Template/tests.html | 91 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 127 insertions(+), 1 deletion(-) diff --git a/src/Template/Template.js b/src/Template/Template.js index 5cf73edd7..6bcfa58cc 100644 --- a/src/Template/Template.js +++ b/src/Template/Template.js @@ -61,15 +61,52 @@ if (typeof HTMLTemplateElement === 'undefined') { }, configurable: true }); + + template.cloneNode = function(deep) { + return HTMLTemplateElement.cloneNode(this, deep); + }; + } catch (err) { canDecorate = false; } } + var nativeCloneNode = Node.prototype.cloneNode; + + HTMLTemplateElement.cloneNode = function(template, deep) { + var clone = nativeCloneNode.call(template); + this.decorate(clone); + if (deep) { + // NOTE: use native clone node to make sure CE's wrapped + // cloneNode does not cause elements to upgrade. + clone.content.appendChild( + nativeCloneNode.call(template.content, true)); + // these two lists should be coincident + var s$ = template.content.querySelectorAll(TEMPLATE_TAG); + var t$ = clone.content.querySelectorAll(TEMPLATE_TAG); + for (var i=0, l=t$.length, t, s; i + document.importNode = function(element, deep) { + return (element.localName === TEMPLATE_TAG) ? + HTMLTemplateElement.cloneNode(element, deep) : + originalImportNode.call(document, element, deep); + }; + /** The `bootstrap` method is called automatically and "fixes" all