- const r =
- document.getElementById(this.containerId).getBoundingClientRect();
- const animateRec = i => {
- this.animate(moves[i], () => {
- this.playVisual(moves[i], r);
- this.play(moves[i]);
- if (i < moves.length - 1) setTimeout(() => animateRec(i+1), 300);
- else callback();
- });
+ const launchAnimation = () => {
+ const r = container.querySelector(".chessboard").getBoundingClientRect();
+ const animateRec = i => {
+ this.animate(moves[i], () => {
+ this.playVisual(moves[i], r);
+ this.play(moves[i]);
+ if (i < moves.length - 1)
+ setTimeout(() => animateRec(i+1), 300);
+ else
+ callback();
+ });
+ };
+ animateRec(0);
+ };
+ // Delay if user wasn't focused:
+ const checkDisplayThenAnimate = (delay) => {
+ if (container.style.display == "none") {
+ alert("New move! Let's go back to game...");
+ document.getElementById("gameInfos").style.display = "none";
+ container.style.display = "block";
+ setTimeout(launchAnimation, 700);
+ }
+ else
+ setTimeout(launchAnimation, delay || 0);