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

Commit

Permalink
template ref should check treeScope.getElementById
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelw committed May 18, 2013
1 parent 2c675ca commit 7de0697
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/template_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@

var filter = Array.prototype.filter.call.bind(Array.prototype.filter);

function getTreeScope(node) {
while (node.parentNode) {
node = node.parentNode;
}

return typeof node.getElementById === 'function' ? node : null;
}

var Map;
if (global.Map && typeof global.Map.prototype.forEach === 'function') {
Map = global.Map;
Expand Down Expand Up @@ -839,8 +847,11 @@
get ref() {
var ref;
var refId = this.getAttribute('ref');
if (refId)
ref = this.ownerDocument.getElementById(refId);
if (refId) {
var treeScope = getTreeScope(this);
if (treeScope)
ref = treeScope.getElementById(refId);
}

if (!ref)
ref = templateInstanceRefTable.get(this);
Expand Down
10 changes: 10 additions & 0 deletions tests/template_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,16 @@ suite('Template Element', function() {
}
});

test('BindShadowDOM Template Ref', function() {
if (HTMLElement.prototype.webkitCreateShadowRoot) {
var root = createShadowTestHtml(
'<template id=foo>Hi</template><template bind ref=foo></template>');
recursivelySetTemplateModel(root, {});
Platform.performMicrotaskCheckpoint();
assert.strictEqual(3, root.childNodes.length);
}
});

// https://github.com/Polymer/mdv/issues/8
test('UnbindingInNestedBind', function() {
var div = createTestHtml(
Expand Down

0 comments on commit 7de0697

Please sign in to comment.