Skip to content

Commit c88d7f2

Browse files
authored
Adding keyboard shortcuts
1 parent 47a27f3 commit c88d7f2

File tree

3 files changed

+45
-15
lines changed

3 files changed

+45
-15
lines changed

build-pwa.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ function generateIndexHtml() {
167167
<ul id="app-links">
168168
${appLinks}
169169
</ul>
170-
<div class="version-label">Version: ${versionString}</div>
170+
<div class="version-label">${versionString}</div>
171171
</div>
172172
</nav>
173-
<main><iframe name="appFrame" id="appFrame"></iframe></main>
173+
<main><iframe name="appFrame" title="App Frame" id="appFrame"></iframe></main>
174174
</div>
175175
176176
<script src="./static/app_script.js"></script>
@@ -252,10 +252,10 @@ self.addEventListener("install", (event) => {
252252
const failed = results.filter(result => result.status === 'rejected');
253253
const successful = results.filter(result => result.status === 'fulfilled');
254254
255+
console.log("[SW] Successfully cached", successful.length, "resources");
255256
if (failed.length > 0) {
256257
console.error("[SW]", failed.length, "resources failed to cache:", failed);
257258
}
258-
console.error("[SW] Successfully cached", successful.length, "resources");
259259
});
260260
})
261261
);

static/app_script.js

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ function updateThemeColorFromIframe() {
155155
const computedStyle = window.getComputedStyle(iframeBody);
156156
const backgroundColor = computedStyle.getPropertyValue("background-color");
157157

158+
iframeBody.addEventListener("click", collapseSidebar);
159+
158160
// Check if a color was successfully retrieved
159161
if (backgroundColor) {
160162
// Find or create the meta theme-color tag in the main document
@@ -247,26 +249,35 @@ function monitorIframeBackgroundColor() {
247249
}
248250
}
249251

250-
function initializeAppUI() {
251-
const iframe = document.getElementById("appFrame");
252+
const collapseSidebar = () => {
252253
const sidebar = document.getElementById("sidebar");
253254
const hamburger = document.getElementById("hamburger-menu");
254255
const header = document.querySelector("body header");
255-
const links = document.querySelectorAll("#app-links li a");
256256

257-
// Initialize theme sync once at startup
258-
monitorIframeBackgroundColor();
259-
260-
const collapseSidebar = () => {
257+
if (!sidebar.classList.contains("collapsed")) {
261258
sidebar.classList.add("collapsed");
259+
}
260+
if (sidebar.classList.contains("overlay")) {
262261
sidebar.classList.remove("overlay");
262+
}
263+
if (hamburger.style.display !== "block") {
263264
hamburger.style.display = "block";
265+
}
264266

265-
if (header) {
266-
header.style.display = "none";
267-
sidebar.style.paddingTop = "6.75em";
268-
}
269-
};
267+
if (header && header.style.display !== "none") {
268+
header.style.display = "none";
269+
sidebar.style.paddingTop = "6.75em";
270+
}
271+
};
272+
273+
function initializeAppUI() {
274+
const iframe = document.getElementById("appFrame");
275+
const sidebar = document.getElementById("sidebar");
276+
const hamburger = document.getElementById("hamburger-menu");
277+
const links = document.querySelectorAll("#app-links li a");
278+
279+
// Initialize theme sync once at startup
280+
monitorIframeBackgroundColor();
270281

271282
iframe.addEventListener("load", collapseSidebar);
272283

@@ -297,4 +308,21 @@ function initializeAppUI() {
297308
hamburger.addEventListener("click", () => {
298309
sidebar.classList.toggle("overlay");
299310
});
311+
312+
document.addEventListener("keydown", (event) => {
313+
// '=' key shortcut to toggle the sidebar
314+
if (event.key === "=") {
315+
event.preventDefault();
316+
sidebar.classList.toggle("overlay");
317+
} else if (event.key === "Escape") {
318+
collapseSidebar();
319+
}
320+
});
321+
322+
document.addEventListener("focusin", (event) => {
323+
// Check if the element that received focus is an iframe
324+
if (event.target.tagName === "IFRAME") {
325+
collapseSidebar();
326+
}
327+
});
300328
}

static/app_stylesheet.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,11 @@ iframe {
185185
border-top: 1px solid #444;
186186
background-color: #333;
187187
padding: 8px;
188+
overflow: hidden;
188189
color: #ccc;
189190
font-size: 0.85em;
190191
text-align: center;
192+
text-wrap: nowrap;
191193
}
192194

193195
@media (max-width: 768px) {

0 commit comments

Comments
 (0)