(value)
| 85 | } |
| 86 | |
| 87 | selectContext(value) { |
| 88 | this.output.clear() |
| 89 | this.clearSandbox() |
| 90 | let chapter = getChapter(this.chapters.value), visible |
| 91 | if (value == "box") { |
| 92 | let code = (this.chapters.value < 20 || this.chapters.value > 21) |
| 93 | ? "Run code here in the context of Chapter " + chapter.number |
| 94 | : "Code from Node.js chapters can't be run in the browser" |
| 95 | let guessed = guessType(chapter.start_code) |
| 96 | if (guessed == "javascript") |
| 97 | code = "// " + code |
| 98 | else |
| 99 | code = "<!-- " + code + " -->" |
| 100 | if (chapter.start_code) code += "\n\n" + chapter.start_code |
| 101 | this.setEditorState(code, {include: chapter.include}) |
| 102 | visible = "box" |
| 103 | } else { |
| 104 | let exercise = findExercise(value, chapter) |
| 105 | if (exercise.goto) { |
| 106 | document.location = exercise.goto |
| 107 | return |
| 108 | } |
| 109 | this.setEditorState(exercise.code, { |
| 110 | include: chapter.include, |
| 111 | solution: exercise.solution, |
| 112 | type: exercise.type |
| 113 | }) |
| 114 | visible = "exercise" |
| 115 | let link = document.querySelector("#download") |
| 116 | link.setAttribute("download", "solution" + value + ".js") |
| 117 | if (/\.zip$/.test(exercise.file)) |
| 118 | link.href = "../" + exercise.file |
| 119 | else |
| 120 | link.href = "data:text/plain;charset=UTF-8," + encodeURIComponent(exercise.solution) |
| 121 | } |
| 122 | ["box", "exercise"].forEach(id => { |
| 123 | document.querySelector("#" + id + "_info").style.display = |
| 124 | (id == visible ? "" : "none") |
| 125 | }) |
| 126 | } |
| 127 | |
| 128 | clearSandbox() { |
| 129 | if (this.sandbox) { |
no test coverage detected