Skip to content

Commit

Permalink
Changed 'shiftWordSelection' functionality and modified easter egg
Browse files Browse the repository at this point in the history
'shiftWordSelection' now shifts your focus to the end of the previous word when pressing delete at the start of a word (assuming you have the 'auto-word' button turned on).

Added the ability to toggle the easter egg, as well as some error handling for the playing of sounds.
  • Loading branch information
tomasvana10 committed May 19, 2024
1 parent 73b7045 commit 654c406
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
27 changes: 24 additions & 3 deletions crossword_puzzle/cword_webapp/static/interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Interaction {
this.currentPlaceholder = 0;
this.doNotHandleStandardCellClick = false;
this.preventInitialLIZoom = true;
this.setCoordsToEndOfWord = false;

// When the DOM is ready, trigger the ``onLoad`` method
document.addEventListener("DOMContentLoaded", this.onLoad.bind(this));
Expand Down Expand Up @@ -131,7 +132,11 @@ class Interaction {

playClick() {
if (this.playClicks) {
return this.clicks[Math.floor(Math.random() * this.clicks.length)].play();
try {
return this.clicks[Math.floor(Math.random() * this.clicks.length)].play();
} catch (err) { } // This error detection prevents an error that I observed
// only once, and I forgot what it was, so this handling
// will be left empty.
}
}

Expand All @@ -153,7 +158,7 @@ class Interaction {
}

let inputValue = event.key;
this.playClick();
this.playClick()

// Handle the setting of a compound input element when pressing [Shift + 1]
if (inputValue === "!" && event.shiftKey) {
Expand Down Expand Up @@ -368,6 +373,9 @@ class Interaction {
newDef = document.querySelector(`[data-num="${num}"]`);
}
let oldCellCoords = this.cellCoords;
if (offset === -1) {
this.setCoordsToEndOfWord = true;
}
newDef.focus();
newDef.click();
newDef.blur();
Expand Down Expand Up @@ -457,6 +465,12 @@ class Interaction {
}
this.direction = dir;
this.cellCoords = Interaction.updateCellCoords(currentCell);
if (this.setCoordsToEndOfWord) { // When user is deleting with auto-word on.
this.cellCoords = Interaction.updateCellCoords(
[...this.getWordElements()].slice(-1)[0]
)
this.setCoordsToEndOfWord = false;
}
this.currentWord = this.updateCurrentWord();
this.setFocusMode(true);
}
Expand Down Expand Up @@ -1138,4 +1152,11 @@ Element.prototype.hasCorrectValue = function () {
let interaction = new Interaction();

// Enable easter egg through console
const egg = () => interaction.playClicks = true;
function egg() {
interaction.playClicks = !interaction.playClicks;
if (interaction.playClicks) {
return "EASTER EGG ON";
} else {
return "EASTER EGG OFF";
}
}
Loading

0 comments on commit 654c406

Please sign in to comment.