@@ -3,7 +3,10 @@ const EasyCoder = {
33 name : `EasyCoder_Main` ,
44
55 domain : {
6- core : EasyCoder_Core
6+ core : EasyCoder_Core ,
7+ browser : EasyCoder_Browser ,
8+ json : EasyCoder_Json ,
9+ rest : EasyCoder_Rest
710 } ,
811
912 elementId : 0 ,
@@ -144,22 +147,26 @@ const EasyCoder = {
144147 } ,
145148
146149 require : function ( type , src , cb ) {
150+ let prefix = `` ;
151+ if ( src [ 0 ] == `/` ) {
152+ prefix = window . location + `/` ;
153+ }
147154 const element = document . createElement ( type === `css` ? `link` : `script` ) ;
148155 switch ( type ) {
149156 case `css` :
150157 element . type = `text/css` ;
151- element . href = src ;
158+ element . href = ` ${ prefix } ${ src } ` ;
152159 element . rel = `stylesheet` ;
153160 break ;
154161 case `js` :
155162 element . type = `text/javascript` ;
156- element . src = src ;
163+ element . src = ` ${ prefix } ${ src } ` ;
157164 break ;
158165 default :
159166 return ;
160167 }
161168 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` ) ;
163170 cb ( ) ;
164171 } ;
165172 document . head . appendChild ( element ) ;
@@ -239,10 +246,6 @@ const EasyCoder = {
239246 program . require = this . require ;
240247 program . isUndefined = this . isUndefined ;
241248 program . isJsonString = this . isJsonString ;
242- program . checkPlugin = this . checkPlugin ;
243- program . getPlugin = this . getPlugin ;
244- program . addLocalPlugin = this . addLocalPlugin ;
245- program . getPluginsPath = this . getPluginsPath ;
246249 program . getSymbolRecord = this . getSymbolRecord ;
247250 program . verifySymbol = this . verifySymbol ;
248251 program . runtimeError = this . runtimeError ;
@@ -325,9 +328,9 @@ const EasyCoder = {
325328 const source = this . tokeniseFile ( file ) ;
326329 try {
327330 program = this . compileScript ( source , imports , module , parent ) ;
328- this . scriptIndex ++ ;
329331 if ( ! program . script ) {
330- program . script = this . scriptIndex ;
332+ program . script = EasyCoder . scriptIndex ;
333+ EasyCoder . scriptIndex ++ ;
331334 }
332335 const finishCompile = Date . now ( ) ;
333336 console . log ( `${ finishCompile - this . timestamp } ms: ` +
@@ -359,7 +362,8 @@ const EasyCoder = {
359362 }
360363 } ,
361364
362- tokenise : function ( source ) {
365+ start : function ( source ) {
366+ EasyCoder . scriptIndex = 0 ;
363367 const script = source . split ( `\n` ) ;
364368 if ( ! this . tokenising ) {
365369 try {
@@ -370,104 +374,4 @@ const EasyCoder = {
370374 this . tokenising = true ;
371375 }
372376 } ,
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- }
473377} ;
0 commit comments