This repository was archived by the owner on Mar 13, 2018. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,21 +23,25 @@ var importParser = {
2323 script : 'parseScript' ,
2424 style : 'parseGeneric'
2525 } ,
26+ // TODO(sorvell): because dynamic imports are not supported, users are
27+ // writing code like in https://github.com/Polymer/HTMLImports/issues/40
28+ // as a workaround. The code here checking for the existence of
29+ // document.scripts is here only to support the workaround.
2630 parse : function ( document ) {
2731 if ( ! document . __importParsed ) {
2832 // only parse once
2933 document . __importParsed = true ;
3034 // all parsable elements in inDocument (depth-first pre-order traversal)
3135 var elts = document . querySelectorAll ( importParser . selectors ) ;
3236 // memoize the number of scripts
33- var scriptCount = document . scripts . length ;
37+ var scriptCount = document . scripts ? document . scripts . length : 0 ;
3438 // for each parsable node type, call the mapped parsing method
3539 for ( var i = 0 , e ; i < elts . length && ( e = elts [ i ] ) ; i ++ ) {
3640 importParser [ importParser . map [ e . localName ] ] ( e ) ;
3741 // if a script was injected, we need to requery our nodes
3842 // TODO(sjmiles): injecting nodes above the current script will
3943 // result in errors
40- if ( scriptCount !== document . scripts . length ) {
44+ if ( document . scripts && scriptCount !== document . scripts . length ) {
4145 // memoize the new count
4246 scriptCount = document . scripts . length ;
4347 // ensure we have any new nodes in our list
Original file line number Diff line number Diff line change 1+ <!doctype html>
2+ < html >
3+ < head >
4+ < title > HTML Imports Dynamic</ title >
5+ < script src ="../../../tools/test/htmltest.js "> </ script >
6+ < script src ="../../../tools/test/chai/chai.js "> </ script >
7+ < script src ="../../html-imports.js "> </ script >
8+ </ head >
9+ < body >
10+
11+ < script >
12+ document . addEventListener ( 'DOMContentLoaded' , function ( ) {
13+ // some time later
14+ setTimeout ( function ( ) {
15+ var div = document . createElement ( 'div' ) ;
16+ div . innerHTML = '<link rel="import" href="imports/load-1.html">' +
17+ '<link rel="import" href="imports/load-2.html">' ;
18+ document . body . appendChild ( div ) ;
19+ // TODO(sorvell): workaround for missing support for dynamic imports.
20+ HTMLImports . importer . load ( div , function ( ) {
21+ HTMLImports . parser . parse ( div ) ;
22+ chai . assert . ok ( load1 , 'dynamic import loaded' ) ;
23+ chai . assert . ok ( load2 , 'dynamic import loaded' ) ;
24+ done ( ) ;
25+ } ) ;
26+ } ) ;
27+ } ) ;
28+ </ script >
29+ </ body >
30+ </ html >
You can’t perform that action at this time.
0 commit comments