Skip to content

Commit

Permalink
add hacky call-out for custom element to upgrade during instance crea…
Browse files Browse the repository at this point in the history
…tion (cloneNode)

BUG=

Review URL: https://codereview.appspot.com/8291043
  • Loading branch information
rafaelw committed Apr 2, 2013
1 parent fbb825b commit c22bcf7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/template_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,13 @@

function createInstance(element, model, delegate) {
var content = element.ref ? element.ref.content : element.content;
return createDeepCloneAndDecorateTemplates(content);
var instance = createDeepCloneAndDecorateTemplates(content);
// TODO(rafaelw): This is a hack, and is neccesary for the polyfil
// because custom elements are not upgraded during cloneNode()
if (typeof HTMLTemplateElement.__instanceCreated == 'function') {
HTMLTemplateElement.__instanceCreated(instance);
}
return instance;
}

mixin(HTMLTemplateElement.prototype, {
Expand Down
17 changes: 17 additions & 0 deletions tests/template_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -1429,4 +1429,21 @@ suite('Template Element', function() {
assert.strictEqual(1, template3.content.childNodes.length);
assert.strictEqual('Hello', template3.content.firstChild.textContent);
});

test('__instanceCreated() hack', function() {
var called = false;
HTMLTemplateElement.__instanceCreated = function(node) {
assert.strictEqual(Node.DOCUMENT_FRAGMENT_NODE, node.nodeType);
called = true;
}

var div = createTestHtml('<template bind="{{}}">Foo</template>');
assert.isFalse(called);

HTMLTemplateElement.bindTree(div);
Model.notifyChanges();
assert.isTrue(called);

HTMLTemplateElement.__instanceCreated = undefined;
});
});

0 comments on commit c22bcf7

Please sign in to comment.