Skip to content

Commit

Permalink
Switch to test mode when the play button is clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
desplesda committed Aug 3, 2024
1 parent 52a99ac commit 93c22c5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 12 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import { initialContent } from './starter-content'

const ModeChangedEvent = new Event("yarnspinner-mode-changed");

let updateSelectedMode : (mode:string) => void;

window.addEventListener('DOMContentLoaded', () => {

// Set up the mode selector so that when a mode toggle is set, the appropriate element is visible
const selectorElements = document.querySelectorAll(".mode-selector") as NodeListOf<HTMLElement>;

const selectableElementsMap = new Map<string, HTMLElement>();

const updateSelectedMode = (mode: string) => {
updateSelectedMode = (mode: string) => {
selectableElementsMap.forEach(v => {
v.classList.add("d-none");
});
Expand Down Expand Up @@ -76,7 +78,15 @@ window.addEventListener('load', async function () {
// import it. Once that's done, load the playground with the content that we
// selected.
const playground = await import("./playground");
await playground.load(contentName);

const testButton = document.getElementById("button-test");
const downloadButton = document.getElementById("button-download-pdf");

testButton.addEventListener("click", () => {
updateSelectedMode("test");
})

await playground.load(contentName, testButton, downloadButton);

// Hide the loading element, which is visible before any script runs.
global.document.getElementById("loader").classList.add("d-none");
Expand Down
6 changes: 3 additions & 3 deletions src/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface IFunctionDefinition {
function: Function;
}

export async function load (initialContentName : string = "default") {
export async function load (initialContentName : string = "default", testButton:HTMLElement, downloadButton:HTMLElement) {

let script = initialContent[initialContentName]

Expand Down Expand Up @@ -300,7 +300,7 @@ export async function load (initialContentName : string = "default") {
logElement.insertBefore(errorText, logElement.firstChild);
}

document.getElementById("button-test").addEventListener("click", async () => {
testButton.addEventListener("click", async () => {
if (errorsExist) {
return;
}
Expand Down Expand Up @@ -392,7 +392,7 @@ export async function load (initialContentName : string = "default") {

let pdfDownloadInProgress = false;

document.getElementById("button-download-pdf")?.addEventListener("click", async => {
downloadButton.addEventListener("click", async () => {
if (pdfDownloadInProgress) {
return;
}
Expand Down

0 comments on commit 93c22c5

Please sign in to comment.