@@ -12,6 +12,7 @@ window.moduloPrevious = window.modulo;
12
12
window . Modulo = class Modulo {
13
13
constructor ( ) {
14
14
window . _moduloID = ( window . _moduloID || 0 ) + 1 ;
15
+ this . window = window ;
15
16
this . id = window . _moduloID ; // Every Modulo instance gets a unique ID.
16
17
this . _configSteps = 0 ; // Used to check for an infinite loop during load
17
18
this . registry = { cparts : { } , coreDefs : { } , utils : { } , core : { } ,
@@ -909,10 +910,11 @@ modulo.register('core', class FetchQueue {
909
910
resolve ( this . data [ src ] , src ) ; // (sync route)
910
911
} else if ( ! ( src in this . queue ) ) { // No cache, no queue
911
912
this . queue [ src ] = [ resolve ] ; // First time, create the queue Array
912
- let { callback, filePadding, force } = this . modulo . config . fetchqueue ;
913
- if ( src . startsWith ( 'file://' ) || force === 'file' ) {
914
- const auto = this . modulo . registry . stripWord ( filePadding . prefix ) ;
915
- window [ callback || auto ] = str => { this . __data = str } ;
913
+ const { force, filePadding } = this . modulo . config . fetchqueue ;
914
+ if ( filePadding && ( src . startsWith ( 'file:/' ) || force === 'file' ) ) {
915
+ const { prefix, callbackName } = filePadding ; // JSONP callback
916
+ const auto = this . modulo . registry . utils . stripWord ( prefix ) ;
917
+ window [ callbackName || auto ] = str => { this . __data = str } ;
916
918
const elem = window . document . createElement ( 'SCRIPT' ) ;
917
919
elem . onload = ( ) => this . receiveData ( this . __data , src ) ;
918
920
elem . src = src + ( src . endsWith ( '/' ) ? 'index.html' : '' ) ;
@@ -931,7 +933,7 @@ modulo.register('core', class FetchQueue {
931
933
932
934
receiveData ( text , src ) { // Receive data, optionally trimming padding
933
935
const { prefix, suffix } = this . modulo . config . fetchqueue . filePadding ;
934
- if ( text . startsWith ( prefix ) && prefix && text . trim ( ) . endsWith ( suffix ) ) {
936
+ if ( text && text . startsWith ( prefix ) && prefix && text . trim ( ) . endsWith ( suffix ) ) {
935
937
text = text . trim ( ) . slice ( prefix . length , 0 - suffix . length ) ; // Clean
936
938
}
937
939
this . data [ src ] = text ; // Keep retrieved data cached here for sync route
0 commit comments