@@ -155,6 +155,8 @@ function updateThemeColorFromIframe() {
155
155
const computedStyle = window . getComputedStyle ( iframeBody ) ;
156
156
const backgroundColor = computedStyle . getPropertyValue ( "background-color" ) ;
157
157
158
+ iframeBody . addEventListener ( "click" , collapseSidebar ) ;
159
+
158
160
// Check if a color was successfully retrieved
159
161
if ( backgroundColor ) {
160
162
// Find or create the meta theme-color tag in the main document
@@ -247,26 +249,35 @@ function monitorIframeBackgroundColor() {
247
249
}
248
250
}
249
251
250
- function initializeAppUI ( ) {
251
- const iframe = document . getElementById ( "appFrame" ) ;
252
+ const collapseSidebar = ( ) => {
252
253
const sidebar = document . getElementById ( "sidebar" ) ;
253
254
const hamburger = document . getElementById ( "hamburger-menu" ) ;
254
255
const header = document . querySelector ( "body header" ) ;
255
- const links = document . querySelectorAll ( "#app-links li a" ) ;
256
256
257
- // Initialize theme sync once at startup
258
- monitorIframeBackgroundColor ( ) ;
259
-
260
- const collapseSidebar = ( ) => {
257
+ if ( ! sidebar . classList . contains ( "collapsed" ) ) {
261
258
sidebar . classList . add ( "collapsed" ) ;
259
+ }
260
+ if ( sidebar . classList . contains ( "overlay" ) ) {
262
261
sidebar . classList . remove ( "overlay" ) ;
262
+ }
263
+ if ( hamburger . style . display !== "block" ) {
263
264
hamburger . style . display = "block" ;
265
+ }
264
266
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 ( ) ;
270
281
271
282
iframe . addEventListener ( "load" , collapseSidebar ) ;
272
283
@@ -297,4 +308,21 @@ function initializeAppUI() {
297
308
hamburger . addEventListener ( "click" , ( ) => {
298
309
sidebar . classList . toggle ( "overlay" ) ;
299
310
} ) ;
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
+ } ) ;
300
328
}
0 commit comments