From bd2f5912168d319de76c4e5c81777516cdf25cca Mon Sep 17 00:00:00 2001 From: Steve Orvell Date: Thu, 21 Nov 2013 09:19:29 -0800 Subject: [PATCH] =?UTF-8?q?Restore=20compatibility=20between=20TemplateBin?= =?UTF-8?q?ding=20and=20Custom=20Elements=20polyfill.=20TemplateBinding=20?= =?UTF-8?q?now=20uses=20a=20staging=20document=20for=20creating=20elements?= =?UTF-8?q?.=20Elements=20should=20be=20upgraded=20there.=20Custom=20Eleme?= =?UTF-8?q?nts=20requires=20manually=20setting=20up=20documents=20to=20sup?= =?UTF-8?q?port=20custom=20elements.=20To=20solve=20this=20generally,=20th?= =?UTF-8?q?is=20requirement=20could=20be=20removed.=20Alternatively,=20Tem?= =?UTF-8?q?plateBinding=20could=20be=20setup=20to=20work=20with=20the=20CE?= =?UTF-8?q?=20polyfill.=20For=20simplicity=20we=E2=80=99ve=20directly=20pa?= =?UTF-8?q?tched=20importNode=20here.=20This=20is=20the=20mechanism=20Temp?= =?UTF-8?q?lateBinding=20uses=20to=20create=20dom=20in=20the=20staging=20d?= =?UTF-8?q?ocument.=20Also=20included=20is=20a=20temp=20workaround=20for?= =?UTF-8?q?=20SD=20polyfill=20support=20for=20importNode.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/patches-mdv.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/patches-mdv.js b/src/patches-mdv.js index 9f2138c..310a637 100644 --- a/src/patches-mdv.js +++ b/src/patches-mdv.js @@ -35,6 +35,24 @@ window.addEventListener('WebComponentsReady', function() { } }); + +if (window.CustomElements && !CustomElements.useNative) { + var originalImportNode = Document.prototype.importNode; + Document.prototype.importNode = function(node, deep) { + // TODO(sorvell): remove these conditionals when polyfill supports importNode + // https://github.com/Polymer/ShadowDOM/issues/317 + if (window.ShadowDOMPolyfill) { + node = ShadowDOMPolyfill.unwrap(node); + } + var imported = originalImportNode.call(this, node, deep); + CustomElements.upgradeAll(imported); + if (window.ShadowDOMPolyfill) { + imported = ShadowDOMPolyfill.wrap(imported); + } + return imported; + } +} + // exports scope.flush = flush;