1- console . log ( "[Explain Code] Script loaded!" ) ;
2-
31const sheets = new Map < string , HTMLDivElement > ( ) ;
42
53function initExplainCodeButtons ( ) {
6- const buttons = document . querySelectorAll < HTMLButtonElement > (
7- "button[data-sheet-trigger]" ,
8- ) ;
9-
10- console . log ( `[Explain Code] Found ${ buttons . length } explain code buttons` ) ;
11-
124 // Use event delegation on document body to catch all clicks
135 document . body . addEventListener ( "click" , ( e ) => {
146 const target = e . target as HTMLElement ;
@@ -18,36 +10,24 @@ function initExplainCodeButtons() {
1810
1911 if ( ! button ) return ;
2012
21- console . log ( `[Explain Code] Button clicked via delegation!` ) ;
2213 e . preventDefault ( ) ;
2314 e . stopPropagation ( ) ;
2415
2516 const sheetId = button . dataset . sheetTrigger ;
2617 const codeContent = button . dataset . codeContent ;
2718 const codeLanguage = button . dataset . codeLanguage ;
2819
29- console . log ( `[Explain Code] Button data:` , {
30- sheetId,
31- hasContent : ! ! codeContent ,
32- codeLanguage,
33- } ) ;
34-
35- if ( ! sheetId || ! codeContent ) {
36- console . warn ( `[Explain Code] Button missing required data attributes` ) ;
37- return ;
38- }
20+ if ( ! sheetId || ! codeContent ) return ;
3921
4022 let sheet = sheets . get ( sheetId ) ;
4123
4224 if ( ! sheet ) {
43- console . log ( `[Explain Code] Creating sheet...` ) ;
4425 sheet = createSheet ( sheetId , codeContent , codeLanguage || "text" ) ;
4526 document . body . appendChild ( sheet ) ;
4627 initSheet ( sheet ) ;
4728 sheets . set ( sheetId , sheet ) ;
4829 }
4930
50- console . log ( `[Explain Code] Opening sheet...` ) ;
5131 openSheet ( sheet ) ;
5232 } ) ;
5333}
@@ -105,8 +85,10 @@ function createSheet(
10585 const closeButton = document . createElement ( "button" ) ;
10686 closeButton . type = "button" ;
10787 closeButton . className =
108- "sheet-close sticky top-0 right-0 ml-auto mb-4 rounded-sm opacity-70 ring-offset-[var(--sl-color-bg)] transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-[var(--sl-color-text-accent)] focus:ring-offset-2 disabled:pointer-events-none z-10 bg-[var(--sl-color-bg)] w-fit " ;
88+ "sheet-close sticky top-0 right-0 ml-auto mb-4 rounded-sm opacity-70 ring-offset-[var(--sl-color-bg)] transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-[var(--sl-color-text-accent)] focus:ring-offset-2 disabled:pointer-events-none z-10 bg-[var(--sl-color-bg)] flex items-center justify-center " ;
10989 closeButton . style . float = "right" ;
90+ closeButton . style . width = "2rem" ;
91+ closeButton . style . height = "2rem" ;
11092 closeButton . setAttribute ( "aria-label" , "Close" ) ;
11193 closeButton . innerHTML = `
11294 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="h-4 w-4">
@@ -217,23 +199,16 @@ function openSheet(container: HTMLElement) {
217199 firstFocusable ?. focus ( ) ;
218200}
219201
220- console . log ( "[Explain Code] Setting up event listener for astro:page-load" ) ;
221-
222202document . addEventListener ( "astro:page-load" , ( ) => {
223- console . log ( "[Explain Code] astro:page-load event fired!" ) ;
224203 initExplainCodeButtons ( ) ;
225204} ) ;
226205
227206// Also try DOMContentLoaded as a fallback
228207document . addEventListener ( "DOMContentLoaded" , ( ) => {
229- console . log ( "[Explain Code] DOMContentLoaded event fired!" ) ;
230208 initExplainCodeButtons ( ) ;
231209} ) ;
232210
233211// And try running immediately if DOM is already loaded
234- if ( document . readyState === "loading" ) {
235- console . log ( "[Explain Code] DOM is still loading, waiting..." ) ;
236- } else {
237- console . log ( "[Explain Code] DOM already loaded, initializing immediately" ) ;
212+ if ( document . readyState !== "loading" ) {
238213 initExplainCodeButtons ( ) ;
239214}
0 commit comments