Compare commits
2 Commits
ea141bfde6
...
3834e579a6
Author | SHA1 | Date | |
---|---|---|---|
3834e579a6 | |||
f0b9052211 |
@ -80,8 +80,8 @@ $grille = new Grille($hauteur, $largeur, $id);
|
||||
</table>
|
||||
</h1>
|
||||
<form id="grilleForm" class="grille" method="get" location=".">
|
||||
<input type="hidden" id="hauteur" name="lignes" value="<?= $hauteur ?>" />
|
||||
<input type="hidden" id="largeur" name="colonnes" value="<?= $largeur ?>" />
|
||||
<input type="hidden" id="lignes" name="lignes" value="<?= $hauteur ?>" />
|
||||
<input type="hidden" id="colonnes" name="colonnes" value="<?= $largeur ?>" />
|
||||
<input type="hidden" id="solution_hashee" value="<?= $grille->hash() ?>" />
|
||||
<table>
|
||||
<tr>
|
||||
|
36
script.js
36
script.js
@ -1,6 +1,3 @@
|
||||
const inputs = Array.from(grilleForm.querySelectorAll('input[type="text"]'));
|
||||
let nb_cases = inputs.length;
|
||||
|
||||
async function sha256(text) {
|
||||
const encoder = new TextEncoder();
|
||||
const data = encoder.encode(text);
|
||||
@ -9,7 +6,11 @@ async function sha256(text) {
|
||||
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
||||
}
|
||||
|
||||
const inputs = Array.from(grilleForm.querySelectorAll('input[type="text"]'));
|
||||
let largeur = Number(colonnes.value);
|
||||
let nb_cases = inputs.length;
|
||||
let index = 0;
|
||||
|
||||
inputs.forEach(input => {
|
||||
input.index = index++;
|
||||
|
||||
@ -18,9 +19,6 @@ inputs.forEach(input => {
|
||||
};
|
||||
|
||||
input.onkeydown = function (event) {
|
||||
console.log(largeur);
|
||||
largeur = Number(largeur.value);
|
||||
console.log(largeur);
|
||||
switch (event.key) {
|
||||
case 'ArrowUp':
|
||||
inputs[(input.index - largeur + nb_cases) % nb_cases].focus();
|
||||
@ -37,32 +35,6 @@ inputs.forEach(input => {
|
||||
}
|
||||
};
|
||||
|
||||
input.oninput = function (event) {
|
||||
this.value = this.value.toUpperCase();
|
||||
if (!input.checkValidity()) {
|
||||
input.value = '';
|
||||
}
|
||||
if (grilleForm.checkValidity()) {
|
||||
sha256(inputs.map(input => input.value).join('')).then(hash => {
|
||||
if (hash == '<?= $grille->hash() ?>') {
|
||||
if (confirm('Bravo ! \nUne nouvelle partie ?')) {
|
||||
location.href = location.href.replace(/grille=[a-f0-9]{13}&/, '');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
document.querySelectorAll('input').forEach(input => {
|
||||
input.onkeydown = function (event) {
|
||||
switch (event.key) {
|
||||
case 'ArrowRight':
|
||||
inputs[(input.index + 1) % nb_cases].focus();
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
input.oninput = function (event) {
|
||||
this.value = this.value.toUpperCase();
|
||||
if (!input.checkValidity()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user