diff --git a/src/elements/element.html b/src/elements/element.html index 7379ac9497..9ca732b347 100644 --- a/src/elements/element.html +++ b/src/elements/element.html @@ -115,13 +115,8 @@ this.createProperties(config.properties); this.createMethodObservers(config.observers); if (this.template) { - var template = this.prepareTemplate(this.template); - // TODO(dfreedm): remove when style stuff is refactored - // away from using element as input. - proto.__notStyleScopeCacheable = template.__notStyleScopeCacheable; - this.data.clearPropagateEffects(proto); - this.data.bindTemplate(proto, template); - proto._template = template; + var template = this.template.cloneNode(true); + this.finalizeTemplate(template); } } } @@ -135,12 +130,16 @@ // TODO(sorvell): support more ways to acquire template. // this requires `is` on constructor... this._template = Polymer.DomModule.import(this.is, - 'template', this.__importDoc || document); + 'template', this.__importDoc || document) || + // note: implemented so a subclass can retrieve the super + // template; call the super impl this way so that `this` points + // to the superclass. + Object.getPrototypeOf(this.prototype).constructor.template; } return this._template; } - static prepareTemplate(template) { + static finalizeTemplate(template) { // TODO(sorvell): remove need for this... Polymer.CompatStyleUtil.normalizeForBC(template.content); // TODO(sorvell): cannot use `this` here, refactor this to only do @@ -155,8 +154,13 @@ __placeholder: this.__placeholder, } Polymer.StyleLib.prepareTemplate(info, template); - template.__notStyleScopeCacheable = info.__notStyleScopeCacheable; - return template; + // TODO(dfreedm): remove when style stuff is refactored + // away from using element as input. + var proto = this.prototype; + proto.__notStyleScopeCacheable = info.__notStyleScopeCacheable; + this.data.clearPropagateEffects(proto); + this.data.bindTemplate(proto, template); + proto._template = template; } constructor() { diff --git a/src/shady/element-mixin.html b/src/shady/element-mixin.html index 47d695b2a2..f720025b47 100644 --- a/src/shady/element-mixin.html +++ b/src/shady/element-mixin.html @@ -548,15 +548,19 @@ }, cloneNode: function(deep) { - var n = nativeCloneNode.call(this, false); - if (deep) { - var c$ = this.childNodes; - for (var i=0, nc; i < c$.length; i++) { - nc = c$[i].cloneNode(true); - n.appendChild(nc); + if (this.localName == 'template') { + return nativeCloneNode.call(this, deep); + } else { + var n = nativeCloneNode.call(this, false); + if (deep) { + var c$ = this.childNodes; + for (var i=0, nc; i < c$.length; i++) { + nc = c$[i].cloneNode(true); + n.appendChild(nc); + } } + return n; } - return n; }, importNode: function(externalNode, deep) { diff --git a/test/runner.html b/test/runner.html index 7b7112a0b1..f0b4fa6c11 100644 --- a/test/runner.html +++ b/test/runner.html @@ -43,6 +43,7 @@ 'unit/polymer.element.html', 'unit/polymer.compatelement.html', 'unit/debounce.html', + 'unit/inheritance.html', 'unit/path.html', 'unit/dom-repeat.html', 'unit/dom-if.html' diff --git a/test/smoke/polymer.element.html b/test/smoke/polymer.element.html index 3b95aff860..27f49fb977 100644 --- a/test/smoke/polymer.element.html +++ b/test/smoke/polymer.element.html @@ -19,12 +19,17 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +