Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit a15a25d

Browse files
Merge pull request #171 from WebReflection/no-template
Fix template issue
2 parents f044b20 + 58d2dc0 commit a15a25d

10 files changed

+84
-23
lines changed

build/document-register-element.amd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/document-register-element.esm.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,12 @@ export default function installCustomElements(window, polyfill) {'use strict';
641641

642642
attachShadow = HTMLElementPrototype.attachShadow,
643643
cloneNode = HTMLElementPrototype.cloneNode,
644+
closest = HTMLElementPrototype.closest || function (name) {
645+
var self = this;
646+
while (self && self.nodeName !== name)
647+
self = self.parentNode;
648+
return self;
649+
},
644650
dispatchEvent = HTMLElementPrototype.dispatchEvent,
645651
getAttribute = HTMLElementPrototype.getAttribute,
646652
hasAttribute = HTMLElementPrototype.hasAttribute,
@@ -1249,7 +1255,7 @@ export default function installCustomElements(window, polyfill) {'use strict';
12491255
i = getTypeIndex(node),
12501256
counterAction
12511257
;
1252-
if (-1 < i) {
1258+
if ((-1 < i) && !closest.call(node, 'TEMPLATE')) {
12531259
patchIfNotAlready(node, protos[i]);
12541260
i = 0;
12551261
if (action === ATTACHED && !node[ATTACHED]) {
@@ -1273,8 +1279,6 @@ export default function installCustomElements(window, polyfill) {'use strict';
12731279
}
12741280
}
12751281

1276-
1277-
12781282
// V1 in da House!
12791283
function CustomElementRegistry() {}
12801284

build/document-register-element.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/document-register-element.max.amd.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,12 @@ define(function(polyfill){'use strict';
638638

639639
attachShadow = HTMLElementPrototype.attachShadow,
640640
cloneNode = HTMLElementPrototype.cloneNode,
641+
closest = HTMLElementPrototype.closest || function (name) {
642+
var self = this;
643+
while (self && self.nodeName !== name)
644+
self = self.parentNode;
645+
return self;
646+
},
641647
dispatchEvent = HTMLElementPrototype.dispatchEvent,
642648
getAttribute = HTMLElementPrototype.getAttribute,
643649
hasAttribute = HTMLElementPrototype.hasAttribute,
@@ -1246,7 +1252,7 @@ define(function(polyfill){'use strict';
12461252
i = getTypeIndex(node),
12471253
counterAction
12481254
;
1249-
if (-1 < i) {
1255+
if ((-1 < i) && !closest.call(node, 'TEMPLATE')) {
12501256
patchIfNotAlready(node, protos[i]);
12511257
i = 0;
12521258
if (action === ATTACHED && !node[ATTACHED]) {
@@ -1270,8 +1276,6 @@ define(function(polyfill){'use strict';
12701276
}
12711277
}
12721278

1273-
1274-
12751279
// V1 in da House!
12761280
function CustomElementRegistry() {}
12771281

build/document-register-element.max.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,12 @@ PERFORMANCE OF THIS SOFTWARE.
638638

639639
attachShadow = HTMLElementPrototype.attachShadow,
640640
cloneNode = HTMLElementPrototype.cloneNode,
641+
closest = HTMLElementPrototype.closest || function (name) {
642+
var self = this;
643+
while (self && self.nodeName !== name)
644+
self = self.parentNode;
645+
return self;
646+
},
641647
dispatchEvent = HTMLElementPrototype.dispatchEvent,
642648
getAttribute = HTMLElementPrototype.getAttribute,
643649
hasAttribute = HTMLElementPrototype.hasAttribute,
@@ -1246,7 +1252,7 @@ PERFORMANCE OF THIS SOFTWARE.
12461252
i = getTypeIndex(node),
12471253
counterAction
12481254
;
1249-
if (-1 < i) {
1255+
if ((-1 < i) && !closest.call(node, 'TEMPLATE')) {
12501256
patchIfNotAlready(node, protos[i]);
12511257
i = 0;
12521258
if (action === ATTACHED && !node[ATTACHED]) {
@@ -1270,8 +1276,6 @@ PERFORMANCE OF THIS SOFTWARE.
12701276
}
12711277
}
12721278

1273-
1274-
12751279
// V1 in da House!
12761280
function CustomElementRegistry() {}
12771281

build/document-register-element.node.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,12 @@ function installCustomElements(window, polyfill) {'use strict';
641641

642642
attachShadow = HTMLElementPrototype.attachShadow,
643643
cloneNode = HTMLElementPrototype.cloneNode,
644+
closest = HTMLElementPrototype.closest || function (name) {
645+
var self = this;
646+
while (self && self.nodeName !== name)
647+
self = self.parentNode;
648+
return self;
649+
},
644650
dispatchEvent = HTMLElementPrototype.dispatchEvent,
645651
getAttribute = HTMLElementPrototype.getAttribute,
646652
hasAttribute = HTMLElementPrototype.hasAttribute,
@@ -1249,7 +1255,7 @@ function installCustomElements(window, polyfill) {'use strict';
12491255
i = getTypeIndex(node),
12501256
counterAction
12511257
;
1252-
if (-1 < i) {
1258+
if ((-1 < i) && !closest.call(node, 'TEMPLATE')) {
12531259
patchIfNotAlready(node, protos[i]);
12541260
i = 0;
12551261
if (action === ATTACHED && !node[ATTACHED]) {
@@ -1273,8 +1279,6 @@ function installCustomElements(window, polyfill) {'use strict';
12731279
}
12741280
}
12751281

1276-
1277-
12781282
// V1 in da House!
12791283
function CustomElementRegistry() {}
12801284

pony/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,12 @@ function installCustomElements(window, polyfill) {'use strict';
641641

642642
attachShadow = HTMLElementPrototype.attachShadow,
643643
cloneNode = HTMLElementPrototype.cloneNode,
644+
closest = HTMLElementPrototype.closest || function (name) {
645+
var self = this;
646+
while (self && self.nodeName !== name)
647+
self = self.parentNode;
648+
return self;
649+
},
644650
dispatchEvent = HTMLElementPrototype.dispatchEvent,
645651
getAttribute = HTMLElementPrototype.getAttribute,
646652
hasAttribute = HTMLElementPrototype.hasAttribute,
@@ -1249,7 +1255,7 @@ function installCustomElements(window, polyfill) {'use strict';
12491255
i = getTypeIndex(node),
12501256
counterAction
12511257
;
1252-
if (-1 < i) {
1258+
if ((-1 < i) && !closest.call(node, 'TEMPLATE')) {
12531259
patchIfNotAlready(node, protos[i]);
12541260
i = 0;
12551261
if (action === ATTACHED && !node[ATTACHED]) {
@@ -1273,8 +1279,6 @@ function installCustomElements(window, polyfill) {'use strict';
12731279
}
12741280
}
12751281

1276-
1277-
12781282
// V1 in da House!
12791283
function CustomElementRegistry() {}
12801284

pony/index.mjs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,12 @@ export default function installCustomElements(window, polyfill) {'use strict';
641641

642642
attachShadow = HTMLElementPrototype.attachShadow,
643643
cloneNode = HTMLElementPrototype.cloneNode,
644+
closest = HTMLElementPrototype.closest || function (name) {
645+
var self = this;
646+
while (self && self.nodeName !== name)
647+
self = self.parentNode;
648+
return self;
649+
},
644650
dispatchEvent = HTMLElementPrototype.dispatchEvent,
645651
getAttribute = HTMLElementPrototype.getAttribute,
646652
hasAttribute = HTMLElementPrototype.hasAttribute,
@@ -1249,7 +1255,7 @@ export default function installCustomElements(window, polyfill) {'use strict';
12491255
i = getTypeIndex(node),
12501256
counterAction
12511257
;
1252-
if (-1 < i) {
1258+
if ((-1 < i) && !closest.call(node, 'TEMPLATE')) {
12531259
patchIfNotAlready(node, protos[i]);
12541260
i = 0;
12551261
if (action === ATTACHED && !node[ATTACHED]) {
@@ -1273,8 +1279,6 @@ export default function installCustomElements(window, polyfill) {'use strict';
12731279
}
12741280
}
12751281

1276-
1277-
12781282
// V1 in da House!
12791283
function CustomElementRegistry() {}
12801284

src/document-register-element.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ var
208208

209209
attachShadow = HTMLElementPrototype.attachShadow,
210210
cloneNode = HTMLElementPrototype.cloneNode,
211+
closest = HTMLElementPrototype.closest || function (name) {
212+
var self = this;
213+
while (self && self.nodeName !== name)
214+
self = self.parentNode;
215+
return self;
216+
},
211217
dispatchEvent = HTMLElementPrototype.dispatchEvent,
212218
getAttribute = HTMLElementPrototype.getAttribute,
213219
hasAttribute = HTMLElementPrototype.hasAttribute,
@@ -816,7 +822,7 @@ function verifyAndSetupAndAction(node, action) {
816822
i = getTypeIndex(node),
817823
counterAction
818824
;
819-
if (-1 < i) {
825+
if ((-1 < i) && !closest.call(node, 'TEMPLATE')) {
820826
patchIfNotAlready(node, protos[i]);
821827
i = 0;
822828
if (action === ATTACHED && !node[ATTACHED]) {
@@ -840,8 +846,6 @@ function verifyAndSetupAndAction(node, action) {
840846
}
841847
}
842848

843-
844-
845849
// V1 in da House!
846850
function CustomElementRegistry() {}
847851

test/template.html

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script src="../build/document-register-element.max.js"></script>
5+
<script>
6+
var count = 0;
7+
document.registerElement('in-template', {
8+
prototype: Object.create(
9+
HTMLElement.prototype, {
10+
createdCallback: {value: function() {
11+
document.getElementById('count').innerHTML = ++count;
12+
this.innerHTML = count;
13+
}}
14+
})
15+
});
16+
</script>
17+
</head>
18+
<body>
19+
<p>
20+
Counter should be 2: <span id="count">0</span>
21+
</p>
22+
<template id="template"><in-template></in-template></template>
23+
<script>
24+
var template = document.getElementById('template');
25+
// This FAILS on Chrome with fix!:
26+
// document.body.appendChild(template.content.cloneNode(true));
27+
document.body.appendChild(document.createElement('in-template'));
28+
var div = document.createElement('div');
29+
div.innerHTML = template.innerHTML;
30+
document.body.appendChild(div);
31+
</script>
32+
</body>
33+
</html>

0 commit comments

Comments
 (0)