@@ -35,7 +35,7 @@ export {
35
35
loadDataPixelsClassCode ,
36
36
setErrorMessage ,
37
37
setFrameViewHasImage ,
38
- setMode ,
38
+ setCodeEditorMode ,
39
39
setTheme ,
40
40
toggleLayout ,
41
41
updateAutoCode
@@ -46,7 +46,7 @@ export {
46
46
* <ul>
47
47
* <li> DataPixelsClassCode </li>
48
48
* <li> DataPixelsClassCodeInternal </li>
49
- * <li> IsExecuting </li>
49
+ * <li> ExecuteAfterLoad </li>
50
50
* </ul>
51
51
*
52
52
* @private
@@ -57,7 +57,7 @@ const M = {
57
57
58
58
DataPixelsClassCode : undefined ,
59
59
DataPixelsClassCodeInternal : undefined ,
60
- IsExecuting : undefined
60
+ ExecuteAfterLoad : undefined
61
61
} ;
62
62
63
63
/**
@@ -85,18 +85,19 @@ function readStates() {
85
85
86
86
S . Alignment = ( localStorage . length ) ? JSON . parse ( localStorage . getItem ( C . Persistence . ALIGNMENT ) ) : true ;
87
87
S . AutoCode = DataPixelsCodeFactory . fromJSON ( localStorage . getItem ( C . Persistence . AUTO_CODE ) ) || null ;
88
+ S . AutoExecute = ( localStorage . length ) ? JSON . parse ( localStorage . getItem ( C . Persistence . AUTO_EXECUTE ) ) : false ;
88
89
S . Code = ( localStorage . length ) ? localStorage . getItem ( C . Persistence . CODE ) : Examples . basic ;
89
90
S . CodeEditorFlexGrow = localStorage . getItem ( C . Persistence . CODE_EDITOR_FLEX_GROW ) || 0.65 ;
90
- S . Description = ( localStorage . length ) ? JSON . parse ( localStorage . getItem ( C . Persistence . DESCRIPTION ) ) : false ;
91
+ S . Description = ( localStorage . length ) ? JSON . parse ( localStorage . getItem ( C . Persistence . DESCRIPTION ) ) : true ;
91
92
S . FrameViewFlexGrow = localStorage . getItem ( C . Persistence . FRAME_VIEW_FLEX_GROW ) || 0.35 ;
92
- S . Mode = localStorage . getItem ( C . Persistence . MODE ) || C . Mode . MANUAL ;
93
+ S . CodeEditorMode = localStorage . getItem ( C . Persistence . MODE ) || C . Mode . MANUAL ;
93
94
S . Indentation = localStorage . getItem ( C . Persistence . INDENTATION ) || C . Indentation . INDENT_4 ;
94
95
S . Orientation = localStorage . getItem ( C . Persistence . ORIENTATION ) || C . Orientation . VERTICAL ;
95
96
S . Theme = localStorage . getItem ( C . Persistence . THEME ) || C . Theme . DARK ;
96
97
97
98
window . addEventListener ( C . Event . BEFORE_UNLOAD , writeStates ) ;
98
99
99
- setMode ( S . Mode ) ;
100
+ setCodeEditorMode ( S . CodeEditorMode ) ;
100
101
setTheme ( S . Theme ) ;
101
102
}
102
103
@@ -113,12 +114,13 @@ function writeStates() {
113
114
try {
114
115
115
116
localStorage . setItem ( C . Persistence . ALIGNMENT , S . Alignment ) ;
116
- localStorage . setItem ( C . Persistence . AUTO_CODE , ( S . Mode === C . Mode . AUTO ) ? JSON . stringify ( S . AutoCode ) : null ) ;
117
+ localStorage . setItem ( C . Persistence . AUTO_CODE , ( S . CodeEditorMode === C . Mode . AUTO ) ? JSON . stringify ( S . AutoCode ) : null ) ;
118
+ localStorage . setItem ( C . Persistence . AUTO_EXECUTE , S . AutoExecute ) ;
117
119
localStorage . setItem ( C . Persistence . CODE_EDITOR_FLEX_GROW , S . CodeEditorFlexGrow ) ;
118
120
localStorage . setItem ( C . Persistence . CODE , C . HTMLElement . TEXT_AREA . value ) ;
119
121
localStorage . setItem ( C . Persistence . DESCRIPTION , S . Description ) ;
120
122
localStorage . setItem ( C . Persistence . FRAME_VIEW_FLEX_GROW , S . FrameViewFlexGrow ) ;
121
- localStorage . setItem ( C . Persistence . MODE , S . Mode ) ;
123
+ localStorage . setItem ( C . Persistence . MODE , S . CodeEditorMode ) ;
122
124
localStorage . setItem ( C . Persistence . INDENTATION , S . Indentation ) ;
123
125
localStorage . setItem ( C . Persistence . ORIENTATION , S . Orientation ) ;
124
126
localStorage . setItem ( C . Persistence . THEME , S . Theme ) ;
@@ -130,23 +132,23 @@ function writeStates() {
130
132
}
131
133
132
134
/**
133
- * @description The mode determines which formatting options are available to the automatically generated program code written in the Code Editor.
134
- * @param {number } mode - The mode value is either 0 (Automatic) or 1 (Manual) .
135
+ * @description The code editor mode determines which formatting options are available to the automatically generated program code written in the Code Editor.
136
+ * @param {number } mode - The mode value must be either C.Mode.AUTO or C.Mode.MANUAL .
135
137
* @private
136
138
* @function
137
139
*
138
140
*/
139
- function setMode ( mode ) {
141
+ function setCodeEditorMode ( mode ) {
140
142
141
- S . Mode = mode ;
143
+ S . CodeEditorMode = mode ;
142
144
143
- if ( S . Mode === C . Mode . MANUAL ) {
145
+ if ( S . CodeEditorMode === C . Mode . AUTO ) {
144
146
145
- C . HTMLElement . TEXT_AREA . removeEventListener ( C . Event . INPUT , textInputManualModeHandler ) ;
147
+ C . HTMLElement . TEXT_AREA . addEventListener ( C . Event . INPUT , textInputManualModeHandler ) ;
146
148
}
147
- else if ( S . Mode === C . Mode . AUTO ) {
149
+ else if ( S . CodeEditorMode === C . Mode . MANUAL ) {
148
150
149
- C . HTMLElement . TEXT_AREA . addEventListener ( C . Event . INPUT , textInputManualModeHandler ) ;
151
+ C . HTMLElement . TEXT_AREA . removeEventListener ( C . Event . INPUT , textInputManualModeHandler ) ;
150
152
}
151
153
}
152
154
@@ -158,12 +160,12 @@ function setMode(mode) {
158
160
*/
159
161
function textInputManualModeHandler ( ) {
160
162
161
- setMode ( C . Mode . MANUAL ) ;
163
+ setCodeEditorMode ( C . Mode . MANUAL ) ;
162
164
}
163
165
164
166
/**
165
167
* @description The set theme applies a cohesive visual style throughout the application.
166
- * @param {string } theme - The theme value is either "Dark" or "Light" .
168
+ * @param {string } theme - The theme value must be either C.Theme.DARK or C.Theme.LIGHT .
167
169
* @private
168
170
* @function
169
171
*
@@ -212,13 +214,16 @@ function displayCode(code, autoMode = true) {
212
214
213
215
document . execCommand ( C . TextArea . COMMAND_INSERT , false , code ) ;
214
216
217
+
215
218
if ( autoMode ) {
216
219
217
- setMode ( C . Mode . AUTO ) ;
220
+ setCodeEditorMode ( C . Mode . AUTO ) ;
218
221
}
219
222
220
- Content . updateLineNumbers ( ) ;
221
- Controls . updateExecuteButton ( ) ;
223
+ if ( ! S . AutoExecute ) {
224
+
225
+ Controls . updateExecuteButton ( ) ;
226
+ }
222
227
}
223
228
224
229
/**
@@ -240,7 +245,7 @@ function executeCode() {
240
245
setErrorMessage ( error ) ;
241
246
} ;
242
247
243
- M . IsExecuting = true ;
248
+ M . ExecuteAfterLoad = true ;
244
249
245
250
loadDataPixelsClassCode ( ) ;
246
251
@@ -263,19 +268,23 @@ function executeCode() {
263
268
setErrorMessage ( null ) ;
264
269
265
270
let code = C . HTMLElement . TEXT_AREA . value ;
266
- code = code . replace ( / i m p o r t .* ?[ ; | \n ] / gmi, "" ) ;
267
271
268
- const runtimeScript = document . createElement ( C . HTML . SCRIPT ) ;
269
- runtimeScript . type = C . HTML . SCRIPT_TYPE ;
270
- runtimeScript . text = `try{ (function(){ ${ M . DataPixelsClassCodeInternal } ${ code } })(); }catch(error){ parent.setErrorMessageDelegate(error); }` ;
272
+ if ( code ) {
273
+
274
+ code = code . replace ( / i m p o r t . * ? [ ; | \n ] / gmi , "" ) ;
271
275
272
- headTag . appendChild ( runtimeScript ) ;
273
- headTag . removeChild ( runtimeScript ) ;
276
+ const runtimeScript = document . createElement ( C . HTML . SCRIPT ) ;
277
+ runtimeScript . type = C . HTML . SCRIPT_TYPE ;
278
+ runtimeScript . text = `try{ (function(){ ${ M . DataPixelsClassCodeInternal } ${ code } })(); }catch(error){ parent.setErrorMessageDelegate(error); }` ;
274
279
275
- frameViewBody . firstChild . style . pointerEvents = C . CSS . NONE ;
276
- frameViewBody . firstChild . style . userSelect = C . CSS . NONE ;
280
+ headTag . appendChild ( runtimeScript ) ;
281
+ headTag . removeChild ( runtimeScript ) ;
277
282
278
- setFrameViewHasImage ( true ) ;
283
+ frameViewBody . firstChild . style . pointerEvents = C . CSS . NONE ;
284
+ frameViewBody . firstChild . style . userSelect = C . CSS . NONE ;
285
+
286
+ setFrameViewHasImage ( true ) ;
287
+ }
279
288
}
280
289
281
290
/**
@@ -354,9 +363,9 @@ function XHRLoadHandler(event) {
354
363
M . DataPixelsClassCode = xhr . responseText ;
355
364
M . DataPixelsClassCodeInternal = xhr . responseText . replace ( / ( e x p o r t d e f a u l t D a t a P i x e l s ; ) / gi, "" ) ;
356
365
357
- if ( M . IsExecuting ) {
366
+ if ( M . ExecuteAfterLoad ) {
358
367
359
- M . IsExecuting = false ;
368
+ M . ExecuteAfterLoad = false ;
360
369
361
370
executeCode ( ) ;
362
371
}
@@ -390,7 +399,7 @@ function XHRErrorHandler(event) {
390
399
*/
391
400
function updateAutoCode ( ) {
392
401
393
- if ( S . Mode === C . Mode . AUTO && S . AutoCode ) {
402
+ if ( S . CodeEditorMode === C . Mode . AUTO && S . AutoCode ) {
394
403
395
404
S . AutoCode . formatCode ( S . Alignment , S . Description ) ;
396
405
S . AutoCode . updateIndentation ( S . Indentation ) ;
0 commit comments