Loading static/js/jslinux.api.mjs +16 −0 Original line number Diff line number Diff line Loading @@ -157,3 +157,19 @@ export function runCommand(command) { // https://thewebdev.info/2021/05/02/how-to-programmatically-trigger-a-change-event-on-an-input-with-javascript/ textarea.dispatchEvent(new Event("input")) } /** * Enables auto-focus to the terminal whenever a key is pressed. * This allows the user to click on an exercise completion button and then seamlessly continue * typing into the terminal, without having to click it first. * * Note: This also prevents any shortcuts from working, so use with care */ export function enableAutoFocus() { window.onkeydown = function () { const textareaElement = document.querySelector("textarea.term_textarea") if (document.activeElement !== textareaElement) { textareaElement.focus() } } } static/js/yalikejazz.mjs +2 −15 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ import { State } from "./state.mjs" import * as tests from "./exercises.mjs" import { createExerciseCard, displayAsSolved, displayAsNonCurrent, displayAsCurrent } from "./exercises.cards.mjs" import { Exercise } from "./exercises.api.mjs" import { enableAutoFocus } from "./jslinux.api.mjs" const testId = new URLSearchParams(location.search).get("id") const currentTest = tests[testId] Loading Loading @@ -132,6 +133,7 @@ export function main() { document.querySelector("section.options").style.display = "none" } enableAutoFocus() initExerciseList() initActionLinks() Loading @@ -139,18 +141,3 @@ export function main() { } window.onload = main let verifiedTextareaExistance = false let textareaElement = null window.onkeydown = function () { if (!verifiedTextareaExistance) { textareaElement = document.querySelector("textarea.term_textarea") if (textareaElement) { verifiedTextareaExistance = true } } if (document.activeElement !== textareaElement) { console.log("Triggering") textareaElement.focus() } } No newline at end of file Loading
static/js/jslinux.api.mjs +16 −0 Original line number Diff line number Diff line Loading @@ -157,3 +157,19 @@ export function runCommand(command) { // https://thewebdev.info/2021/05/02/how-to-programmatically-trigger-a-change-event-on-an-input-with-javascript/ textarea.dispatchEvent(new Event("input")) } /** * Enables auto-focus to the terminal whenever a key is pressed. * This allows the user to click on an exercise completion button and then seamlessly continue * typing into the terminal, without having to click it first. * * Note: This also prevents any shortcuts from working, so use with care */ export function enableAutoFocus() { window.onkeydown = function () { const textareaElement = document.querySelector("textarea.term_textarea") if (document.activeElement !== textareaElement) { textareaElement.focus() } } }
static/js/yalikejazz.mjs +2 −15 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ import { State } from "./state.mjs" import * as tests from "./exercises.mjs" import { createExerciseCard, displayAsSolved, displayAsNonCurrent, displayAsCurrent } from "./exercises.cards.mjs" import { Exercise } from "./exercises.api.mjs" import { enableAutoFocus } from "./jslinux.api.mjs" const testId = new URLSearchParams(location.search).get("id") const currentTest = tests[testId] Loading Loading @@ -132,6 +133,7 @@ export function main() { document.querySelector("section.options").style.display = "none" } enableAutoFocus() initExerciseList() initActionLinks() Loading @@ -139,18 +141,3 @@ export function main() { } window.onload = main let verifiedTextareaExistance = false let textareaElement = null window.onkeydown = function () { if (!verifiedTextareaExistance) { textareaElement = document.querySelector("textarea.term_textarea") if (textareaElement) { verifiedTextareaExistance = true } } if (document.activeElement !== textareaElement) { console.log("Triggering") textareaElement.focus() } } No newline at end of file