X-Git-Url: https://git.auder.net/img/rock_paper_scissors_lizard_spock.gif?a=blobdiff_plain;f=client%2Fsrc%2Fcomponents%2FSettings.vue;h=d08b943f1da65af646b883d1491e6ba75f7e3aba;hb=d36ca1989daec86e5ad4b2e65c8a045af171fafd;hp=5541cf372f67db80f2987d083d646138f3e18744;hpb=cf94b843f223b34fd2f3680112a183f6d5cd409c;p=vchess.git diff --git a/client/src/components/Settings.vue b/client/src/components/Settings.vue index 5541cf37..d08b943f 100644 --- a/client/src/components/Settings.vue +++ b/client/src/components/Settings.vue @@ -51,6 +51,18 @@ export default { const boardSize = localStorage.getItem("boardSize"); if (!!boardSize) document.getElementById("myRange").value = Math.floor(boardSize / 10); + // timeout to avoid calling too many time the adjust method + let timeoutLaunched = false; + window.addEventListener("resize", (e) => { + if (!timeoutLaunched) + { + timeoutLaunched = true; + setTimeout( () => { + this.adjustBoard(); + timeoutLaunched = false; + }, 500); + } + }); }, methods: { updateSettings: function(event) { @@ -65,13 +77,15 @@ export default { if (!boardContainer) return; //no board on page const k = document.getElementById("myRange").value; - const movesWidth = 280; //TODO: constant somewhere...; + const movesWidth = (window.innerWidth >= 768 ? 280 : 0); const minBoardWidth = 240; //TODO: same - // Value of 0 is board min size; 100 is screen.width - movesWidth - const boardSize = k * (screen.width - (movesWidth+minBoardWidth)) / 100 + minBoardWidth; + // Value of 0 is board min size; 100 is window.width [- movesWidth] + const boardSize = minBoardWidth + + k * (window.innerWidth - (movesWidth+minBoardWidth)) / 100; localStorage.setItem("boardSize", boardSize); boardContainer.style.width = boardSize + "px"; - document.getElementById("gameContainer").style.width = (boardSize + movesWidth) + "px"; + document.getElementById("gameContainer").style.width = + (boardSize + movesWidth) + "px"; }, }, };