Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix keyboard lag and submit spacing on mobile #34

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 66 additions & 31 deletions assets/scripts/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var submissionLst = [];
KEYBOARD_EL.innerHTML = `<div id="keyboard-cont">
<div class="first-row">
<button class="keyboard-button boxed" id="q">Q</button>
<button class="keyboard-button boxed" id="q">W</button>
<button class="keyboard-button boxed" id="w">W</button>
<button class="keyboard-button boxed" id="e">E</button>
<button class="keyboard-button boxed" id="r">R</button>
<button class="keyboard-button boxed" id="t">T</button>
Expand Down Expand Up @@ -102,14 +102,14 @@ function checkLevel(level){
dictValue = "levelThree"

} else {
window.location.replace("ahshit.html");
window.location.replace("ahshit.html");
}
}

// POPULATE PAGE WITH LEVEL APPROPRIATE WORDS
function assignSound(levelPath, words){
path = `assets/audio/${levelPath}`;
try{
try{
// setting neutral values
wordLst = words;
numSubmitted = 0;
Expand All @@ -122,7 +122,7 @@ function assignSound(levelPath, words){
wordFivePlayer.src = `${path}/${words[4]}.mp3`
} catch(error) {
console.log(error)
}
}
}

// MOVE TO NEXT ROUND
Expand All @@ -134,7 +134,7 @@ function nextRound(){
} else if (level.textContent == "Level Three: Hard"){
endGame();
} else {
window.location.replace("ahshit.html");
window.location.replace("ahshit.html");
}
nextRoundBtn.innerHTML = `<div></div>`
checkLevel(level)
Expand Down Expand Up @@ -215,21 +215,21 @@ function checkGuess() {
if ((attemptStr.toLowerCase() == activeWord.toLowerCase())) {
stopSound(activePlayer[1]);
activePlayer[0].style.backgroundColor = "#79b15a";
activePlayer[0].classList.add("submitted", "fa-check");
activePlayer[0].classList.add("submitted", "fa-check");
activePlayer[0].classList.remove("clicked","fa-play-circle", "fa-circle-stop","btn");

// RECORD FOR RESULTS
activePlayer[3] = `<td>${attemptStr}</td>`
//submissionLst.push(`<td>${attemptStr}</td>`)


// DEACTIVATE WORD
activeWord = null;
activePlayer = null;
activePlayer = null;
} else {
stopSound(activePlayer[1]);
activePlayer[0].style.backgroundColor = "#d25842";
activePlayer[0].classList.add("submitted", "fa-xmark");
activePlayer[0].classList.add("submitted", "fa-xmark");
activePlayer[0].classList.remove("clicked","fa-circle-stop", "fa-play-circle","btn");

// RECORD FOR RESULTS
Expand All @@ -238,10 +238,10 @@ function checkGuess() {

// DEACTIVATE WORD
activeWord = null;
activePlayer = null;
activePlayer = null;
}
attemptStr = '';
attempt.value = attemptStr;
attempt.value = attemptStr;
numSubmitted += 1;

if (numSubmitted == 5) {
Expand Down Expand Up @@ -286,7 +286,7 @@ function updatePlayer(playerLst, activePlayer) {
activePlayer[0].classList.add("fa-play-circle");

lastActiveWord = activeWord;

// DEACTIVATE WORD
activeWord = null;
activePlayer = null;
Expand Down Expand Up @@ -350,63 +350,98 @@ wordFive.addEventListener("click", (e) => {
// LINK ONSCREEN KEYBOARD FUNCTIONALITY TO KEYPRESSS
document.getElementById("keyboard-cont").addEventListener("click", (e) => {
const target = e.target

if (!target.classList.contains("keyboard-button")) {
return
}

let key = target.textContent

if (target.classList.contains("fa-delete-left")){
if (target.classList.contains("fa-delete-left")) {
target.classList.add("clicked")
setTimeout(() => {
setTimeout(target.classList.remove("clicked"));
}, 50);
deleteLetter();
return
//key = "Backspace"
}

if (key==="submit"){
if (key === "submit") {
target.classList.add("clicked")
setTimeout(() => {
setTimeout(target.classList.remove("clicked"));
}, 50);
guessPreprocess();
return
//key = "Enter"
}

let pressedKey = target.innerText;
insertLetter(pressedKey)
let found = pressedKey.match(/[a-z]/gi)

if (!found || found.length > 1) {
return
} else {
insertLetter(pressedKey)
document.querySelector(`#${pressedKey.toLowerCase()}`).classList.add("clicked")
setTimeout(() => {
setTimeout(document.querySelector(`#${pressedKey.toLowerCase()}`).classList.remove("clicked"));
}, 50);
return;
}
//document.querySelector(`#${pressedKey.toLowerCase()}`).classList.add("clicked")
//document.dispatchEvent(new KeyboardEvent("keyup", {'key': key}))
})

// KEYPRESS TYPING LISTENER
document.addEventListener("keyup", (e) => {
document.addEventListener("keydown", (e) => {

let pressedKey = String(e.key)
let found = pressedKey.match(/[a-z]/gi)
let pressedKey = String(e.key)
let found = pressedKey.match(/[a-z]/gi)

if (pressedKey === "Enter") {
document.querySelector(`#${pressedKey}`).classList.add("clicked");
return;
}

if (pressedKey === "Backspace" & attemptStr.length != 0) {
document.querySelector(`#${pressedKey}`).classList.add("clicked")
setTimeout(() => {
setTimeout(document.querySelector(`#${pressedKey}`).classList.remove("clicked"));
}, 50);
return;
}

if (!found || found.length > 1) {
return
} else if (document.querySelector(`#${pressedKey.toLowerCase()}`) && !document.querySelector(`#${pressedKey.toLowerCase()}`).classList.contains("clicked")) {
insertLetter(pressedKey)
document.querySelector(`#${pressedKey.toLowerCase()}`).classList.add("clicked")
return;
} else {
return;
}
})

document.addEventListener("keyup", (e) => {

let pressedKey = String(e.key)
let found = pressedKey.match(/[a-z]/gi)

if (pressedKey === "Enter") {
document.querySelector(`#${pressedKey}`).classList.remove("clicked");
guessPreprocess();
return;
}

if (pressedKey === "Backspace" & attemptStr.length != 0) {
document.querySelector(`#${pressedKey}`).classList.add("clicked")
setTimeout(() => {
setTimeout(document.querySelector(`#${pressedKey}`).classList.remove("clicked"));
}, 50);
document.querySelector(`#${pressedKey}`).classList.remove("clicked");
deleteLetter()
return;
}

if (!found || found.length > 1) {
return
} else {
insertLetter(pressedKey)
document.querySelector(`#${pressedKey.toLowerCase()}`).classList.add("clicked")
setTimeout(() => {
setTimeout(document.querySelector(`#${pressedKey.toLowerCase()}`).classList.remove("clicked"));
}, 50);
document.querySelector(`#${pressedKey.toLowerCase()}`).classList.remove("clicked");
return;
}
})
Expand Down
70 changes: 47 additions & 23 deletions assets/scripts/practice.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ KEYBOARD_EL.innerHTML = `<div id="keyboard-cont">
<button class="keyboard-button boxed" id="m">M</button>
<button class="keyboard-button boxed fa fa-delete-left" style="line-height:1.5" id="Backspace"></button>
</div>
<div class="fourthsrow">
<div class="fourth-row">
<button class="keyboard-button boxed" id="Enter">submit</button>
</div>
</div>`
Expand All @@ -79,7 +79,7 @@ function checkLevel(level){
wordLst = shuffle(hardWords)
levelPath = "levelThreeNEW"
} else {
window.location.replace("ahshit.html");
window.location.replace("ahshit.html");
}
path = `assets/audio/${levelPath}`;
updateWord();
Expand Down Expand Up @@ -185,7 +185,7 @@ function checkGuess() {
}

attemptStr = '';
attempt.value = attemptStr;
attempt.value = attemptStr;
return
}

Expand All @@ -195,7 +195,7 @@ function updatePlayer(playerLst, activePlayer) {
stopSound(activePlayer[1]);
activePlayer[0].classList.remove("clicked","fa-circle-stop");
activePlayer[0].classList.add("fa-play-circle");

lastActiveWord = activeWord;

// DEACTIVATE WORD
Expand Down Expand Up @@ -234,20 +234,28 @@ wordOne.addEventListener("click", (e) => {
// LINK ONSCREEN KEYBOARD FUNCTIONALITY TO KEYPRESSS
document.getElementById("keyboard-cont").addEventListener("click", (e) => {
const target = e.target

if (!target.classList.contains("keyboard-button")) {
return
}

let key = target.textContent

if (target.classList.contains("fa-delete-left")){
if (target.classList.contains("fa-delete-left")) {
target.classList.add("clicked")
setTimeout(() => {
setTimeout(target.classList.remove("clicked"));
}, 50);
deleteLetter();
return
//key = "Backspace"
}

if (key==="submit"){
if (key === "submit") {
target.classList.add("clicked")
setTimeout(() => {
setTimeout(target.classList.remove("clicked"));
}, 50);
guessPreprocess();
return
//key = "Enter"
Expand All @@ -263,44 +271,60 @@ document.getElementById("keyboard-cont").addEventListener("click", (e) => {
document.querySelector(`#${pressedKey.toLowerCase()}`).classList.add("clicked")
setTimeout(() => {
setTimeout(document.querySelector(`#${pressedKey.toLowerCase()}`).classList.remove("clicked"));
}, 50);
}, 50);
return;
}
//document.dispatchEvent(new KeyboardEvent("keyup", {'key': key}))
})

// KEYPRESS TYPING LISTENER
document.addEventListener("keyup", (e) => {
document.addEventListener("keydown", (e) => {

let pressedKey = String(e.key)
let found = pressedKey.match(/[a-z]/gi)
let pressedKey = String(e.key)
let found = pressedKey.match(/[a-z]/gi)

if (pressedKey === "Enter") {
document.querySelector(`#${pressedKey}`).classList.add("clicked");
return;
}

if (pressedKey === "Backspace" & attemptStr.length != 0) {
document.querySelector(`#${pressedKey}`).classList.add("clicked")
setTimeout(() => {
setTimeout(document.querySelector(`#${pressedKey}`).classList.remove("clicked"));
}, 50);
return;
}

if (!found || found.length > 1) {
return
} else if (document.querySelector(`#${pressedKey.toLowerCase()}`) && !document.querySelector(`#${pressedKey.toLowerCase()}`).classList.contains("clicked")) {
insertLetter(pressedKey)
document.querySelector(`#${pressedKey.toLowerCase()}`).classList.add("clicked")
return;
} else {
return;
}
})

document.addEventListener("keyup", (e) => {

let pressedKey = String(e.key)
let found = pressedKey.match(/[a-z]/gi)

if (pressedKey === "Enter") {
document.querySelector(`#${pressedKey}`).classList.remove("clicked");
guessPreprocess()
return;
}

if (pressedKey === "Backspace" & attemptStr.length != 0) {
document.querySelector(`#${pressedKey}`).classList.add("clicked")
setTimeout(() => {
setTimeout(document.querySelector(`#${pressedKey}`).classList.remove("clicked"));
}, 50);
document.querySelector(`#${pressedKey}`).classList.remove("clicked");
deleteLetter()
return;
}

if (!found || found.length > 1) {
return
} else {
insertLetter(pressedKey)
document.querySelector(`#${pressedKey.toLowerCase()}`).classList.add("clicked")
setTimeout(() => {
setTimeout(document.querySelector(`#${pressedKey.toLowerCase()}`).classList.remove("clicked"));
}, 50);
document.querySelector(`#${pressedKey.toLowerCase()}`).classList.remove("clicked");
return;
}
})
Expand Down
Loading