@@ -5,9 +5,12 @@ import * as babel from 'https://esm.sh/prettier@3.5.1/plugins/babel';
5
5
import * as estree from 'https://esm.sh/prettier@3.5.1/plugins/estree' ;
6
6
import { marked } from 'https://esm.sh/marked@15.0.7' ;
7
7
8
- var tipElement , tipContainer , allMenus , navLinks , versionsLinks ;
8
+ var allMenus , navLinks , versionsLinks ;
9
9
10
10
const showTip = async ( ) => {
11
+ const tipElement = document . getElementById ( 'tip' ) ;
12
+ if ( ! tipElement ) return ;
13
+
11
14
const tips = await getContents ( '/assets/tips.md' ) ;
12
15
const features = await getContents ( '/assets/features.md' ) ;
13
16
const all = tips . concat ( features ) ;
@@ -261,19 +264,21 @@ function buildPageToC() {
261
264
262
265
function replaceContent ( text ) {
263
266
var tocContainer = document . querySelector ( '.toc-container' ) ;
264
- tocContainer . className =
265
- text . trim ( ) !== ''
266
- ? 'toc-container col hide-on-small-only m3 '
267
- : 'toc-container' ;
268
-
269
- var tmpElement = document . createElement ( 'div' ) ;
270
- tmpElement . innerHTML = text ;
271
-
272
- toggleDockBlocks ( false ) ;
267
+ if ( tocContainer ) {
268
+ tocContainer . className =
269
+ text . trim ( ) !== ' '
270
+ ? 'toc-container col hide-on-small-only m3'
271
+ : 'toc-container' ;
272
+
273
+ var tmpElement = document . createElement ( 'div' ) ;
274
+ tmpElement . innerHTML = text ;
275
+ }
273
276
274
- var content = document . querySelector ( '.DocSearch-content' ) ;
275
- content . innerHTML =
276
- tmpElement . querySelector ( '.DocSearch-content' ) . innerHTML ;
277
+ var content = document . querySelector ( '.container' ) ;
278
+ var tmpContent = tmpElement . querySelector ( '.container' ) ;
279
+ if ( content && tmpContent ) {
280
+ content . innerHTML = tmpContent . innerHTML ;
281
+ }
277
282
278
283
window . scrollTo ( 0 , 0 ) ;
279
284
@@ -285,9 +290,10 @@ function replaceContent(text) {
285
290
function changeSelectedMenu ( ) {
286
291
var activeMenu = document . querySelector ( `.sidenav li.active` ) ;
287
292
activeMenu && activeMenu . classList . remove ( 'active' ) ;
288
- allMenus
289
- . find ( menuEl => menuEl . href === window . location . href )
290
- . parentNode . classList . add ( 'active' ) ;
293
+ const newActiveMenu = allMenus . find (
294
+ menuEl => menuEl . href === window . location . href
295
+ ) ;
296
+ newActiveMenu && newActiveMenu . parentNode . classList . add ( 'active' ) ;
291
297
}
292
298
293
299
function toggleDockBlocks ( status ) {
@@ -343,11 +349,26 @@ function showNonBeginnerDoc() {
343
349
} ) ;
344
350
}
345
351
352
+ function hideTips ( ) {
353
+ const tipElement = document . getElementById ( 'tip' ) ;
354
+ const tipContainer = document . getElementById ( 'tip-container' ) ;
355
+
356
+ if ( tipElement ) {
357
+ tipElement . remove ( ) ;
358
+ }
359
+ if ( tipContainer ) {
360
+ tipContainer . remove ( ) ;
361
+ }
362
+ }
363
+
346
364
document . addEventListener ( 'DOMContentLoaded' , ( ) => {
347
365
const beginnerModeTrigger = document . getElementById (
348
366
'beginner-mode-trigger'
349
367
) ;
350
368
369
+ if ( window . location . pathname === '/documentation.html' ) {
370
+ }
371
+
351
372
if ( beginnerModeTrigger ) {
352
373
beginnerModeTrigger . addEventListener ( 'click' , ( ) => {
353
374
beginnerMode = ! beginnerMode ;
@@ -383,12 +404,6 @@ document.addEventListener('click', event => {
383
404
if ( ! navLinks . includes ( href ) ) {
384
405
return ; // not a navigation link
385
406
}
386
- if ( tipElement ) {
387
- tipElement . remove ( ) ;
388
- }
389
- if ( tipContainer ) {
390
- tipContainer . remove ( ) ;
391
- }
392
407
window . sessionStorage . setItem (
393
408
'scrollIntoView' ,
394
409
link . closest ( '.sidenav' ) ? 'false' : 'true'
@@ -406,6 +421,13 @@ document.addEventListener('click', event => {
406
421
fetch ( href )
407
422
. then ( res => res . text ( ) )
408
423
. then ( replaceContent )
424
+ . then ( ( ) => {
425
+ if ( href . includes ( 'documentation.html' ) ) {
426
+ showTip ( ) ;
427
+ } else {
428
+ hideTips ( ) ;
429
+ }
430
+ } )
409
431
. then ( buildJSCodeBlocksFromTS )
410
432
. then ( loadNewsletterScript ) ;
411
433
// change the URL
@@ -420,29 +442,39 @@ window.addEventListener('popstate', () => {
420
442
return ;
421
443
}
422
444
if ( window . location . pathname === '/documentation.html' ) {
423
- document . querySelector ( '.DocSearch-content' ) . innerHTML = '' ;
424
- toggleDockBlocks ( true ) ;
445
+ fetch ( window . location . pathname )
446
+ . then ( res => res . text ( ) )
447
+ . then ( replaceContent )
448
+ . then ( ( ) => {
449
+ document . querySelector ( '.DocSearch-content' ) . innerHTML = '' ;
450
+ toggleDockBlocks ( true ) ;
451
+ showTip ( ) ;
452
+ } ) ;
425
453
} else {
426
454
// fetch the new content
427
455
fetch ( window . location . pathname )
428
456
. then ( res => res . text ( ) )
429
457
. then ( replaceContent )
458
+ . then ( ( ) => {
459
+ toggleDockBlocks ( false ) ;
460
+ } )
461
+ . then ( hideTips )
430
462
. then ( buildJSCodeBlocksFromTS )
431
463
. then ( loadNewsletterScript ) ;
432
464
}
433
465
changeSelectedMenu ( ) ;
434
466
} ) ;
435
467
436
468
window . addEventListener ( 'DOMContentLoaded' , ( ) => {
437
- tipElement = document . getElementById ( 'tip' ) ;
438
- tipContainer = document . getElementById ( 'tip-container' ) ;
439
469
allMenus = Array . from ( document . querySelectorAll ( `.sidenav a.nav-link` ) ) ;
440
470
navLinks = allMenus
441
471
. filter ( link => ! link . classList . contains ( 'external' ) )
442
472
. map ( link => link . href ) ;
443
473
versionsLinks = Array . from ( document . querySelectorAll ( '#versions > li > a' ) ) ;
444
474
445
- if ( tipElement ) showTip ( ) ;
475
+ if ( window . location . pathname === '/documentation.html' ) {
476
+ showTip ( ) ;
477
+ }
446
478
buildPageToC ( ) ;
447
479
448
480
navigationFitScroll ( ) ;
0 commit comments