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

clean up index.js ready function #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
29 changes: 18 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ const splitText = all_text.split(' ');
let testLength = 25;
let maxSplitPoint = splitText.length-testLength;

const rstlne = 'qagwsxdecfrvzl?;hbunjkimyo,pt. '
const twof = 'jxmwsdrnlctbzgvqhyuafie,op.k;? '
const onef = 'vgfcdnlatreoismhupwy.b,xkzjq;? '
const rstlne = 'qagwsxdecfrvzl?;hbunjkimyo,pt. ';
const twof = 'jxmwsdrnlctbzgvqhyuafie,op.k;? ';
const onef = 'vgfcdnlatreoismhupwy.b,xkzjq;? ';

const deleteIndex = 31;
const spaceIndex = 30;

let curIndex = 0;
let curLayout = rstlne;
Expand All @@ -17,6 +20,7 @@ let endTime;
$(document).ready(() => {
resetText();

// add layouts to dropdown menu and add onChange lambda
$('#layout-selector')
.dropdown({
values: [
Expand Down Expand Up @@ -75,25 +79,28 @@ $(document).ready(() => {
resetText();
});

for(let i=0; i<=31; i++) {
// for each key in the current layout, plus the backspace/delete key
for(let i = 0; i <= curLayout.length + 1; i++) {
// add on-click lambda to each key
$(`#key-${i}`).click(function() {
// get key index from html id of visual key element
let index = parseInt(this.id.split('-')[1])
if (index == 31) {
// enables backspace / delete feature
if (index == deleteIndex) {
// if typedText isn't empty
if (typedText.length > 0) {
// remove 1 character from end of typed text
typedText = typedText.substring(0, typedText.length-1)
}
} else if (index == 30) {
if (typedText.length > 0) {
typedText += curLayout[index]
}
} else {
// if start time was reset, set it to current time
if (startTime == 0) {
startTime = Date.now();
}
// add character corresponding to pressed key
typedText += curLayout[index]
}
let formatText = evaluateText()
updateText(formatText)
updateText(evaluateText())
});
}
})
Expand Down