X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=app.js;h=8bd5e70a73f2f78e6f65be16244946cbd3e359e2;hb=016306e3aa2262e141899f8d4b900421d68f5439;hp=c553ce5abbab6e988d8dd9a0db494da010974bc0;hpb=21e8e7122487ae9417c5e7e72c25aa642b7a1226;p=xogo.git
diff --git a/app.js b/app.js
index c553ce5..8bd5e70 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 += `
-
-
-
-
- ${txt}
-
- `;
+ ${txt}
+
+
+
`;
$.getElementById("gameInfos").innerHTML = htmlContent;
});
};
@@ -207,7 +253,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 +285,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 +360,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();
});
}