@@ -23,73 +23,57 @@ let cwcChromeSupport = (
23
23
typeof chrome !== 'undefined' &&
24
24
typeof chrome . app !== 'undefined' &&
25
25
typeof chrome . app . window !== 'undefined' ) ;
26
+ let loader = cwcChromeSupport && chrome . app . window . get ( 'loader' ) ;
26
27
27
28
let cwcBuildUi = function ( ) {
28
- if ( cwcChromeSupport ) {
29
- let loader = chrome . app . window . get ( 'loader' ) ;
30
- if ( loader ) {
31
- loader . contentWindow . postMessage ( { 'command' : 'progress' ,
32
- 'text' : 'Build the Coding with Chrome UI ...' ,
33
- 'current' : 1 , 'total' : 100 } , '*' ) ;
34
- }
29
+ if ( loader ) {
30
+ loader . contentWindow . postMessage ( { 'command' : 'progress' ,
31
+ 'text' : 'Build the Coding with Chrome UI ...' ,
32
+ 'current' : 1 , 'total' : 100 } , '*' ) ;
35
33
if ( typeof cwc == 'undefined' ) {
36
- if ( loader ) {
37
- loader . contentWindow . postMessage ( { 'command' : 'error' ,
38
- 'msg' : 'The cwc namespace is undefined!\n' +
39
- 'Please make sure that the compiler runs without any errors!' } ,
40
- '*' ) ;
41
- }
42
- return null ;
34
+ loader . contentWindow . postMessage ( { 'command' : 'error' ,
35
+ 'msg' : 'The cwc namespace is undefined!\n' +
36
+ 'Please make sure that the compiler runs without any errors!' } ,
37
+ '*' ) ;
43
38
} else if ( typeof cwc . ui == 'undefined' ||
44
39
typeof cwc . ui . Builder == 'undefined' ) {
45
- if ( loader ) {
46
- loader . contentWindow . postMessage ( { 'command' : 'error' ,
47
- 'msg' : 'cwc.ui.Builder is undefined!\n' +
48
- 'Maybe an uncaught TypeError, SyntaxError, ... or missing files.' } ,
49
- '*' ) ;
50
- }
51
- return null ;
40
+ loader . contentWindow . postMessage ( { 'command' : 'error' ,
41
+ 'msg' : 'cwc.ui.Builder is undefined!\n' +
42
+ 'Maybe an uncaught TypeError, SyntaxError, ... or missing files.' } ,
43
+ '*' ) ;
52
44
}
53
45
}
54
- let uiBuilder = new cwc . ui . Builder ( ) ;
55
- uiBuilder . decorate ( ) ;
56
- return uiBuilder ;
46
+ return new cwc . ui . Builder ( ) . decorate ( ) ;
57
47
} ;
58
48
59
-
60
49
let cwcLoadScripts = function ( ) {
61
50
let header = document . getElementsByTagName ( 'head' ) [ 0 ] ;
62
- if ( header ) {
63
- let loader = cwcChromeSupport && chrome . app . window . get ( 'loader' ) ;
64
- let message = 'Loading additional JavaScripts ...' ;
65
- if ( loader ) {
66
- loader . contentWindow . postMessage ( { 'command' : 'progress' ,
67
- 'text' : message ,
68
- 'current' : 0 , 'total' : 100 } , '*' ) ;
69
- }
70
- // Adding main ui script.
71
- let uiScript = document . createElement ( 'script' ) ;
72
- uiScript . type = 'text/javascript' ;
73
- uiScript . src = '../js/cwc_ui.js' ;
74
- uiScript . onload = function ( ) {
75
- // Adding debugging script.
76
- let debugScript = document . createElement ( 'script' ) ;
77
- debugScript . type = 'text/javascript' ;
78
- debugScript . src = '../js/debug.js' ;
79
- header . appendChild ( debugScript ) ;
80
- } ;
81
- header . appendChild ( uiScript ) ;
82
-
83
- if ( loader ) {
84
- loader . contentWindow . postMessage ( { 'command' : 'progress' ,
85
- 'text' : message ,
86
- 'current' : 100 , 'total' : 100 } , '*' ) ;
87
- }
88
- } else {
51
+ if ( ! header ) {
89
52
console . error ( 'Seems DOM content is not ready!' ) ;
53
+ return ;
90
54
}
91
- } ;
55
+ if ( loader ) {
56
+ loader . contentWindow . postMessage ( { 'command' : 'progress' ,
57
+ 'text' : 'Loading additional Scripts ...' ,
58
+ 'current' : 0 , 'total' : 100 } , '*' ) ;
59
+ }
60
+ let uiScript = document . createElement ( 'script' ) ;
61
+ uiScript . type = 'text/javascript' ;
62
+ uiScript . src = '../js/cwc_ui.js' ;
63
+ uiScript . onload = function ( ) {
64
+ let debugScript = document . createElement ( 'script' ) ;
65
+ debugScript . type = 'text/javascript' ;
66
+ debugScript . src = '../js/debug.js' ;
67
+ header . appendChild ( debugScript ) ;
68
+ } ;
69
+ header . appendChild ( uiScript ) ;
92
70
71
+ if ( loader ) {
72
+ loader . contentWindow . postMessage ( { 'command' : 'progress' ,
73
+ 'text' : 'Loaded additional Scripts' ,
74
+ 'current' : 100 , 'total' : 100 } , '*' ) ;
75
+ }
76
+ } ;
93
77
94
78
window . addEventListener ( 'load' , cwcBuildUi , false ) ;
95
79
document . addEventListener ( 'DOMContentLoaded' , cwcLoadScripts , false ) ;
0 commit comments