@@ -3,7 +3,10 @@ const EasyCoder = {
3
3
name : `EasyCoder_Main` ,
4
4
5
5
domain : {
6
- core : EasyCoder_Core
6
+ core : EasyCoder_Core ,
7
+ browser : EasyCoder_Browser ,
8
+ json : EasyCoder_Json ,
9
+ rest : EasyCoder_Rest
7
10
} ,
8
11
9
12
elementId : 0 ,
@@ -144,22 +147,26 @@ const EasyCoder = {
144
147
} ,
145
148
146
149
require : function ( type , src , cb ) {
150
+ let prefix = `` ;
151
+ if ( src [ 0 ] == `/` ) {
152
+ prefix = window . location + `/` ;
153
+ }
147
154
const element = document . createElement ( type === `css` ? `link` : `script` ) ;
148
155
switch ( type ) {
149
156
case `css` :
150
157
element . type = `text/css` ;
151
- element . href = src ;
158
+ element . href = ` ${ prefix } ${ src } ` ;
152
159
element . rel = `stylesheet` ;
153
160
break ;
154
161
case `js` :
155
162
element . type = `text/javascript` ;
156
- element . src = src ;
163
+ element . src = ` ${ prefix } ${ src } ` ;
157
164
break ;
158
165
default :
159
166
return ;
160
167
}
161
168
element . onload = function ( ) {
162
- console . log ( `${ Date . now ( ) - EasyCoder . timestamp } ms: Library ${ src } loaded` ) ;
169
+ console . log ( `${ Date . now ( ) - EasyCoder . timestamp } ms: Library ${ prefix } ${ src } loaded` ) ;
163
170
cb ( ) ;
164
171
} ;
165
172
document . head . appendChild ( element ) ;
@@ -239,10 +246,6 @@ const EasyCoder = {
239
246
program . require = this . require ;
240
247
program . isUndefined = this . isUndefined ;
241
248
program . isJsonString = this . isJsonString ;
242
- program . checkPlugin = this . checkPlugin ;
243
- program . getPlugin = this . getPlugin ;
244
- program . addLocalPlugin = this . addLocalPlugin ;
245
- program . getPluginsPath = this . getPluginsPath ;
246
249
program . getSymbolRecord = this . getSymbolRecord ;
247
250
program . verifySymbol = this . verifySymbol ;
248
251
program . runtimeError = this . runtimeError ;
@@ -325,9 +328,9 @@ const EasyCoder = {
325
328
const source = this . tokeniseFile ( file ) ;
326
329
try {
327
330
program = this . compileScript ( source , imports , module , parent ) ;
328
- this . scriptIndex ++ ;
329
331
if ( ! program . script ) {
330
- program . script = this . scriptIndex ;
332
+ program . script = EasyCoder . scriptIndex ;
333
+ EasyCoder . scriptIndex ++ ;
331
334
}
332
335
const finishCompile = Date . now ( ) ;
333
336
console . log ( `${ finishCompile - this . timestamp } ms: ` +
@@ -359,7 +362,8 @@ const EasyCoder = {
359
362
}
360
363
} ,
361
364
362
- tokenise : function ( source ) {
365
+ start : function ( source ) {
366
+ EasyCoder . scriptIndex = 0 ;
363
367
const script = source . split ( `\n` ) ;
364
368
if ( ! this . tokenising ) {
365
369
try {
@@ -370,104 +374,4 @@ const EasyCoder = {
370
374
this . tokenising = true ;
371
375
}
372
376
} ,
373
-
374
- setPluginCount : function ( count ) {
375
- EasyCoder . plugins = [ ] ;
376
- EasyCoder . pluginCount = count ;
377
- } ,
378
-
379
- checkPlugin : function ( name ) {
380
- return EasyCoder . domain [ name ] ;
381
- } ,
382
-
383
- getPlugin : function ( name , src , onload ) {
384
- if ( EasyCoder . domain [ name ] ) {
385
- onload ( ) ;
386
- return ;
387
- }
388
- const script = document . createElement ( `script` ) ;
389
- script . type = `text/javascript` ;
390
- let location = document . scripts [ 0 ] . src ;
391
- location = location . substring ( 0 , location . indexOf ( `/easycoder.js` ) ) ;
392
- // script.src = `${location}/${src}?ver=${EasyCoder.version}`;
393
- script . src = `${ src } ?ver=${ EasyCoder . version } ` ;
394
- script . onload = function ( ) {
395
- console . log ( `${ Date . now ( ) - EasyCoder . timestamp } ms: Plugin ${ src } loaded` ) ;
396
- onload ( ) ;
397
- } ;
398
- document . head . appendChild ( script ) ;
399
- } ,
400
-
401
- addGlobalPlugin : function ( name , handler ) {
402
- // alert(`Add plugin ${name}`);
403
- EasyCoder . plugins . push ( {
404
- name,
405
- handler
406
- } ) ;
407
- if ( EasyCoder . plugins . length === EasyCoder . pluginCount ) {
408
- EasyCoder . plugins . forEach ( function ( plugin ) {
409
- EasyCoder . domain [ plugin . name ] = plugin . handler ;
410
- } ) ;
411
- EasyCoder . tokenise ( EasyCoder . source ) ;
412
- }
413
- } ,
414
-
415
- addLocalPlugin : function ( name , handler , callback ) {
416
- EasyCoder . domain [ name ] = handler ;
417
- callback ( ) ;
418
- } ,
419
-
420
- getPluginsPath : function ( ) {
421
- return EasyCoder . pluginsPath ;
422
- } ,
423
-
424
- loadPluginJs : function ( path ) {
425
- console . log ( `${ Date . now ( ) - this . timestamp } ms: Load ${ path } /easycoder/plugins.js` ) ;
426
- const script = document . createElement ( `script` ) ;
427
- script . src = `${ window . location . origin } ${ path } /easycoder/plugins.js?ver=${ this . version } ` ;
428
- script . type = `text/javascript` ;
429
- script . onload = ( ) => {
430
- EasyCoder_Plugins . getGlobalPlugins (
431
- this . timestamp ,
432
- path ,
433
- this . setPluginCount ,
434
- this . getPlugin ,
435
- this . addGlobalPlugin
436
- ) ;
437
- } ;
438
- script . onerror = ( ) => {
439
- if ( path ) {
440
- this . loadPluginJs ( path . slice ( 0 , path . lastIndexOf ( `/` ) ) ) ;
441
- } else {
442
- this . reportError ( {
443
- message : `Can't load plugins.js`
444
- } , this . program , this . source ) ;
445
- }
446
- } ;
447
- document . head . appendChild ( script ) ;
448
- this . pluginsPath = path ;
449
- } ,
450
-
451
- start : function ( source ) {
452
- this . source = source ;
453
- this . scriptIndex = 0 ;
454
- let pathname = window . location . pathname ;
455
- if ( pathname . endsWith ( `/` ) ) {
456
- pathname = pathname . slice ( 0 , - 1 ) ;
457
- } else {
458
- pathname = `` ;
459
- }
460
- if ( typeof EasyCoder_Plugins === `undefined` ) {
461
- this . loadPluginJs ( pathname ) ;
462
- } else {
463
- this . pluginsPath = pathname ;
464
- EasyCoder_Plugins . getGlobalPlugins (
465
- this . timestamp ,
466
- pathname ,
467
- this . setPluginCount ,
468
- this . getPlugin ,
469
- this . addGlobalPlugin
470
- ) ;
471
- }
472
- }
473
377
} ;
0 commit comments