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

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Nov 26, 2013
1 parent 10721ad commit 45a73ff
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,25 @@ var importParser = {
script: 'parseScript',
style: 'parseGeneric'
},
// TODO(sorvell): because dynamic imports are not supported, users are
// writing code like in https://github.com/Polymer/HTMLImports/issues/40
// as a workaround. The code here checking for the existence of
// document.scripts is here only to support the workaround.
parse: function(document) {
if (!document.__importParsed) {
// only parse once
document.__importParsed = true;
// all parsable elements in inDocument (depth-first pre-order traversal)
var elts = document.querySelectorAll(importParser.selectors);
// memoize the number of scripts
var scriptCount = document.scripts.length;
var scriptCount = document.scripts ? document.scripts.length : 0;
// for each parsable node type, call the mapped parsing method
for (var i=0, e; i<elts.length && (e=elts[i]); i++) {
importParser[importParser.map[e.localName]](e);
// if a script was injected, we need to requery our nodes
// TODO(sjmiles): injecting nodes above the current script will
// result in errors
if (scriptCount !== document.scripts.length) {
if (document.scripts && scriptCount !== document.scripts.length) {
// memoize the new count
scriptCount = document.scripts.length;
// ensure we have any new nodes in our list
Expand Down
30 changes: 30 additions & 0 deletions test/html/dynamic.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!doctype html>
<html>
<head>
<title>HTML Imports Dynamic</title>
<script src="../../../tools/test/htmltest.js"></script>
<script src="../../../tools/test/chai/chai.js"></script>
<script src="../../html-imports.js"></script>
</head>
<body>

<script>
document.addEventListener('DOMContentLoaded', function() {
// some time later
setTimeout(function() {
var div = document.createElement('div');
div.innerHTML = '<link rel="import" href="imports/load-1.html">' +
'<link rel="import" href="imports/load-2.html">';
document.body.appendChild(div);
// TODO(sorvell): workaround for missing support for dynamic imports.
HTMLImports.importer.load(div, function() {
HTMLImports.parser.parse(div);
chai.assert.ok(load1, 'dynamic import loaded');
chai.assert.ok(load2, 'dynamic import loaded');
done();
});
});
});
</script>
</body>
</html>

0 comments on commit 45a73ff

Please sign in to comment.