Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix(jqLite): traverse host property for DocumentFragment in inherit…
Browse files Browse the repository at this point in the history
…edData()

If dealing with a document fragment node with a host element, and no parent, use the host
element as the parent. This enables directives within a Shadow DOM or polyfilled Shadow DOM
to lookup parent controllers.

Closes #6637
  • Loading branch information
caitp authored and vojtajina committed Mar 21, 2014
1 parent 57b0d91 commit 98d825e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,15 @@ function jqLiteInheritedData(element, name, value) {
var names = isArray(name) ? name : [name];

while (element.length) {

var node = element[0];
for (var i = 0, ii = names.length; i < ii; i++) {
if ((value = element.data(names[i])) !== undefined) return value;
}
element = element.parent();

// If dealing with a document fragment node with a host element, and no parent, use the host
// element as the parent. This enables directives within a Shadow DOM or polyfilled Shadow DOM
// to lookup parent controllers.
element = jqLite(node.parentNode || (node.nodeType === 11 && node.host));
}
}

Expand Down
13 changes: 13 additions & 0 deletions test/jqLiteSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,19 @@ describe('jqLite', function() {

dealoc(ul);
});

it('should pass through DocumentFragment boundaries via host', function() {
var host = jqLite('<div></div>'),
frag = document.createDocumentFragment(),
$frag = jqLite(frag);
frag.host = host[0];
host.data("foo", 123);
host.append($frag);
expect($frag.inheritedData("foo")).toBe(123);

dealoc(host);
dealoc($frag);
});
});


Expand Down

0 comments on commit 98d825e

Please sign in to comment.