Skip to content

Commit

Permalink
Fix controls modal toggling behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
j4ckofalltrades committed Oct 15, 2023
1 parent cabac27 commit 712ccf8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
A drum kit web app that uses Nintendo Joy-Cons as controllers (connected via [WebHID](https://web.dev/hid)).

> [!IMPORTANT]
> WebHID is currently only supported on Chromium-based browsers e.g. Chrome, Edge, etc.
> The WebHID API is currently only supported on [Chromium-based browsers](https://developer.mozilla.org/en-US/docs/Web/API/WebHID_API#browser_compatibility) e.g. Chrome, Edge, etc.
## Demo

Expand Down Expand Up @@ -39,4 +39,4 @@ Launch the app locally with `pnpm install --frozen-lockfile` and `pnpm run start

- [Joy-Con WebHID](https://github.com/tomayac/joy-con-webhid) Driver
- Joy-Con models by [Stix](https://codepen.io/stix/details/WRoweX#input_1604658346501:~:text=License)
- Icons by [Icons8](https://icons8.com)
- Icons by [Icons8](https://icons8.com)
13 changes: 8 additions & 5 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@ <h1>
</h1>
<ol>
<li>
Connect the <a href="https://en.wikipedia.org/wiki/Joy-Con" target="_blank" rel="noreferrer">Joy-Cons</a>
Connect the
<a href="https://en.wikipedia.org/wiki/Joy-Con" target="_blank" rel="noreferrer"> Joy-Cons </a>
via the operating system's Bluetooth setup dialog
</li>
<li>
Click the button below to connect the Joy-Cons via
<a href="https://web.dev/hid/">WebHID</a>
Click the button below to connect the Joy-Cons via the
<a href="https://developer.mozilla.org/en-US/docs/Web/API/WebHID_API" target="_blank" rel="noreferrer">
WebHID API
</a>
<div>
<button id="connect-joy-cons" type="button">Connect Joy-Cons</button>
<button id="connect-joy-cons" class="instructions" type="button">Connect Joy-Cons</button>
</div>
</li>
<li>
Click the button below to toggle the drum kit controls
<div>
<button id="btn-controls" type="button">Toggle Controls</button>
<button id="btn-controls" class="instructions" type="button">Toggle Controls</button>
</div>
</li>
</ol>
Expand Down
11 changes: 9 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,19 @@ setInterval(async () => {

// Controls modal
const controlsModal = document.getElementById("controls")
const toggleControls = () => {
if (!controlsModal.style.display || controlsModal.style.display === "none") {
controlsModal.style.display = "block"
} else {
controlsModal.style.display = "none"
}
}

const controlsModalBtn = document.getElementById("btn-controls")
controlsModalBtn.onclick = () => (controlsModal.style.display = "block")

window.onclick = (event) => {
if (event.target === controlsModal) {
controlsModal.style.display = "none"
}
}

controlsModalBtn.onclick = toggleControls
2 changes: 1 addition & 1 deletion src/styles/controls.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

.left-joycon-ctrl {
background-color: #00b2dc;
padding-bottom: 8px;
padding-bottom: 10px;
}

.right-joycon-ctrl {
Expand Down
4 changes: 4 additions & 0 deletions src/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,7 @@ figure {
ol {
line-height: 180%;
}

.instructions {
width: 127px;
}

0 comments on commit 712ccf8

Please sign in to comment.