Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit77ac9af

Browse files
committed
prevent conflicts on loading
1 parent36f010f commit77ac9af

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

‎js/script.js‎

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,46 @@ codeEditor.on('change', function () {
3737
});
3838

3939
varcachedFile={};
40+
varloading=false;
4041
varloadFile=function(category,algorithm,file,explanation){
42+
if(checkLoading())return;
4143
lastData=null;
4244
$('#explanation').html(explanation);
4345

4446
vardir=lastDir='./algorithm/'+category+'/'+algorithm+'/'+file+'/';
47+
loading=true;
4548
if(cachedFile[dir]&&cachedFile[dir].data!==undefined&&cachedFile[dir].code!==undefined){
4649
dataEditor.setValue(cachedFile[dir].data,-1);
4750
codeEditor.setValue(cachedFile[dir].code,-1);
4851
}else{
4952
cachedFile[dir]={};
5053
dataEditor.setValue('');
5154
codeEditor.setValue('');
55+
varonFail=function(jqXHR,textStatus,errorThrown){
56+
loading=false;
57+
alert("AJAX call failed: "+textStatus+", "+errorThrown);
58+
};
5259
$.get(dir+'data.js',function(data){
5360
cachedFile[dir].data=data;
5461
dataEditor.setValue(data,-1);
5562

5663
$.get(dir+'code.js',function(code){
5764
cachedFile[dir].code=code;
5865
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+
varcheckLoading=function(){
72+
if(loading){
73+
showErrorToast('Wait until completes loading of previous file.');
74+
returntrue;
6375
}
76+
returnfalse;
6477
};
6578
varloadAlgorithm=function(category,algorithm){
79+
if(checkLoading())return;
6680
$('#list > button').removeClass('active');
6781
$('[data-category="'+category+'"][data-algorithm="'+algorithm+'"]').addClass('active');
6882
$('#btn_desc').click();
@@ -167,6 +181,16 @@ $('#navigation').click(function () {
167181
_tracer.resize();
168182
});
169183

184+
varshowErrorToast=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+
170194
$('#btn_run').click(function(){
171195
try{
172196
eval(dataEditor.getValue());
@@ -177,13 +201,7 @@ $('#btn_run').click(function () {
177201
_tracer.visualize();
178202
}catch(err){
179203
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);
187205
}
188206
});
189207
$('#btn_pause').click(function(){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp