From: Benjamin Auder Date: Mon, 26 Nov 2018 11:57:04 +0000 (+0100) Subject: Add a small silent when landing on variant page to allow newgame sound when unfocused X-Git-Url: https://git.auder.net/img/%7B%7B%20asset%28%27mixstore/css/parser.js?a=commitdiff_plain;h=92ff5bae505d05010e0f1be7fc00577f3ab076f1;p=vchess.git Add a small silent when landing on variant page to allow newgame sound when unfocused --- diff --git a/public/javascripts/components/game.js b/public/javascripts/components/game.js index 3f74fde9..b0fde5eb 100644 --- a/public/javascripts/components/game.js +++ b/public/javascripts/components/game.js @@ -393,6 +393,11 @@ Vue.component('my-game', { ? localStorage.getItem("myid") // random enough (TODO: function) : (Date.now().toString(36) + Math.random().toString(36).substr(2, 7)).toUpperCase(); + if (!continuation) + { + // HACK: play a small silent sound to allow "new game" sound later if tab not focused + new Audio("/sounds/silent.mp3").play().then(() => {}).catch(err => {}); + } this.conn = new WebSocket(url + "/?sid=" + this.myid + "&page=" + variant); const socketOpenListener = () => { if (continuation) @@ -734,8 +739,9 @@ Vue.component('my-game', { let rectStart = startSquare.getBoundingClientRect(); let rectEnd = endSquare.getBoundingClientRect(); let translation = {x:rectEnd.x-rectStart.x, y:rectEnd.y-rectStart.y}; - let movingPiece = document.querySelector("#" + this.getSquareId(move.start) + " > img.piece"); - // HACK for animation (otherwise with positive translate, image slides "under background"...) + let movingPiece = + document.querySelector("#" + this.getSquareId(move.start) + " > img.piece"); + // HACK for animation (with positive translate, image slides "under background"...) // Possible improvement: just alter squares on the piece's way... squares = document.getElementsByClassName("board"); for (let i=0; i