X-Git-Url: https://git.auder.net/?a=blobdiff_plain;ds=sidebyside;f=app.js;h=a011513a48b74177845875b71d7cd1345b2eca32;hb=8022d544e472df7a213f95bd66f64d6f9cb14aaa;hp=c553ce5abbab6e988d8dd9a0db494da010974bc0;hpb=21e8e7122487ae9417c5e7e72c25aa642b7a1226;p=xogo.git
diff --git a/app.js b/app.js
index c553ce5..a011513 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,24 @@ 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 == "boardContainer") {
+ // Avoid smartphone scrolling effects (TODO?)
+ document.querySelector("html").style.overflow = "hidden";
+ document.body.style.overflow = "hidden";
+ }
+ else {
+ document.querySelector("html").style.overflow = "visible";
+ document.body.style.overflow = "visible";
+ if (element.id == "newGame") {
+ // Workaround "superposed texts" effect
+ inputName.focus();
+ inputName.blur();
+ }
+ }
}
let seek_vname;
@@ -74,8 +104,8 @@ function showNewGameForm() {
$.getElementById("selectColor").selectedIndex = 0;
toggleVisible("newGameForm");
import(`/variants/${vname}/class.js`).then(module => {
- const Rules = module.default;
- prepareOptions(Rules);
+ window.V = module.default;
+ prepareOptions();
});
}
}
@@ -87,50 +117,68 @@ function toggleStyle(e, word) {
}
let options;
-function prepareOptions(Rules) {
+function prepareOptions() {
options = {};
- let optHtml = "";
- for (let select of Rules.Options.select) {
- optHtml += `
-
-
-
-
- ${txt}
-
- `;
+ ${txt}
+
+
+
`;
$.getElementById("gameInfos").innerHTML = htmlContent;
});
};
@@ -207,7 +263,7 @@ const messageCenter = (msg) => {
switch (obj.code) {
// Start new game:
case "gamestart": {
- if (!$.hasFocus()) notifyMe("game");
+ if (document.hidden) notifyMe("game");
gid = obj.gid;
initializeGame(obj);
break;
@@ -239,7 +295,7 @@ const messageCenter = (msg) => {
break;
// Receive opponent's move:
case "newmove":
- if (!$.hasFocus()) notifyMe("move");
+ if (document.hidden) notifyMe("move");
vr.playReceivedMove(obj.moves, () => {
if (vr.getCurrentScore(obj.moves[obj.moves.length-1]) != "*") {
localStorage.removeItem("gid");
@@ -314,7 +370,7 @@ function notifyMe(code) {
}
if (Notification.permission === 'granted') doNotify();
else if (Notification.permission !== 'denied') {
- Notification.requestPermission().then((permission) => {
+ Notification.requestPermission().then(permission => {
if (permission === 'granted') doNotify();
});
}
@@ -358,21 +414,31 @@ let vr, playerColor;
function initializeGame(obj) {
const options = obj.options || {};
import(`/variants/${obj.vname}/class.js`).then(module => {
- const Rules = module.default;
+ window.V = module.default;
conditionalLoadCSS(obj.vname);
playerColor = (sid == obj.players[0].sid ? "w" : "b");
// Init + remove potential extra DOM elements from a previous game:
document.getElementById("boardContainer").innerHTML = `
-
+
-
+
`;
- vr = new Rules({
+ vr = new V({
seed: obj.seed, //may be null if FEN already exists (running game)
fen: obj.fen,
element: "chessboard",