MCPcopy Index your code
hub / github.com/marijnh/Eloquent-JavaScript / showHelp

Function showHelp

src/client/ejs.mjs:30–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28 let modName = /Mac/.test(navigator.platform) ? "Cmd-" : "Ctrl-"
29
30 function showHelp() {
31 let popup = document.body.appendChild(document.createElement("div"))
32 popup.className = "popup"
33 popup.appendChild(document.createElement("h2")).textContent = "Instructions"
34 popup.appendChild(document.createElement("p")).textContent = `Code snippets on this page can be edited and run by clicking them or moving focus to them and pressing Enter. Executed snippets share their environment with other snippets ran on the page, and some pre-defined code for the chapter. When inside the code editor, the following keyboard shortcuts are available:`
35 for (let [key, desc] of [
36 [modName + "Enter", "Run code"],
37 [modName + "j", "Revert code"],
38 [modName + "↓", "Deactivate editor"],
39 [modName + "Escape", "Reset environment"],
40 ]) {
41 let b = popup.appendChild(document.createElement("div"))
42 b.appendChild(document.createElement("kbd")).textContent = key
43 b.appendChild(document.createTextNode(": " + desc))
44 }
45 popup.tabIndex = 0
46 popup.addEventListener("blur", () => popup.remove())
47 popup.addEventListener("keydown", e => {
48 if (e.key == "Escape") { e.preventDefault(); popup.remove() }
49 })
50 popup.focus()
51 }
52
53 document.body.addEventListener("mousedown", e => {
54 for (let n = e.target; n; n = n.parentNode) {

Callers 1

chapterInteractionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected