Draft code reorganisation (+ fix Alice rules + stateless VariantRules object)
[vchess.git] / public / javascripts / variant.js
index e9e956c..ae576d8 100644 (file)
@@ -1,25 +1,25 @@
 new Vue({
        el: "#variantPage",
        data: {
-               display: getCookie("display-"+variant,""), //default: do not show anything...
-               problem: undefined, //current problem in view
+               display: "room", //default: main hall
+       },
+       created: function() {
+               // TODO: navigation becomes a little more complex
+               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
-                               setCookie("display-"+variant, "");
-                       }
-                       else
-                       {
-                               this.display = elt; //show
-                               setCookie("display-"+variant, elt);
-                       }
-               },
-               showProblem: function(problemTxt) {
-                       this.problem = JSON.parse(problemTxt);
-                       this.display = "game";
+               setDisplay: function(elt) {
+                       this.display = elt;
+                       // Close menu on small screens:
+                       let menuToggle = document.getElementById("drawer-control");
+                       if (!!menuToggle)
+                               menuToggle.checked = false;
                },
        },
 });
+
+// TODO:
+// si quand on arrive il y a une continuation "humaine" : display="game" et retour à la partie !