X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=client%2Fsrc%2Fcomponents%2FSettings.vue;h=d08b943f1da65af646b883d1491e6ba75f7e3aba;hp=5d038865c380be2792ca081812f6da60cd137447;hb=d36ca1989daec86e5ad4b2e65c8a045af171fafd;hpb=96e9585a39ca3ccef59c701b3f7ac3809692ca73 diff --git a/client/src/components/Settings.vue b/client/src/components/Settings.vue index 5d038865..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,14 +77,15 @@ export default { if (!boardContainer) return; //no board on page const k = document.getElementById("myRange").value; - const movesWidth = (window.innerWidth >= 768 ? 280 : 0); //TODO: constant somewhere...; + const movesWidth = (window.innerWidth >= 768 ? 280 : 0); const minBoardWidth = 240; //TODO: same // 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"; }, }, };