X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=app.js;h=56ba25a02854c2f60d3014372d730ebd8c5cfbe5;hb=2dba3fe12f4a2970e5ed01e77e07c7bece56bdc0;hp=f89706233b24ef2fb380202f9cc0f59cceb24c7f;hpb=41534b92f0bcfc8ef5f58d8040706a5e7ce088c6;p=xogo.git diff --git a/app.js b/app.js index f897062..56ba25a 100644 --- a/app.js +++ b/app.js @@ -30,6 +30,22 @@ if (!localStorage.getItem("name")) const sid = localStorage.getItem("sid"); $.getElementById("myName").value = localStorage.getItem("name"); +// "Material" input field name +let inputName = document.getElementById("myName"); +let formField = document.getElementById("ng-name"); +const setActive = (active) => { + if (active) formField.classList.add("form-field--is-active"); + else { + formField.classList.remove("form-field--is-active"); + inputName.value === "" ? + formField.classList.remove("form-field--is-filled") : + formField.classList.add("form-field--is-filled"); + } +}; +inputName.onblur = () => setActive(false); +inputName.onfocus = () => setActive(true); +inputName.focus(); + ///////// // Utils @@ -39,10 +55,15 @@ function setName() { // Turn a "tab" on, and "close" all others function toggleVisible(element) { - for (elt of document.querySelectorAll('body > div')) { + for (elt of document.querySelectorAll('main > div')) { if (elt.id != element) elt.style.display = "none"; else elt.style.display = "block"; } + if (element.id == "newGame") { + // Workaround "superposed texts" effect + inputName.focus(); + inputName.blur(); + } } let seek_vname; @@ -89,47 +110,64 @@ function toggleStyle(e, word) { let options; function prepareOptions(Rules) { options = {}; - let optHtml = ""; - for (let select of Rules.Options.select) { - optHtml += ` - - ` + + select.options.map(option => { return ` + `; + }).join("") + ` + + + + `; + }).join(""); + optHtml += Rules.Options.check.map(check => { + return ` +
+ +
`; + }).join(""); + if (Rules.Options.styles.length >= 1) { + optHtml += '
'; + let i = 0; + const stylesLength = Rules.Options.styles.length; + while (i < stylesLength) { + optHtml += '
'; + for (let j=i; j${style}`; + } + optHtml += "
"; + i += 4; } - optHtml += ''; - } - for (let check of Rules.Options.check) { - optHtml += ` - - = 1) optHtml += "

"; - for (let style of Rules.Options.styles) { - optHtml += ` - - ${style} - `; + optHtml += "

"; } - if (Rules.Options.styles.length >= 1) optHtml += "

"; $.getElementById("gameOptions").innerHTML = optHtml; } function getGameLink() { const vname = $.getElementById("selectVariant").value; const color = $.getElementById("selectColor").value; - for (const select of $.querySelectorAll("#gameOptions > select")) { + for (const select of $.querySelectorAll("#gameOptions select")) { let value = select.value; if (select.attributes["data-numeric"]) value = parseInt(value, 10); options[ select.id.split("_")[1] ] = value; } - for (const check of $.querySelectorAll("#gameOptions > input")) + for (const check of $.querySelectorAll("#gameOptions input")) options[ check.id.split("_")[1] ] = check.checked; send("creategame", { vname: vname, @@ -143,28 +181,36 @@ const fillGameInfos = (gameInfos, oppIndex) => { .then(res => res.text()) .then(txt => { let htmlContent = ` -

- ${gameInfos.vdisp} - vs. ${gameInfos.players[oppIndex].name} -

-
-

`; - htmlContent += - Object.entries(gameInfos.options).map(opt => { - return ( - '' + - (opt[1] === true ? opt[0] : `${opt[0]}:${opt[1]}`) + - '' - ); - }) - .join(", "); +

+

+ ${gameInfos.vdisp} + vs. ${gameInfos.players[oppIndex].name} +

+
`; + const options = Object.entries(gameInfos.options); + if (options.length > 0) { + htmlContent += '
'; + let i = 0; + while (i < options.length) { + htmlContent += '
'; + for (let j=i; j' + + (opt[1] === true ? opt[0] : `${opt[0]}:${opt[1]}`) + " " + + ''; + } + htmlContent += "
"; + i += 4; + } + htmlContent += "
"; + } htmlContent += ` -

-
-
- ${txt} -
- `; +
${txt}
+
+ +
`; $.getElementById("gameInfos").innerHTML = htmlContent; }); }; @@ -328,7 +374,7 @@ const afterPlay = (move) => { //pack into one moves array, then send start: move.start, end: move.end }); - if (vr.turn != color) { + if (vr.turn != playerColor) { toggleTurnIndicator(false); send("newmove", { gid: gid, moves: curMoves, fen: vr.getFen() }); curMoves = []; @@ -354,13 +400,13 @@ const conditionalLoadCSS = (vname) => { } }; -let vr, color; +let vr, playerColor; function initializeGame(obj) { const options = obj.options || {}; import(`/variants/${obj.vname}/class.js`).then(module => { const Rules = module.default; conditionalLoadCSS(obj.vname); - color = (sid == obj.players[0].sid ? "w" : "b"); + playerColor = (sid == obj.players[0].sid ? "w" : "b"); // Init + remove potential extra DOM elements from a previous game: document.getElementById("boardContainer").innerHTML = `
{