1- import { $$ , ajax , debounce , replaceToolbarState } from "./utils.js" ;
1+ import { $$ , getDebugElement , ajax , debounce , replaceToolbarState } from "./utils.js" ;
22
33function onKeyDown ( event ) {
44 if ( event . keyCode === 27 ) {
55 djdt . hideOneLevel ( ) ;
66 }
77}
88
9- function getDebugElement ( ) {
10- // Fetch the debug element from the DOM.
11- // This is used to avoid writing the element's id
12- // everywhere the element is being selected. A fixed reference
13- // to the element should be avoided because the entire DOM could
14- // be reloaded such as via HTMX boosting.
15- return document . getElementById ( "djDebug" ) ;
16- }
17-
189const djdt = {
1910 handleDragged : false ,
2011 needUpdateOnFetch : false ,
@@ -27,7 +18,7 @@ const djdt = {
2718 return ;
2819 }
2920 const panelId = this . className ;
30- const current = document . getElementById ( panelId ) ;
21+ const current = djDebug . querySelector ( `# ${ panelId } ` ) ;
3122 if ( $$ . visible ( current ) ) {
3223 djdt . hidePanels ( ) ;
3324 } else {
@@ -103,7 +94,7 @@ const djdt = {
10394 }
10495
10596 ajax ( url , ajaxData ) . then ( ( data ) => {
106- const win = document . getElementById ( " djDebugWindow") ;
97+ const win = djDebug . querySelector ( "# djDebugWindow") ;
10798 win . innerHTML = data . content ;
10899 $$ . show ( win ) ;
109100 } ) ;
@@ -116,7 +107,7 @@ const djdt = {
116107 const toggleClose = "-" ;
117108 const openMe = this . textContent === toggleOpen ;
118109 const name = this . dataset . toggleName ;
119- const container = document . getElementById ( ` ${ name } _${ id } `) ;
110+ const container = djDebug . querySelector ( `# ${ name } _${ id } `) ;
120111 for ( const el of container . querySelectorAll ( ".djDebugCollapsed" ) ) {
121112 $$ . toggle ( el , openMe ) ;
122113 }
@@ -156,7 +147,7 @@ const djdt = {
156147 } ) ;
157148 let startPageY ;
158149 let baseY ;
159- const handle = document . getElementById ( " djDebugToolbarHandle") ;
150+ const handle = djDebug . querySelector ( "# djDebugToolbarHandle") ;
160151 function onHandleMove ( event ) {
161152 // Chrome can send spurious mousemove events, so don't do anything unless the
162153 // cursor really moved. Otherwise, it will be impossible to expand the toolbar
@@ -240,16 +231,17 @@ const djdt = {
240231 } ,
241232 hidePanels ( ) {
242233 const djDebug = getDebugElement ( ) ;
243- $$ . hide ( document . getElementById ( " djDebugWindow") ) ;
234+ $$ . hide ( djDebug . querySelector ( "# djDebugWindow") ) ;
244235 for ( const el of djDebug . querySelectorAll ( ".djdt-panelContent" ) ) {
245236 $$ . hide ( el ) ;
246237 }
247- for ( const el of document . querySelectorAll ( "#djDebugToolbar li" ) ) {
238+ for ( const el of djDebug . querySelectorAll ( "#djDebugToolbar li" ) ) {
248239 el . classList . remove ( "djdt-active" ) ;
249240 }
250241 } ,
251242 ensureHandleVisibility ( ) {
252- const handle = document . getElementById ( "djDebugToolbarHandle" ) ;
243+ const djDebug = getDebugElement ( ) ;
244+ const handle = djDebug . querySelector ( "#djDebugToolbarHandle" ) ;
253245 // set handle position
254246 const handleTop = Math . min (
255247 localStorage . getItem ( "djdt.top" ) || 265 ,
@@ -258,11 +250,12 @@ const djdt = {
258250 handle . style . top = `${ handleTop } px` ;
259251 } ,
260252 hideToolbar ( ) {
253+ const djDebug = getDebugElement ( ) ;
261254 djdt . hidePanels ( ) ;
262255
263- $$ . hide ( document . getElementById ( " djDebugToolbar") ) ;
256+ $$ . hide ( djDebug . querySelector ( "# djDebugToolbar") ) ;
264257
265- const handle = document . getElementById ( " djDebugToolbarHandle") ;
258+ const handle = djDebug . querySelector ( "# djDebugToolbarHandle") ;
266259 $$ . show ( handle ) ;
267260 djdt . ensureHandleVisibility ( ) ;
268261 window . addEventListener ( "resize" , djdt . ensureHandleVisibility ) ;
@@ -271,11 +264,12 @@ const djdt = {
271264 localStorage . setItem ( "djdt.show" , "false" ) ;
272265 } ,
273266 hideOneLevel ( ) {
274- const win = document . getElementById ( "djDebugWindow" ) ;
267+ const djDebug = getDebugElement ( ) ;
268+ const win = djDebug . querySelector ( "#djDebugWindow" ) ;
275269 if ( $$ . visible ( win ) ) {
276270 $$ . hide ( win ) ;
277271 } else {
278- const toolbar = document . getElementById ( " djDebugToolbar") ;
272+ const toolbar = djDebug . querySelector ( "# djDebugToolbar") ;
279273 if ( toolbar . querySelector ( "li.djdt-active" ) ) {
280274 djdt . hidePanels ( ) ;
281275 } else {
@@ -284,16 +278,17 @@ const djdt = {
284278 }
285279 } ,
286280 showToolbar ( ) {
281+ const djDebug = getDebugElement ( ) ;
287282 document . addEventListener ( "keydown" , onKeyDown ) ;
288- $$ . show ( document . getElementById ( " djDebug" ) ) ;
289- $$ . hide ( document . getElementById ( " djDebugToolbarHandle") ) ;
290- $$ . show ( document . getElementById ( " djDebugToolbar") ) ;
283+ $$ . show ( djDebug ) ;
284+ $$ . hide ( djDebug . querySelector ( "# djDebugToolbarHandle") ) ;
285+ $$ . show ( djDebug . querySelector ( "# djDebugToolbar") ) ;
291286 localStorage . setItem ( "djdt.show" , "true" ) ;
292287 window . removeEventListener ( "resize" , djdt . ensureHandleVisibility ) ;
293288 } ,
294289 updateOnAjax ( ) {
295290 const sidebarUrl =
296- document . getElementById ( "djDebug" ) . dataset . sidebarUrl ;
291+ getDebugElement ( ) . dataset . sidebarUrl ;
297292 const slowjax = debounce ( ajax , 200 ) ;
298293
299294 function handleAjaxResponse ( requestId ) {
0 commit comments