X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=public%2Fjavascripts%2Fvariant.js;fp=public%2Fjavascripts%2Fvariant.js;h=5920c0c783d885bcaaba1e06f199f377c96598a5;hp=5a6c224a020e77bb68effe242dbe6424ec18108b;hb=97da8720d3f33cb0c29079baf42c52ed047c3049;hpb=badeb466c977ed9a8e1b464a2236001126decb9e diff --git a/public/javascripts/variant.js b/public/javascripts/variant.js index 5a6c224a..5920c0c7 100644 --- a/public/javascripts/variant.js +++ b/public/javascripts/variant.js @@ -2,8 +2,8 @@ new Vue({ el: "#VueElement", data: { display: "", //default to main hall; see "created()" function - gameid: undefined, //...yet - queryHash: "", + gameRef: undefined, //...for now + probId: undefined, conn: null, mode: "analyze", allowChat: false, @@ -19,14 +19,11 @@ new Vue({ }, }, created: function() { + window.onhashchange = this.setDisplay; if (!!localStorage["variant"]) - { location.hash = "#game?id=" + localStorage["gameId"]; - this.display = location.hash.substr(1); - } else this.setDisplay(); - window.onhashchange = this.setDisplay; // Our ID, always set (DB id if registered, collision-free random string otherwise) this.myid = user.id || localStorage["myid"] || "anon-" + getRandString(); this.conn = new WebSocket(socketUrl + "/?sid=" + this.myid + "&page=" + variant.id); @@ -56,7 +53,21 @@ new Vue({ location.hash = "#room"; //default const hashParts = location.hash.substr(1).split("?"); this.display = hashParts[0]; - this.queryHash = hashParts[1]; //may be empty, undefined... + if (hashParts[0] == "problems" && !!hashParts[1]) + { + // Show a specific problem + this.probId = hashParts[1].split("=")[1]; + } + else if (hashParts[0] == "game" && !!hashParts[1]) + { + // Show a specific game, maybe with a user ID + const params = hashParts[1].split("&").filter(h => h.split("=")[1]); + // TODO: Vue.set(...) probably required here + this.gameRef = { + id: params[0], + uid: params[1], //may be undefined + }; + } // Close menu on small screens: let menuToggle = document.getElementById("drawer-control"); if (!!menuToggle)