Improve style on variant page; TODO: problems, Crazyhouse
[vchess.git] / public / javascripts / variant.js
index 2174c50..f77be32 100644 (file)
@@ -1,15 +1,23 @@
 new Vue({
        el: "#variantPage",
-       data: { display: "" }, //do not show anything...
-       // TODO: listen event "show problem", avec le probleme stringifié en arg
-       // Alors: display=game, mode=friend, newGame(fen, turn, ...),
-       //   et set Instructions+Soluce
+       data: {
+               display: "game", //default: play!
+               problem: undefined, //current problem in view
+       },
+       created: function() {
+               const url = window.location.href;
+               const hashPos = url.indexOf("#");
+               if (hashPos >= 0)
+                       this.setDisplay(url.substr(hashPos+1));
+       },
        methods: {
-               toggleDisplay: function(elt) {
-                       if (this.display == elt)
-                               this.display = ""; //hide
-                       else
-                               this.display = elt; //show
+               showProblem: function(problemTxt) {
+                       this.problem = JSON.parse(problemTxt);
+                       this.display = "game";
+               },
+               setDisplay: function(elt) {
+                       this.display = elt;
+                       document.getElementById("drawer-control").checked = false;
                },
        },
 });