Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Merge pull request #218 from arv/template-element-extract-in-wrapper
Browse files Browse the repository at this point in the history
Extract template content in the wrapper
  • Loading branch information
dfreedm committed Aug 22, 2013
2 parents e4c51df + 52f5c4c commit cfe0a09
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/wrappers/HTMLTemplateElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
var mixin = scope.mixin;
var registerWrapper = scope.registerWrapper;
var setInnerHTML = scope.setInnerHTML;
var unwrap = scope.unwrap;
var wrap = scope.wrap;

var contentTable = new SideTable();
Expand All @@ -33,9 +34,9 @@
}

function extractContent(templateElement) {
// templateElement is not a wrapper here.
var doc = getTemplateContentsOwner(templateElement.ownerDocument);
var df = doc.createDocumentFragment();
var nextSibling;
var df = unwrap(doc.createDocumentFragment());
var child;
while (child = templateElement.firstChild) {
df.appendChild(child);
Expand All @@ -47,23 +48,18 @@

function HTMLTemplateElement(node) {
HTMLElement.call(this, node);
if (!OriginalHTMLTemplateElement) {
var content = extractContent(node);
contentTable.set(this, wrap(content));
}
}
HTMLTemplateElement.prototype = Object.create(HTMLElement.prototype);

mixin(HTMLTemplateElement.prototype, {
get content() {
if (OriginalHTMLTemplateElement)
return wrap(this.impl.content);

// TODO(arv): This should be done in createCallback. I initially tried to
// do this in the constructor but the wrapper is not yet created at that
// point in time so we hit an iloop.
var content = contentTable.get(this);
if (!content) {
content = extractContent(this);
contentTable.set(this, content);
}
return content;
return contentTable.get(this);
},

get innerHTML() {
Expand Down

0 comments on commit cfe0a09

Please sign in to comment.