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

Commit

Permalink
correct timing of HTMLImports parsing hook installation and add test. F…
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Aug 18, 2014
1 parent 4e1c235 commit 65bb151
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ function bootstrap() {
CustomElements.parser.parse(document);
// one more pass before register is 'live'
CustomElements.upgradeDocument(document);
// install upgrade hook if HTMLImports are available
if (window.HTMLImports) {
HTMLImports.__importsParsingHook = function(elt) {
CustomElements.parser.parse(elt.import);
}
}
// set internal 'ready' flag, now document.registerElement will trigger
// synchronous upgrades
CustomElements.ready = true;
Expand All @@ -30,13 +36,6 @@ function bootstrap() {
document.dispatchEvent(
new CustomEvent('WebComponentsReady', {bubbles: true})
);

// install upgrade hook if HTMLImports are available
if (window.HTMLImports) {
HTMLImports.__importsParsingHook = function(elt) {
CustomElements.parser.parse(elt.import);
}
}
});
}

Expand Down
46 changes: 46 additions & 0 deletions test/html/imports.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!doctype html>
<html>
<head>
<title>Custom Elements: imports integration</title>
<script src="../../../tools/test/htmltest.js"></script>
<script src="../../../tools/test/chai/chai.js"></script>
<script>
HTMLImports = {};

var elementsCreated = 0;

addEventListener('load', function() {
setTimeout(function() {
document.dispatchEvent(new CustomEvent('HTMLImportsLoaded', {bubbles: true}));
// parsing hook available
chai.assert.ok(HTMLImports.__importsParsingHook, 'imports parsing hook installed');
//
var doc = document.implementation.createHTMLDocument('Foo');
doc.body.innerHTML = '<x-foo></x-foo>';
var link = document.createElement('mock-link');
link.import = doc;
HTMLImports.__importsParsingHook(link);
//
addEventListener('WebComponentsReady', function() {
chai.assert.equal(2, elementsCreated, 'HTML hook allows main document and import document to upgrade');
done();
})
}, 1);
});
</script>
<script src="../../custom-elements.js"></script>
<script>
(function() {
var proto = Object.create(HTMLElement.prototype);
proto.createdCallback = function() {
elementsCreated++;
}

document.registerElement('x-foo', {prototype: proto});
})();
</script>
</head>
<body>
<x-foo></x-foo>
</body>
</html>
1 change: 1 addition & 0 deletions test/js/customElements.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,4 +522,5 @@ htmlSuite('customElements (html)', function() {
htmlTest('html/attributes.html');
htmlTest('html/upgrade-order.html');
htmlTest('html/upgrade-dcl.html');
htmlTest('html/imports.html');
});

0 comments on commit 65bb151

Please sign in to comment.