@@ -37,32 +37,46 @@ codeEditor.on('change', function () {
37
37
} ) ;
38
38
39
39
var cachedFile = { } ;
40
+ var loading = false ;
40
41
var loadFile = function ( category , algorithm , file , explanation ) {
42
+ if ( checkLoading ( ) ) return ;
41
43
lastData = null ;
42
44
$ ( '#explanation' ) . html ( explanation ) ;
43
45
44
46
var dir = lastDir = './algorithm/' + category + '/' + algorithm + '/' + file + '/' ;
47
+ loading = true ;
45
48
if ( cachedFile [ dir ] && cachedFile [ dir ] . data !== undefined && cachedFile [ dir ] . code !== undefined ) {
46
49
dataEditor . setValue ( cachedFile [ dir ] . data , - 1 ) ;
47
50
codeEditor . setValue ( cachedFile [ dir ] . code , - 1 ) ;
48
51
} else {
49
52
cachedFile [ dir ] = { } ;
50
53
dataEditor . setValue ( '' ) ;
51
54
codeEditor . setValue ( '' ) ;
55
+ var onFail = function ( jqXHR , textStatus , errorThrown ) {
56
+ loading = false ;
57
+ alert ( "AJAX call failed: " + textStatus + ", " + errorThrown ) ;
58
+ } ;
52
59
$ . get ( dir + 'data.js' , function ( data ) {
53
60
cachedFile [ dir ] . data = data ;
54
61
dataEditor . setValue ( data , - 1 ) ;
55
62
56
63
$ . get ( dir + 'code.js' , function ( code ) {
57
64
cachedFile [ dir ] . code = code ;
58
65
codeEditor . setValue ( code , - 1 ) ;
59
- } ) ;
60
- } ) . fail ( function ( jqXHR , textStatus , errorThrown ) {
61
- alert ( "AJAX call failed: " + textStatus + ", " + errorThrown ) ;
62
- } ) ;
66
+ loading = false ;
67
+ } ) . fail ( onFail ) ;
68
+ } ) . fail ( onFail ) ;
69
+ }
70
+ } ;
71
+ var checkLoading = function ( ) {
72
+ if ( loading ) {
73
+ showErrorToast ( 'Wait until completes loading of previous file.' ) ;
74
+ return true ;
63
75
}
76
+ return false ;
64
77
} ;
65
78
var loadAlgorithm = function ( category , algorithm ) {
79
+ if ( checkLoading ( ) ) return ;
66
80
$ ( '#list > button' ) . removeClass ( 'active' ) ;
67
81
$ ( '[data-category="' + category + '"][data-algorithm="' + algorithm + '"]' ) . addClass ( 'active' ) ;
68
82
$ ( '#btn_desc' ) . click ( ) ;
@@ -167,6 +181,16 @@ $('#navigation').click(function () {
167
181
_tracer . resize ( ) ;
168
182
} ) ;
169
183
184
+ var showErrorToast = function ( err ) {
185
+ var $toast = $ ( '<div class="toast error">' ) . append ( err ) ;
186
+ $ ( '.toast_container' ) . append ( $toast ) ;
187
+ setTimeout ( function ( ) {
188
+ $toast . fadeOut ( function ( ) {
189
+ $toast . remove ( ) ;
190
+ } ) ;
191
+ } , 3000 ) ;
192
+ } ;
193
+
170
194
$ ( '#btn_run' ) . click ( function ( ) {
171
195
try {
172
196
eval ( dataEditor . getValue ( ) ) ;
@@ -177,13 +201,7 @@ $('#btn_run').click(function () {
177
201
_tracer . visualize ( ) ;
178
202
} catch ( err ) {
179
203
console . error ( err ) ;
180
- var $toast = $ ( '<div class="toast error">' ) . append ( err ) ;
181
- $ ( '.toast_container' ) . append ( $toast ) ;
182
- setTimeout ( function ( ) {
183
- $toast . fadeOut ( function ( ) {
184
- $toast . remove ( ) ;
185
- } ) ;
186
- } , 3000 ) ;
204
+ showErrorToast ( err ) ;
187
205
}
188
206
} ) ;
189
207
$ ( '#btn_pause' ) . click ( function ( ) {
0 commit comments