optimize
This commit is contained in:
parent
fa970170d4
commit
b5345e1a4d
12
js/sudoku.js
12
js/sudoku.js
@ -10,6 +10,7 @@ let valueToInsert = ""
|
|||||||
let history = []
|
let history = []
|
||||||
let accessKeyModifiers = "AccessKey+"
|
let accessKeyModifiers = "AccessKey+"
|
||||||
let easyBoxes = []
|
let easyBoxes = []
|
||||||
|
let insertRadios = []
|
||||||
|
|
||||||
function shuffle(iterable) {
|
function shuffle(iterable) {
|
||||||
array = Array.from(iterable)
|
array = Array.from(iterable)
|
||||||
@ -59,11 +60,14 @@ window.onload = function() {
|
|||||||
|
|
||||||
boxes.forEach(box => {
|
boxes.forEach(box => {
|
||||||
box.neighbourhood = new Set(rows[box.rowId].concat(columns[box.columnId]).concat(regions[box.regionId]))
|
box.neighbourhood = new Set(rows[box.rowId].concat(columns[box.columnId]).concat(regions[box.regionId]))
|
||||||
|
box.andNeighbourhood = Array.from(box.neighbourhood)
|
||||||
box.neighbourhood.delete(box)
|
box.neighbourhood.delete(box)
|
||||||
box.neighbourhood = Array.from(box.neighbourhood)
|
box.neighbourhood = Array.from(box.neighbourhood)
|
||||||
searchCandidatesOf(box)
|
searchCandidatesOf(box)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
insertRadios = Array.from(insertRadioGroup.getElementsByTagName("input"))
|
||||||
|
|
||||||
for (label of document.getElementsByTagName("label")) {
|
for (label of document.getElementsByTagName("label")) {
|
||||||
label.control.label = label
|
label.control.label = label
|
||||||
}
|
}
|
||||||
@ -169,7 +173,7 @@ function refreshBox(box) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function checkBox(box) {
|
function checkBox(box) {
|
||||||
box.neighbourhood.concat([box]).forEach(neighbour => {
|
box.andNeighbourhood.forEach(neighbour => {
|
||||||
neighbour.setCustomValidity("")
|
neighbour.setCustomValidity("")
|
||||||
neighbour.classList.remove("is-invalid")
|
neighbour.classList.remove("is-invalid")
|
||||||
searchCandidatesOf(neighbour)
|
searchCandidatesOf(neighbour)
|
||||||
@ -217,7 +221,7 @@ function refreshUI() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function enableRadio() {
|
function enableRadio() {
|
||||||
for (radio of insertRadioGroup.getElementsByTagName("input")) {
|
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))) {
|
||||||
radio.disabled = false
|
radio.disabled = false
|
||||||
radio.label.title = `Insérer un ${radio.value} [${radio.accessKeyLabel||(accessKeyModifiers+radio.accessKey)}]`
|
radio.label.title = `Insérer un ${radio.value} [${radio.accessKeyLabel||(accessKeyModifiers+radio.accessKey)}]`
|
||||||
@ -228,6 +232,7 @@ function enableRadio() {
|
|||||||
valueToInsert = ""
|
valueToInsert = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
insertRadios = insertRadios.filter(radio => !radio.disabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
function highlight() {
|
function highlight() {
|
||||||
@ -241,6 +246,7 @@ function highlight() {
|
|||||||
box.parentElement.classList.remove("table-primary")
|
box.parentElement.classList.remove("table-primary")
|
||||||
box.tabIndex = 0
|
box.tabIndex = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valueToInsert && highlighterCheckbox.checked && !box.candidates.has(valueToInsert)) {
|
if (valueToInsert && highlighterCheckbox.checked && !box.candidates.has(valueToInsert)) {
|
||||||
box.parentElement.classList.add("table-active")
|
box.parentElement.classList.add("table-active")
|
||||||
box.tabIndex = -1
|
box.tabIndex = -1
|
||||||
@ -261,7 +267,7 @@ function onblur() {
|
|||||||
if (this.classList.contains("pencil")) {
|
if (this.classList.contains("pencil")) {
|
||||||
this.placeholder = this.value
|
this.placeholder = this.value
|
||||||
this.value = ""
|
this.value = ""
|
||||||
//this.type = "number"
|
//this.type = "number"
|
||||||
this.classList.remove("pencil")
|
this.classList.remove("pencil")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user