]> git.sesse.net Git - remoteglot/blobdiff - www/js/chessboard-0.3.0.js
Fix a super-long-standing bug, where making a move on the board could make us replay...
[remoteglot] / www / js / chessboard-0.3.0.js
index e15ab00ff5d57b2d3ed61c6c683967e7f3b564b2..451f1a9f4d17cf73ed93c0b52788ccfb2cda1577 100644 (file)
@@ -726,7 +726,7 @@ function animateSquareToSquare(src, dest, piece, completeFn) {
   // animate the piece to the destination square
   animatedPieceEl.addEventListener('transitionend', complete, {once: true});
   requestAnimationFrame(() => {
-    animatedPieceEl.style.transitionProperty = 'top left';
+    animatedPieceEl.style.transitionProperty = 'top, left';
     animatedPieceEl.style.transitionDuration = cfg.moveSpeed + 'ms';
     animatedPieceEl.style.top = destSquarePosition.top + 'px';
     animatedPieceEl.style.left = destSquarePosition.left + 'px';
@@ -818,33 +818,35 @@ function doAnimations(a, oldPos, newPos) {
     }
   }
 
-  for (var i = 0; i < a.length; i++) {
-    // clear a piece
-    if (a[i].type === 'clear') {
-      document.getElementById(SQUARE_ELS_IDS[a[i].square]).querySelectorAll('.' + CSS.piece).forEach(
-        (piece) => fadeOut(piece, onFinish)
-      );
-    }
+  requestAnimationFrame(() => {  // Firefox workaround.
+    for (var i = 0; i < a.length; i++) {
+      // clear a piece
+      if (a[i].type === 'clear') {
+        document.getElementById(SQUARE_ELS_IDS[a[i].square]).querySelectorAll('.' + CSS.piece).forEach(
+          (piece) => fadeOut(piece, onFinish)
+        );
+      }
 
-    // add a piece (no spare pieces)
-    if (a[i].type === 'add' && cfg.sparePieces !== true) {
-      let square = document.getElementById(SQUARE_ELS_IDS[a[i].square]);
-      square.append(buildPiece(a[i].piece, true));
-      let piece = square.querySelector('.' + CSS.piece);
-      fadeIn(piece, onFinish);
-    }
+      // add a piece (no spare pieces)
+      if (a[i].type === 'add' && cfg.sparePieces !== true) {
+        let square = document.getElementById(SQUARE_ELS_IDS[a[i].square]);
+        square.append(buildPiece(a[i].piece, true));
+        let piece = square.querySelector('.' + CSS.piece);
+        fadeIn(piece, onFinish);
+      }
 
-    // add a piece from a spare piece
-    if (a[i].type === 'add' && cfg.sparePieces === true) {
-      animateSparePieceToSquare(a[i].piece, a[i].square, onFinish);
-    }
+      // add a piece from a spare piece
+      if (a[i].type === 'add' && cfg.sparePieces === true) {
+        animateSparePieceToSquare(a[i].piece, a[i].square, onFinish);
+      }
 
-    // move a piece
-    if (a[i].type === 'move') {
-      animateSquareToSquare(a[i].source, a[i].destination, a[i].piece,
-        onFinish);
+      // move a piece
+      if (a[i].type === 'move') {
+        animateSquareToSquare(a[i].source, a[i].destination, a[i].piece,
+          onFinish);
+      }
     }
-  }
+  });
 }
 
 // returns the distance between two squares
@@ -1118,7 +1120,7 @@ function snapbackDraggedPiece() {
   // animate the piece to the target square
   draggedPieceEl.addEventListener('transitionend', complete, {once: true});
   requestAnimationFrame(() => {
-    draggedPieceEl.style.transitionProperty = 'top left';
+    draggedPieceEl.style.transitionProperty = 'top, left';
     draggedPieceEl.style.transitionDuration = cfg.snapbackSpeed + 'ms';
     draggedPieceEl.style.top = sourceSquarePosition.top + 'px';
     draggedPieceEl.style.left = sourceSquarePosition.left + 'px';
@@ -1176,7 +1178,7 @@ function dropDraggedPieceOnSquare(square) {
   // snap the piece to the target square
   draggedPieceEl.addEventListener('transitionend', complete, {once: true});
   requestAnimationFrame(() => {
-    draggedPieceEl.style.transitionProperty = 'top left';
+    draggedPieceEl.style.transitionProperty = 'top, left';
     draggedPieceEl.style.transitionDuration = cfg.snapSpeed + 'ms';
     draggedPieceEl.style.top = targetSquarePosition.top + 'px';
     draggedPieceEl.style.left = targetSquarePosition.left + 'px';