diff --git a/app.js b/app.js index 0dec1ac..cde00bb 100644 --- a/app.js +++ b/app.js @@ -1,4 +1,5 @@ const VALUES = "123456789" +const UNKNOWN = '.' const SUGESTION_DELAY = 60000 //ms let boxes = [] @@ -6,10 +7,11 @@ let rows = Array.from(Array(9), x => []) let columns = Array.from(Array(9), x => []) let regions = Array.from(Array(9), x => []) let suggestionTimer= null -let highlightedValue = "" +let selectedValue = "" let history = [] let accessKeyModifiers = "AccessKey+" let penStyle = "ink-pen" +let highlighting = false window.onload = function() { let rowId = 0 @@ -21,6 +23,8 @@ window.onload = function() { box.onfocus = onfocus box.oninput = oninput box.onblur = onblur + box.onclick = onclick + box.previousPlaceholder = "" } box.oncontextmenu = oncontextmenu box.rowId = rowId @@ -38,7 +42,10 @@ window.onload = function() { let savedGame = localStorage[location.href] if (savedGame) { boxes.forEach((box, i) => { - if (!box.disabled && savedGame[i] != '.') box.value = savedGame[i] + if (!box.disabled && savedGame[i] != UNKNOWN) { + box.value = savedGame[i] + box.previousValue = savedGame[i] + } }) } @@ -49,19 +56,19 @@ window.onload = function() { searchCandidatesOf(box) }) - enableButtons() - highlightAndTab() - if (/Win/.test(navigator.platform) || /Linux/.test(navigator.platform)) accessKeyModifiers = "Alt+Maj+" else if (/Mac/.test(navigator.platform)) accessKeyModifiers = "⌃⌥" for(node of document.querySelectorAll("*[accesskey]")) { node.title += " [" + (node.accessKeyLabel || accessKeyModifiers + node.accessKey) + "]" } + enableButtons() + highlightAndTab() + document.onclick = function (event) { contextMenu.style.display = "none" } - suggestionTimer = setTimeout(showSuggestion, 30000) + suggestionTimer = setTimeout(showSuggestion, SUGESTION_DELAY) if ("serviceWorker" in navigator) { navigator.serviceWorker.register("service-worker.js") @@ -85,6 +92,18 @@ function searchCandidatesOf(box) { } } +function onclick() { + if (selectedValue) { + if (penStyle == "ink-pen") { + this.value = selectedValue + } else { + if (!this.value.includes(selectedValue)) + this.value += selectedValue + } + oninput.apply(this) + } +} + function onfocus() { if (penStyle == "pencil" && this.value == "") { this.value = this.placeholder @@ -96,7 +115,9 @@ function onfocus() { } function oninput() { - history.push({box: this, value: this.previousValue || "", placeholder: this.previousPlaceholder || ""}) + history.push({box: this, value: this.previousValue, placeholder: this.previousPlaceholder}) + this.previousValue = this.value + this.previousPlaceholder = this.placeholder undoButton.disabled = false if (penStyle != "pencil") { refresh(this) @@ -165,29 +186,33 @@ function onblur() { this.value = "" this.classList.remove("pencil") } - this.previousValue = this.value - this.previousPlaceholder = this.placeholder } function enableButtons() { for (button of buttons.getElementsByTagName("button")) { if (boxes.filter(box => box.value == "").some(box => box.candidates.has(button.textContent))) { button.disabled = false + if (button.previousTitle) { + button.title = button.previousTitle + button.previousTitle = null + } } else { button.disabled = true - if (highlightedValue == button.textContent) highlightedValue = "" + button.previousTitle = button.title + button.title = "Tous les " + button.textContent + " sont posés" + if (selectedValue == button.textContent) selectedValue = "" } } } function highlight(value) { - if (value == highlightedValue) { - highlightedValue = "" + if (value == selectedValue) { + selectedValue = "" } else { - highlightedValue = value + selectedValue = value } for (button of buttons.getElementsByTagName("button")) { - if (button.textContent == highlightedValue) button.classList.add("pressed") + if (button.textContent == selectedValue) button.classList.add("pressed") else button.classList.remove("pressed") } highlightAndTab() @@ -195,15 +220,15 @@ function highlight(value) { } function highlightAndTab() { - if (highlightedValue) { + if (highlighting && selectedValue) { boxes.forEach(box => { - if (box.value == highlightedValue) { + if (box.value == selectedValue) { box.classList.add("same-value") box.tabIndex = -1 } else { box.classList.remove("same-value") - if (box.candidates.has(highlightedValue)) { + if (box.candidates.has(selectedValue)) { box.classList.remove("forbidden-value") box.tabIndex = 0 } else { @@ -319,3 +344,13 @@ function eraseAll() { highlightAndTab() } } + +function toggleHighlighting() { + highlighting = !highlighting + if (highlighting) { + highlighterButton.classList.add("pressed") + } else { + highlighterButton.classList.remove("pressed") + } + highlightAndTab() +} diff --git a/img/highlighter.svg b/img/highlighter.svg new file mode 100644 index 0000000..e3019af --- /dev/null +++ b/img/highlighter.svg @@ -0,0 +1,44 @@ + + + diff --git a/img/ink-eraser.png b/img/ink-eraser.png deleted file mode 100644 index 10a6a47..0000000 Binary files a/img/ink-eraser.png and /dev/null differ diff --git a/img/ink-eraser.svg b/img/ink-eraser.svg new file mode 100644 index 0000000..b233c46 --- /dev/null +++ b/img/ink-eraser.svg @@ -0,0 +1,43 @@ + + + diff --git a/img/ink-pen.png b/img/ink-pen.png deleted file mode 100644 index c573e0c..0000000 Binary files a/img/ink-pen.png and /dev/null differ diff --git a/img/ink-pen.svg b/img/ink-pen.svg new file mode 100644 index 0000000..64ca976 --- /dev/null +++ b/img/ink-pen.svg @@ -0,0 +1,48 @@ + + + diff --git a/img/pencil-eraser.png b/img/pencil-eraser.png deleted file mode 100644 index fc752e1..0000000 Binary files a/img/pencil-eraser.png and /dev/null differ diff --git a/img/pencil-eraser.svg b/img/pencil-eraser.svg new file mode 100644 index 0000000..91cf5f4 --- /dev/null +++ b/img/pencil-eraser.svg @@ -0,0 +1,43 @@ + + + diff --git a/img/pencil.png b/img/pencil.png deleted file mode 100644 index 62a56dd..0000000 Binary files a/img/pencil.png and /dev/null differ diff --git a/img/pencil.svg b/img/pencil.svg new file mode 100644 index 0000000..72e7703 --- /dev/null +++ b/img/pencil.svg @@ -0,0 +1,45 @@ + + + diff --git a/img/undo.png b/img/undo.png deleted file mode 100644 index f3c80df..0000000 Binary files a/img/undo.png and /dev/null differ diff --git a/img/undo.svg b/img/undo.svg new file mode 100644 index 0000000..1c7c953 --- /dev/null +++ b/img/undo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/style.css b/style.css index 4bbe7a1..de51417 100644 --- a/style.css +++ b/style.css @@ -121,7 +121,7 @@ input::-webkit-calendar-picker-indicator { height: 2.5rem !important; } -.highlight-buttons { +.select-buttons { column-gap: 2px; } button, input[type="color"] { @@ -131,6 +131,10 @@ button, input[type="color"] { padding: 4px 9px 5px 9px; margin: 0px 1px 1px 1px; } +button img { + width: 16px; + height: 16px; +} button:enabled:hover { border-width: 1px; border-style: outset; @@ -211,3 +215,8 @@ a { .context-menu li.error:hover { background-color: #EEE; } + +.credits { + font-size: 0.8rem; + margin: 0; +} diff --git a/sudoku.php b/sudoku.php index 456a66a..315ed72 100644 --- a/sudoku.php +++ b/sudoku.php @@ -68,28 +68,31 @@ -