Slider: refactor logic re auto progressing sliders

pull/2953/head
thyttan 2023-09-30 21:11:39 +02:00
parent 98a6417008
commit 0952ad9a26
1 changed files with 8 additions and 4 deletions

View File

@ -163,17 +163,21 @@ try { // for making it possiblie to run the test app in the following catch stat
}
if (o.c.autoProgress) {
o.v.shouldAutoDraw = true;
o.f.autoUpdate = ()=>{
//if (o.v.level===undefined) o.v.level = -1;
o.v.level = o.v.level+1;
if (o.v.shouldAutoDraw) o.f.draw&&o.f.draw(o.v.level);
o.v.level = o.c.currLevel + Math.round((Date.now()-o.v.initTime)/1000)
if (o.v.level>o.c.steps) o.v.level=o.c.steps;
o.f.draw&&o.f.draw(o.v.level);
cb("auto");
if (o.v.level==o.c.steps) {o.f.stopAutoUpdate();}
};
o.f.updateInitTime = ()=>{
o.v.initTime=Date.now();
}
o.f.startAutoUpdate = ()=>{
o.f.stopAutoUpdate();
if (o.v.shouldAutoDraw) o.f.draw&&o.f.draw(o.v.level);
!o.v.initTime&&o.f.updateInitTime();
o.f.draw&&o.f.draw(o.v.level);
o.v.autoIntervalID = setInterval(o.f.autoUpdate,1000);
};
o.f.stopAutoUpdate = ()=>{if (o.v.autoIntervalID) {clearInterval(o.v.autoIntervalID); o.v.autoIntervalID = undefined;}};