fix check on onpopstate
This commit is contained in:
parent
84d9222a1c
commit
57d06c3b53
77
sudoku.js
77
sudoku.js
@ -105,10 +105,10 @@ function loadGame(state) {
|
|||||||
undoButton.disabled = true
|
undoButton.disabled = true
|
||||||
fixGridLink.href = ""
|
fixGridLink.href = ""
|
||||||
}
|
}
|
||||||
boxes.forEach(searchCandidatesOf)
|
|
||||||
boxes.forEach(checkBox)
|
checkBoxes()
|
||||||
checkSuccess()
|
enableRadio()
|
||||||
refreshUI()
|
highlight()
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onpopstate = (event) => loadGame(event.state)
|
window.onpopstate = (event) => loadGame(event.state)
|
||||||
@ -138,6 +138,9 @@ function onfocus() {
|
|||||||
} else {
|
} else {
|
||||||
this.select()
|
this.select()
|
||||||
}
|
}
|
||||||
|
if (penColor && inkPenRadio.checked) {
|
||||||
|
this.style.setProperty("color", penColor)
|
||||||
|
}
|
||||||
this.style.caretColor = valueToInsert ? "transparent" : "auto"
|
this.style.caretColor = valueToInsert ? "transparent" : "auto"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,16 +165,13 @@ function onclick() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function oninput() {
|
function oninput() {
|
||||||
if (penColor) {
|
|
||||||
this.style.setProperty("color", penColor)
|
|
||||||
}
|
|
||||||
if (inkPenRadio.checked) {
|
if (inkPenRadio.checked) {
|
||||||
checkBox(this)
|
checkBox(this)
|
||||||
checkSuccess()
|
enableRadio()
|
||||||
refreshUI()
|
highlight()
|
||||||
saveGame()
|
|
||||||
fixGridLink.href = "?" + boxes.map(box => box.value || UNKNOWN).join("")
|
fixGridLink.href = "?" + boxes.map(box => box.value || UNKNOWN).join("")
|
||||||
}
|
}
|
||||||
|
saveGame()
|
||||||
restartLink.classList.remove("disabled")
|
restartLink.classList.remove("disabled")
|
||||||
undoButton.disabled = false
|
undoButton.disabled = false
|
||||||
}
|
}
|
||||||
@ -188,24 +188,50 @@ function checkBox(box) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (box.value) {
|
if (box.value) {
|
||||||
for (area of[{
|
for (let [area, neighbours] of Object.entries({
|
||||||
name: "région",
|
région: regions[box.regionId],
|
||||||
neighbours: regions[box.regionId]
|
ligne: rows[box.rowId],
|
||||||
}, {
|
colonne: columns[box.columnId],
|
||||||
name: "ligne",
|
}))
|
||||||
neighbours: rows[box.rowId]
|
for (neighbour of neighbours)
|
||||||
}, {
|
|
||||||
name: "colonne",
|
|
||||||
neighbours: columns[box.columnId]
|
|
||||||
}, ])
|
|
||||||
for (neighbour of area.neighbours)
|
|
||||||
if (box != neighbour && box.value == neighbour.value) {
|
if (box != neighbour && box.value == neighbour.value) {
|
||||||
for (neighbour of [box, neighbour]) {
|
for (neighbour of [box, neighbour]) {
|
||||||
neighbour.setCustomValidity(`Il y a un autre ${box.value} dans cette ${area.name}.`)
|
neighbour.setCustomValidity(`Il y a un autre ${box.value} dans cette ${area}.`)
|
||||||
neighbour.classList.add("is-invalid")
|
neighbour.classList.add("is-invalid")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkSuccess()
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkBoxes() {
|
||||||
|
boxes.forEach(box => {
|
||||||
|
box.setCustomValidity("")
|
||||||
|
box.classList.remove("is-invalid")
|
||||||
|
searchCandidatesOf(box)
|
||||||
|
if (box.candidates.size == 0) {
|
||||||
|
box.setCustomValidity("Aucun chiffre possible !")
|
||||||
|
box.classList.add("is-invalid")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
for (let [areaName, areas] of Object.entries({
|
||||||
|
région: regions,
|
||||||
|
ligne: rows,
|
||||||
|
colonne: columns,
|
||||||
|
}))
|
||||||
|
for (area of areas)
|
||||||
|
for (box1 of area)
|
||||||
|
for (box2 of area)
|
||||||
|
if (box1 != box2 && box1.value && box1.value == box2.value) {
|
||||||
|
for (box of [box1, box2]) {
|
||||||
|
box.setCustomValidity(`Il y a un autre ${box.value} dans cette ${areaName}.`)
|
||||||
|
box.classList.add("is-invalid")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkSuccess()
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkSuccess() {
|
function checkSuccess() {
|
||||||
@ -225,11 +251,6 @@ function checkSuccess() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function refreshUI() {
|
|
||||||
enableRadio()
|
|
||||||
highlight()
|
|
||||||
}
|
|
||||||
|
|
||||||
function enableRadio() {
|
function enableRadio() {
|
||||||
for (radio of insertRadios) {
|
for (radio of insertRadios) {
|
||||||
if (boxes.filter(box => box.value == "").some(box => box.candidates.has(radio.value))) {
|
if (boxes.filter(box => box.value == "").some(box => box.candidates.has(radio.value))) {
|
||||||
@ -281,7 +302,6 @@ function onblur() {
|
|||||||
this.value = ""
|
this.value = ""
|
||||||
//this.type = "number"
|
//this.type = "number"
|
||||||
this.classList.remove("pencil")
|
this.classList.remove("pencil")
|
||||||
saveGame()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -403,6 +423,7 @@ document.onkeydown = function(event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.onbeforeunload = function(event) {
|
window.onbeforeunload = function(event) {
|
||||||
|
saveGame()
|
||||||
if (sightCheckbox.checked) localStorage["tool"] = "sight"
|
if (sightCheckbox.checked) localStorage["tool"] = "sight"
|
||||||
else if (highlighterCheckbox.checked) localStorage["tool"] = "highlighter"
|
else if (highlighterCheckbox.checked) localStorage["tool"] = "highlighter"
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user