Browse Source

check if working

schtonn 2 năm trước cách đây
mục cha
commit
6f9ac5106c
2 tập tin đã thay đổi với 22 bổ sung5 xóa
  1. 20 3
      js/paint.js
  2. 2 2
      paint/index.html

+ 20 - 3
js/paint.js

@@ -75,16 +75,20 @@ function getId() {
     }
 }
 
-var curVer = 0, maxVer = -1, stopVer = 1000, stopped = false;
+var curVer = 0, maxVer = -1, stopVer = 1000, stopped = false, working = false;
 var maxResult = {};
 
 function getMap() {
+    if (working) return;
+    working = true;
+    console.log('g' + working)
     if (curVer != 0) document.getElementById('upload').classList.add('disabled')
     else document.getElementById('upload').classList.remove('disabled')
     if (curVer >= stopVer) {
         if (!stopped) document.getElementById('lbtn').classList.add('disabled'), stopped = true;
         else {
             curVer = stopVer;
+            working = false;
             return;
         }
     }
@@ -99,6 +103,7 @@ function getMap() {
         for (let i = 0; i < box.length; i++) {
             box[i].style.backgroundColor = map[i]
         }
+        working = false;
     } else {
         const query = new AV.Query('paint');
         query.descending('updatedAt')
@@ -120,6 +125,7 @@ function getMap() {
                 stopVer = result.length - 1;
                 getMap()
             }
+            working = false;
         })
     }
 }
@@ -131,14 +137,25 @@ function reset() {
     getMap()
 }
 
+function prevVer() {
+    console.log(working)
+    if (working) return;
+    curVer++, getMap();
+}
+
+function nextVer() {
+    if (working) return;
+    curVer == 0 ? true : (curVer--, getMap());
+}
+
 document.onkeydown = function (event) {
     var e = event || window.event || arguments.callee.caller.arguments[0];
     if (e) {
         if (e.key == "ArrowLeft") {
-            curVer++, getMap()
+            prevVer()
         }
         else if (e.key == "ArrowRight") {
-            curVer == 0 ? true : (curVer--, getMap());
+            nextVer()
         }
     }
 };

+ 2 - 2
paint/index.html

@@ -216,10 +216,10 @@
                 aria-hidden="true"></span>&nbsp;同步</button>
         <button class="btn btn-danger" id="clear" onclick="tryClear()"><span class="glyphicon glyphicon-ban-circle"
                 aria-hidden="true"></span>&nbsp;清空</button>
-        <a id="lbtn" tabindex="0" class="btn btn-default noshadow" onclick="curVer++,getMap()">
+        <a id="lbtn" tabindex="0" class="btn btn-default noshadow" onclick="prevVer()">
             <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
         </a>
-        <a id="rbtn" tabindex="0" class="btn btn-default noshadow" onclick="curVer==0?true:(curVer--,getMap());">
+        <a id="rbtn" tabindex="0" class="btn btn-default noshadow" onclick="nextVer()">
             <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
         </a>
         <span id="version" style="margin-right:auto"></span>