TODO: fix draw logic
[vchess.git] / client / src / components / BaseGame.vue
index 27821c3..595f9aa 100644 (file)
@@ -1,7 +1,8 @@
 <template lang="pug">
-div#baseGame(tabindex=-1 @click="() => focusBg()" @keydown="handleKeys")
+div#baseGame(tabindex=-1 @click="() => focusBg()"
+    @keydown="handleKeys" @wheel="handleScroll")
   input#modalEog.modal(type="checkbox")
-  div(role="dialog" aria-labelledby="eogMessage")
+  div(role="dialog" data-checkbox="modalEog" aria-labelledby="eogMessage")
     .card.smallpad.small-modal.text-center
       label.modal-close(for="modalEog")
       h3#eogMessage.section {{ endgameMessage }}
@@ -25,8 +26,7 @@ div#baseGame(tabindex=-1 @click="() => focusBg()" @keydown="handleKeys")
       MoveList(v-if="showMoves" :score="game.score" :message="game.scoreMsg"
         :firstNum="firstMoveNumber" :moves="moves" :cursor="cursor"
         @goto-move="gotoMove")
-  // TODO: clearer required ?!
-  .clearer
+    .clearer
 </template>
 
 <script>
@@ -78,13 +78,22 @@ export default {
       this.re_setVariables();
   },
   mounted: function() {
-    const boardSize = localStorage.getItem("boardSize");
-    if (!!boardSize)
-      document.getElementById("boardContainer").style.width = boardSize + "px";
+    // Take full width on small screens:
+    let boardSize = parseInt(localStorage.getItem("boardSize"));
+    if (!boardSize)
+    {
+      boardSize = (window.innerWidth >= 768
+        ? Math.min(600, 0.5*window.innerWidth) //heuristic...
+        : window.innerWidth);
+    }
+    const movesWidth = (window.innerWidth >= 768 ? 280 : 0);
+    document.getElementById("boardContainer").style.width = boardSize + "px";
+    let gameContainer = document.getElementById("gameContainer");
+    gameContainer.style.width = (boardSize + movesWidth) + "px";
   },
   methods: {
     focusBg: function() {
-      // TODO: small blue border appears...
+      // NOTE: small blue border appears...
       document.getElementById("baseGame").focus();
     },
     handleKeys: function(e) {
@@ -109,6 +118,16 @@ export default {
           break;
       }
     },
+    handleScroll: function(e) {
+      if (this.game.mode == "analyze" || this.game.score != "*")
+      {
+        e.preventDefault();
+        if (e.deltaY < 0)
+          this.undo();
+        else if (e.deltaY > 0)
+          this.play();
+      }
+    },
     re_setVariables: function() {
       this.endgameMessage = "";
       this.orientation = this.game.mycolor || "w"; //default orientation for observed games
@@ -334,7 +353,7 @@ export default {
 };
 </script>
 
-<style lang="sass">
+<style lang="sass" scoped>
 #baseGame
   width: 100%
 
@@ -344,11 +363,6 @@ export default {
 
 #modal-eog+div .card
   overflow: hidden
-@media screen and (min-width: 768px)
-  #controls
-    width: 400px
-    margin-left: auto
-    margin-right: auto
 #controls
   margin-top: 10px
   margin-left: auto
@@ -357,16 +371,23 @@ export default {
     display: inline-block
     width: 20%
     margin: 0
+@media screen and (min-width: 768px)
+  #controls
+    max-width: 400px
 #pgnDiv
   text-align: center
   margin-left: auto
   margin-right: auto
 #boardContainer
   float: left
+// TODO: later, maybe, allow movesList of variable width
+// or e.g. between 250 and 350px (but more complicated)
 #movesList
   width: 280px
   float: left
-
-.clearer
-  clear: both
+@media screen and (max-width: 767px)
+  #movesList
+    width: 100%
+    float: none
+    clear: both
 </style>