|
339 | 339 |
|
340 | 340 | <!-- update active toc class when mouse scrolls -->
|
341 | 341 | <script type="text/javascript">
|
342 |
| - window.addEventListener("wheel", () => { |
343 |
| - |
344 |
| - const ioConfiguration = { |
345 |
| - "rootMargin": "-120px 0px -400px 0px", |
346 |
| - "threshold": 0 |
347 |
| - }; |
| 342 | + window.addEventListener('DOMContentLoaded', () => { |
| 343 | + window.addEventListener("wheel", () => { |
| 344 | + |
| 345 | + const ioConfiguration = { |
| 346 | + "rootMargin": "-120px 0px -400px 0px", |
| 347 | + "threshold": 0 |
| 348 | + }; |
348 | 349 |
|
349 |
| - const observer = new IntersectionObserver(setCurrent, ioConfiguration, entries => { |
350 |
| - entries.forEach(entry => { |
351 |
| - var id = entry.target.getAttribute('id'); |
352 |
| - //fight with js |
353 |
| - document.querySelector(`#toc li a[href="#${id}"]`).classList.remove('toc-active'); |
| 350 | + const observer = new IntersectionObserver(setCurrent, ioConfiguration, entries => { |
| 351 | + entries.forEach(entry => { |
| 352 | + var id = entry.target.getAttribute('id'); |
| 353 | + //fight with js |
| 354 | + document.querySelector(`#toc li a[href="#${id}"]`).classList.remove('toc-active'); |
| 355 | + }); |
354 | 356 | });
|
355 |
| - }); |
356 |
| - |
357 |
| - //track all h1-4 headings that have an id |
358 |
| - document.querySelectorAll('.main h2[id], .main h3[id]').forEach((h) => { |
359 |
| - observer.observe(h); |
360 |
| - }); |
361 |
| - |
362 |
| - //runs when the IntersectionObserver fires |
363 |
| - function setCurrent(e) { |
364 |
| - var allTocLinks = document.querySelectorAll("#toc li a"); |
365 |
| - e.map(i => { |
366 |
| - if (i.isIntersecting && i.intersectionRatio >= 1) { |
367 |
| - allTocLinks.forEach(link => link.classList.remove("toc-active")); |
368 |
| - document.querySelector(`#toc li a[href="#${i.target.id}"]`).classList.add('toc-active'); |
369 |
| - } |
370 |
| - }); |
371 |
| - }; |
372 | 357 |
|
373 |
| - //make clicked toc item active and stop IntersectionObserver |
374 |
| - $("#toc a").click(function() { |
375 |
| - //stop tracking all h1-4 headings that have an id |
| 358 | + //track all h1-4 headings that have an id |
376 | 359 | document.querySelectorAll('.main h2[id], .main h3[id]').forEach((h) => {
|
377 |
| - observer.unobserve(h); |
| 360 | + observer.observe(h); |
378 | 361 | });
|
379 |
| - var tocItems = $("#toc a"); |
380 |
| - for (let i = 0; i < tocItems.length; i++) { |
381 |
| - tocItems[i].classList.remove("toc-active"); |
382 |
| - } |
383 |
| - this.classList.add("toc-active"); |
| 362 | + |
| 363 | + //runs when the IntersectionObserver fires |
| 364 | + function setCurrent(e) { |
| 365 | + var allTocLinks = document.querySelectorAll("#toc li a"); |
| 366 | + if (allTocLinks !== undefined) { |
| 367 | + e.map(i => { |
| 368 | + if (i.isIntersecting && i.intersectionRatio >= 1) { |
| 369 | + allTocLinks.forEach(link => link.classList.remove("toc-active")); |
| 370 | + document.querySelector(`#toc li a[href="#${i.target.id}"]`).classList.add('toc-active') |
| 371 | + } |
| 372 | + }) |
| 373 | + } |
| 374 | + }; |
| 375 | + |
| 376 | + //make clicked toc item active and stop IntersectionObserver |
| 377 | + $("#toc a").click(function() { |
| 378 | + //stop tracking all h1-4 headings that have an id |
| 379 | + document.querySelectorAll('.main h2[id], .main h3[id]').forEach((h) => { |
| 380 | + observer.unobserve(h); |
| 381 | + }); |
| 382 | + var tocItems = $("#toc a"); |
| 383 | + if (tocItems !== undefined) { |
| 384 | + for (let i = 0; i < tocItems.length; i++) { |
| 385 | + tocItems[i].classList.remove("toc-active"); |
| 386 | + }; |
| 387 | + this.classList.add("toc-active"); |
| 388 | + } |
| 389 | + }) |
384 | 390 | })
|
385 | 391 | })
|
386 | 392 | </script>
|
|
407 | 413 | })
|
408 | 414 | </script>
|
409 | 415 |
|
| 416 | + <!--adjust sidebar and toc when footer is displayed --> |
| 417 | + <script type="text/javascript"> |
| 418 | + sidebar = document.querySelector('.sidebar') |
| 419 | + toc = document.querySelector('#toc') |
| 420 | + main = document.querySelector('.main') |
| 421 | + okd_footer = document.querySelector('.footer-origin-docs') |
| 422 | + document.addEventListener('scroll', () => { |
| 423 | + //scroll to bottom |
| 424 | + if (window.innerWidth >= 1425) { |
| 425 | + if(sidebar !== null && toc !== null) { |
| 426 | + if(document.documentElement.scrollHeight === window.pageYOffset + window.innerHeight) { |
| 427 | + sidebar.style.marginBottom = "38px"; |
| 428 | + toc.style.bottom = "35px"; |
| 429 | + main.style.marginBottom = "35px"; |
| 430 | + //okd footer |
| 431 | + if(okd_footer !== null) { |
| 432 | + sidebar.style.marginBottom = "176px"; |
| 433 | + toc.style.bottom = "175px"; |
| 434 | + main.style.marginBottom = "135px"; |
| 435 | + }; |
| 436 | + }; |
| 437 | + if(document.documentElement.scrollHeight != window.pageYOffset + window.innerHeight) { |
| 438 | + sidebar.style.marginBottom = "0px"; |
| 439 | + toc.style.bottom = "0px"; |
| 440 | + } |
| 441 | + } |
| 442 | + } |
| 443 | + }) |
| 444 | + </script> |
| 445 | + |
410 | 446 | <!-- adjust alerts on mobile -->
|
411 | 447 | <script type="text/javascript">
|
| 448 | + alert = document.querySelector('#support-alert') |
412 | 449 | window.addEventListener("wheel", () => {
|
413 | 450 | if (window.innerWidth < 1425) {
|
414 | 451 | //adjust alert
|
415 | 452 | if(window.pageYOffset > 0) {
|
416 |
| - document.querySelector('#support-alert').style.position = "fixed"; |
417 |
| - document.querySelector('#support-alert').style.bottom = "0px"; |
418 |
| - document.querySelector('#support-alert').style.margin = "5px"; |
419 |
| - document.querySelector('#support-alert').style.zIndex = "9999999"; |
| 453 | + if(alert !== null) { |
| 454 | + document.querySelector('#support-alert').style.position = "fixed"; |
| 455 | + document.querySelector('#support-alert').style.bottom = "0px"; |
| 456 | + document.querySelector('#support-alert').style.margin = "5px"; |
| 457 | + document.querySelector('#support-alert').style.zIndex = "9999999"; |
| 458 | + } |
420 | 459 | }
|
421 | 460 | }
|
422 | 461 | });
|
423 | 462 | window.addEventListener('resize', () => {
|
424 | 463 | if (window.innerWidth >= 1425) {
|
425 |
| - document.querySelector('#support-alert').style.removeProperty('position'); |
426 |
| - document.querySelector('#support-alert').style.removeProperty('bottom'); |
427 |
| - document.querySelector('#support-alert').style.removeProperty('margin'); |
428 |
| - document.querySelector('#support-alert').style.removeProperty('zIndex'); |
| 464 | + if(alert !== null) { |
| 465 | + document.querySelector('#support-alert').style.removeProperty('position'); |
| 466 | + document.querySelector('#support-alert').style.removeProperty('bottom'); |
| 467 | + document.querySelector('#support-alert').style.removeProperty('margin'); |
| 468 | + document.querySelector('#support-alert').style.removeProperty('zIndex'); |
| 469 | + } |
429 | 470 | }
|
430 | 471 | })
|
431 | 472 | </script>
|
|
0 commit comments