X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Findex.js;h=0e2a2631dde814d5b701ac4c3620de49ed81895b;hb=4608eed94432356bd2df8c144d7d233913c6483c;hp=f59bc045ae28d0444ef11e0e1786223043b76e8e;hpb=b57dbd126734b4398861292c611197c6991ed3eb;p=vchess.git diff --git a/public/javascripts/index.js b/public/javascripts/index.js index f59bc045..0e2a2631 100644 --- a/public/javascripts/index.js +++ b/public/javascripts/index.js @@ -5,13 +5,14 @@ new Vue({ counts: {}, curPrefix: "", conn: null, + display: "variants", }, computed: { sortedCounts: function () { - // TODO: priorité aux parties corr où c'est à nous de jouer ! + const capitalizedPrefix = this.curPrefix.replace(/^\w/, c => c.toUpperCase()); const variantsCounts = variantArray .filter( v => { - return v.name.startsWith(this.curPrefix); + return v.name.startsWith(capitalizedPrefix); }) .map( v => { return { @@ -29,6 +30,9 @@ new Vue({ }, }, created: function() { + this.setDisplay(); + window.onhashchange = this.setDisplay; + const url = socketUrl; const sid = getRandString(); this.conn = new WebSocket(url + "/?sid=" + sid + "&page=index"); @@ -37,9 +41,9 @@ new Vue({ if (data.code == "counts") this.counts = data.counts; else if (data.code == "increase") - this.counts[data.vname]++; + this.counts[data.vid]++; else if (data.code == "decrease") - this.counts[data.vname]--; + this.counts[data.vid]--; }; const socketCloseListener = () => { this.conn = new WebSocket(url + "/?sid=" + sid + "&page=index"); @@ -48,37 +52,19 @@ new Vue({ }; this.conn.onmessage = socketMessageListener; this.conn.onclose = socketCloseListener; + + // TODO: AJAX call get corr games (all variants) + // si dernier lastMove sur serveur n'est pas le mien et nextColor == moi, alors background orange + // ==> background orange si à moi de jouer par corr (sur main index) + // (helper: static fonction "GetNextCol()" dans base_rules.js) + }, -// mounted: function() { -// // Handle key stroke -// document.onkeydown = event => { -// // Is it Back or Esc? If yes, apply action on current word -// if (event.keyCode == 8) //Back -// { -// event.preventDefault(); -// this.curPrefix = this.curPrefix.slice(0,-1); -// } -// else if (event.keyCode == 27) //Esc -// { -// event.preventDefault(); -// this.curPrefix = ""; -// } -// // Is it alphanumeric? If yes, stack it -// else if (_.range(48,58).includes(event.keyCode) -// || _.range(65,91).includes(event.keyCode) -// || _.range(97,123).includes(event.keyCode)) -// { -// let newChar = String.fromCharCode(event.keyCode); -// this.curPrefix += this.curPrefix.length==0 -// ? newChar.toUpperCase() -// : newChar.toLowerCase(); -// } -// // ...ignore everything else -// }; -// }, -}); + methods: { + setDisplay: function() { + if (!location.hash) + location.hash = "#variants"; //default + this.display = location.hash.substr(1); + }, -// TODO: -// si dernier lastMove sur serveur n'est pas le mien et nextColor == moi, alors background orange -// ==> background orange si à moi de jouer par corr (sur main index) -// (fonction "getNextCol()" dans base_rules.js ?) + }, +});