44 * license that can be found in the LICENSE file.
55 */
66
7- ( function ( ) {
7+ ( function ( scope ) {
8+
9+ if ( ! scope ) {
10+ scope = window . HTMLImports = { flags :{ } } ;
11+ }
812
913var IMPORT_LINK_TYPE = 'import' ;
1014
1115// highlander object represents a primary document (the argument to 'parse')
1216// at the root of a tree of documents
1317
14- var HTMLImports = {
18+ var importer = {
1519 documents : { } ,
1620 cache : { } ,
1721 preloadSelectors : [
@@ -21,15 +25,15 @@ var HTMLImports = {
2125 ] . join ( ',' ) ,
2226 load : function ( inDocument , inNext ) {
2327 // construct a loader instance
24- loader = new Loader ( HTMLImports . loaded , inNext ) ;
28+ loader = new Loader ( importer . loaded , inNext ) ;
2529 // alias the loader cache (for debugging)
26- loader . cache = HTMLImports . cache ;
30+ loader . cache = importer . cache ;
2731 // add nodes from document into loader queue
28- HTMLImports . preload ( inDocument ) ;
32+ importer . preload ( inDocument ) ;
2933 } ,
3034 preload : function ( inDocument ) {
3135 // all preloadable nodes in inDocument
32- var nodes = inDocument . querySelectorAll ( HTMLImports . preloadSelectors ) ;
36+ var nodes = inDocument . querySelectorAll ( importer . preloadSelectors ) ;
3337 // only load imports from the main document
3438 // TODO(sjmiles): do this by altering the selector list instead
3539 if ( inDocument === document ) {
@@ -42,17 +46,17 @@ var HTMLImports = {
4246 } ,
4347 loaded : function ( inUrl , inElt , inResource ) {
4448 if ( isDocumentLink ( inElt ) ) {
45- var document = HTMLImports . documents [ inUrl ] ;
49+ var document = importer . documents [ inUrl ] ;
4650 // if we've never seen a document at this url
4751 if ( ! document ) {
4852 // generate an HTMLDocument from data
4953 document = makeDocument ( inResource , inUrl ) ;
5054 // resolve resource paths relative to host document
5155 path . resolvePathsInHTML ( document ) ;
5256 // cache document
53- HTMLImports . documents [ inUrl ] = document ;
57+ importer . documents [ inUrl ] = document ;
5458 // add nodes from this document to the loader queue
55- HTMLImports . preload ( document ) ;
59+ importer . preload ( document ) ;
5660 }
5761 // store document resource
5862 inElt . content = inElt . __resource = document ;
@@ -315,7 +319,10 @@ var xhr = {
315319 } ,
316320 load : function ( url , next , nextContext ) {
317321 var request = new XMLHttpRequest ( ) ;
318- request . open ( 'GET' , url + '?' + Math . random ( ) , xhr . async ) ;
322+ if ( scope . flags . debug || scope . flags . bust ) {
323+ url += '?' + Math . random ( ) ;
324+ }
325+ request . open ( 'GET' , url , xhr . async ) ;
319326 request . addEventListener ( 'readystatechange' , function ( e ) {
320327 if ( request . readyState === 4 ) {
321328 next . call ( nextContext , ! xhr . ok ( request ) && request ,
@@ -329,8 +336,9 @@ var xhr = {
329336var forEach = Array . prototype . forEach . call . bind ( Array . prototype . forEach ) ;
330337
331338// exports
332- window . HTMLImports = HTMLImports ;
333- window . HTMLImports . getDocumentUrl = path . getDocumentUrl ;
339+
340+ scope . importer = importer ;
341+ scope . getDocumentUrl = path . getDocumentUrl ;
334342
335343// bootstrap
336344
@@ -345,7 +353,7 @@ if (typeof window.CustomEvent !== 'function') {
345353
346354window . addEventListener ( 'load' , function ( ) {
347355 // preload document resource trees
348- HTMLImports . load ( document , function ( ) {
356+ importer . load ( document , function ( ) {
349357 // TODO(sjmiles): ShadowDOM polyfill pollution
350358 var doc = window . ShadowDOMPolyfill ? ShadowDOMPolyfill . wrap ( document )
351359 : document ;
@@ -357,4 +365,4 @@ window.addEventListener('load', function() {
357365 } ) ;
358366} ) ;
359367
360- } ) ( ) ;
368+ } ) ( window . HTMLImports ) ;
0 commit comments