File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -120,14 +120,14 @@ commonUtils.loadPouchDBForBrowser = function (plugins) {
120120
121121// Thanks to http://engineeredweb.com/blog/simple-async-javascript-loader/
122122commonUtils . asyncLoadScript = function ( url ) {
123- return new commonUtils . Promise ( function ( resolve ) {
123+ return new commonUtils . Promise ( function ( resolve , reject ) {
124124 // Create a new script and setup the basics.
125125 var script = document . createElement ( "script" ) ;
126- var firstScript = document . getElementsByTagName ( 'script' ) [ 0 ] ;
127126
128127 script . async = true ;
129128 script . src = url ;
130129
130+ script . onerror = reject ;
131131 script . onload = function ( ) {
132132 resolve ( ) ;
133133
@@ -141,9 +141,7 @@ commonUtils.asyncLoadScript = function (url) {
141141 }
142142 } ;
143143
144- // Attach the script tag to the page (before the first script) so the
145- //magic can happen.
146- firstScript . parentNode . insertBefore ( script , firstScript ) ;
144+ document . body . append ( script ) ;
147145 } ) ;
148146} ;
149147
Original file line number Diff line number Diff line change @@ -43,13 +43,7 @@ describe('migration', function () {
4343 if ( ! match ) {
4444 return testUtils . Promise . resolve ( ) ;
4545 }
46- return new testUtils . Promise ( function ( resolve , reject ) {
47- var script = document . createElement ( 'script' ) ;
48- script . onload = resolve ;
49- script . onerror = reject ;
50- script . src = 'deps/pouchdb-' + match [ 1 ] + '-postfixed.js' ;
51- document . body . appendChild ( script ) ;
52- } ) ;
46+ return testUtils . asyncLoadScript ( 'deps/pouchdb-' + match [ 1 ] + '-postfixed.js' ) ;
5347 } ) ) ;
5448 } ) ;
5549
Original file line number Diff line number Diff line change @@ -3113,15 +3113,9 @@ adapters.forEach(function (adapter) {
31133113 var bigimage = require ( './deps/bigimage.js' ) ;
31143114 cb ( null , bigimage ) ;
31153115 } else { // browser
3116- var script = document . createElement ( 'script' ) ;
3117- script . src = 'deps/bigimage.js' ;
3118- document . body . appendChild ( script ) ;
3119- var timeout = setInterval ( function ( ) {
3120- if ( window . bigimage ) {
3121- clearInterval ( timeout ) ;
3122- cb ( null , window . bigimage ) ;
3123- }
3124- } , 500 ) ;
3116+ testUtils . asyncLoadScript ( 'deps/bigimage.js' )
3117+ . then ( ( ) => cb ( null , window . bigimage ) )
3118+ . catch ( err => cb ( err ) ) ;
31253119 }
31263120 }
31273121
You can’t perform that action at this time.
0 commit comments