@ -23,28 +23,33 @@
DEALINGS IN THE SOFTWARE .
DEALINGS IN THE SOFTWARE .
* /
* /
var Module = {
"use strict" ;
function createMagnumModule ( init ) {
const module = Object . assign ( { } , Module ) ;
Object . assign ( module , {
preRun : [ ] ,
preRun : [ ] ,
postRun : [ ] ,
postRun : [ ] ,
arguments : [ ] ,
arguments : [ ] ,
doNotCaptureKeyboard : true ,
printErr : function ( _message ) {
if ( module . log ) {
printErr : function ( message ) {
module . log . innerHTML += Array . prototype . slice . call ( arguments ) . join ( ' ' )
var log = document . getElementById ( 'log' ) ;
log . innerHTML += Array . prototype . slice . call ( arguments ) . join ( ' ' )
. replace ( /[\"&<>]/g , function ( a ) {
. replace ( /[\"&<>]/g , function ( a ) {
return { '"' : '"' , '&' : '&' , '<' : '<' , '>' : '>' } [ a ] ;
return { '"' : '"' , '&' : '&' , '<' : '<' , '>' : '>' } [ a ] ;
} ) + '\n' ;
} ) + '\n' ;
}
} ,
} ,
print : function ( message ) {
print : function ( _ message) {
var log = document . getElementById ( 'log' ) ;
if ( module . log ) {
log . innerHTML += Array . prototype . slice . call ( arguments ) . join ( ' ' )
module . log . innerHTML += Array . prototype . slice . call ( arguments ) . join ( ' ' )
. replace ( /[\"&<>]/g , function ( a ) {
. replace ( /[\"&<>]/g , function ( a ) {
return { '"' : '"' , '&' : '&' , '<' : '<' , '>' : '>' } [ a ] ;
return { '"' : '"' , '&' : '&' , '<' : '<' , '>' : '>' } [ a ] ;
} ) + '\n' ;
} ) + '\n' ;
}
} ,
} ,
/* onAbort not handled here, as the output is printed directly on the page */
/* onAbort not handled here, as the output is printed directly on the page */
@ -55,12 +60,13 @@ var Module = {
log : document . getElementById ( 'log' ) ,
log : document . getElementById ( 'log' ) ,
setStatus : function ( message ) {
setStatus : function ( message ) {
if ( Module . status ) Module . status . innerHTML = message ;
if ( module . status )
module . status . innerHTML = message ;
} ,
} ,
setStatusDescription : function ( message ) {
setStatusDescription : function ( message ) {
if ( M odule. statusDescription )
if ( m odule. statusDescription )
M odule. statusDescription . innerHTML = message ;
m odule . statusDescription . innerHTML = message ;
} ,
} ,
totalDependencies : 0 ,
totalDependencies : 0 ,
@ -69,29 +75,46 @@ var Module = {
this . totalDependencies = Math . max ( this . totalDependencies , left ) ;
this . totalDependencies = Math . max ( this . totalDependencies , left ) ;
if ( left ) {
if ( left ) {
M odule. setStatus ( 'Downloading...' ) ;
m odule . setStatus ( 'Downloading...' ) ;
M odule. setStatusDescription ( ( this . totalDependencies - left ) + ' / ' + this . totalDependencies ) ;
m odule . setStatusDescription ( ( this . totalDependencies - left ) + ' / ' + this . totalDependencies ) ;
} else {
} else {
M odule. setStatus ( 'Download complete' ) ;
m odule . setStatus ( 'Download complete' ) ;
M odule. setStatusDescription ( '' ) ;
m odule . setStatusDescription ( '' ) ;
M odule. log . style . display = 'block' ;
m odule . log . style . display = 'block' ;
}
}
}
}
} ;
} ) ;
/ * P a r s e a r g u m e n t s , e . g . / a p p / ? f o o = b a r & f i z z & b u z z = 3 g o e s t o t h e a p p a s
/ * P a r s e a r g u m e n t s , e . g . / a p p / ? f o o = b a r & f i z z & b u z z = 3 g o e s t o t h e a p p a s
[ '--foo' , 'bar' , '--fizz' , '--buzz' , '3' ] * /
[ '--foo' , 'bar' , '--fizz' , '--buzz' , '3' ] * /
var args = decodeURIComponent ( window . location . search . substr ( 1 ) ) . trim ( ) . split ( '&' ) ;
const args = decodeURIComponent ( window . location . search . substr ( 1 ) ) . trim ( ) . split ( '&' ) ;
for ( var i = 0 ; i != args . length ; ++ i ) {
for ( let i = 0 ; i != args . length ; ++ i ) {
var j = args [ i ] . indexOf ( '=' ) ;
let j = args [ i ] . indexOf ( '=' ) ;
/* Key + value */
/* Key + value */
if ( j != - 1 ) {
if ( j != - 1 ) {
M odule. arguments . push ( '--' + args [ i ] . substring ( 0 , j ) ) ;
m odule . arguments . push ( '--' + args [ i ] . substring ( 0 , j ) ) ;
M odule. arguments . push ( args [ i ] . substring ( j + 1 ) ) ;
m odule . arguments . push ( args [ i ] . substring ( j + 1 ) ) ;
/* Just key */
/* Just key */
} else M odule. arguments . push ( '--' + args [ i ] ) ;
} else m odule. arguments . push ( '--' + args [ i ] ) ;
}
}
Module . setStatus ( 'Downloading...' ) ;
Object . assign ( module , init ) ;
Module . log . style . display = 'none' ;
module . setStatus ( "Downloading..." ) ;
if ( module . log )
module . log . style . display = 'none' ;
return module ;
}
/* Default global Module object */
var Module = createMagnumModule ( ) ;
/* UMD export */
if ( typeof exports === 'object' && typeof module === 'object' ) /* CommonJS/Node */
module . exports = createMagnumModule ;
else if ( typeof define === 'function' && define [ 'amd' ] ) /* AMD */
define ( [ ] , function ( ) { return createMagnumModule ; } ) ;
else if ( typeof exports === 'object' ) /* CommonJS strict */
exports [ "createMagnumModule" ] = createMagnumModule ;