|
286 | 286 | <!-- remove toc active class when page is loaded -->
|
287 | 287 | <script type="text/javascript">
|
288 | 288 | window.addEventListener('DOMContentLoaded', () => {
|
289 |
| - var tocItems = $("#toc a"); |
| 289 | + toc_items = document.querySelectorAll('#toc a') |
290 | 290 |
|
291 |
| - for (let i = 0; i < tocItems.length; i++) { |
292 |
| - tocItems[i].classList.remove("toc-active"); |
| 291 | + for (let i = 0; i < toc_items.length; i++) { |
| 292 | + toc_items[i].classList.remove("toc-active"); |
293 | 293 | }
|
294 | 294 | })
|
295 | 295 | </script>
|
|
329 | 329 | <!-- clear and add toc-active to clicked toc link -->
|
330 | 330 | <script type="text/javascript">
|
331 | 331 | $("#toc a").click(function() {
|
332 |
| - var tocItems = $("#toc a"); |
333 |
| - for (let i = 0; i < tocItems.length; i++) { |
334 |
| - tocItems[i].classList.remove("toc-active"); |
| 332 | + toc_items = document.querySelectorAll('#toc a') |
| 333 | + for (let i = 0; i < toc_items.length; i++) { |
| 334 | + toc_items[i].classList.remove("toc-active"); |
335 | 335 | }
|
336 | 336 | this.classList.add("toc-active");
|
337 | 337 | });
|
|
365 | 365 | e.map(i => {
|
366 | 366 | if (i.isIntersecting && i.intersectionRatio >= 1) {
|
367 | 367 | allTocLinks.forEach(link => link.classList.remove("toc-active"));
|
368 |
| - document.querySelector(`#toc li a[href="#${i.target.id}"]`).classList.add('toc-active'); |
| 368 | + toc_item = document.querySelector(`#toc li a[href="#${i.target.id}"]`) |
| 369 | + if(toc_item !== null) toc_item.classList.add('toc-active'); |
369 | 370 | }
|
370 | 371 | });
|
371 | 372 | };
|
|
376 | 377 | document.querySelectorAll('.main h2[id], .main h3[id]').forEach((h) => {
|
377 | 378 | observer.unobserve(h);
|
378 | 379 | });
|
379 |
| - var tocItems = $("#toc a"); |
380 |
| - for (let i = 0; i < tocItems.length; i++) { |
381 |
| - tocItems[i].classList.remove("toc-active"); |
| 380 | + toc_items = document.querySelectorAll('#toc a') |
| 381 | + for (let i = 0; i < toc_items.length; i++) { |
| 382 | + toc_items[i].classList.remove("toc-active"); |
382 | 383 | }
|
383 | 384 | this.classList.add("toc-active");
|
384 | 385 | })
|
|
387 | 388 |
|
388 | 389 | <!--handle page scroll top and bottom, add toc-active -->
|
389 | 390 | <script type="text/javascript">
|
| 391 | + toc_items = document.querySelectorAll('#toc a') |
390 | 392 | document.addEventListener('scroll', () => {
|
391 | 393 | //scroll to bottom
|
392 | 394 | if(document.documentElement.scrollHeight === window.pageYOffset + window.innerHeight) {
|
393 |
| - var tocItems = $("#toc a"); |
394 |
| - for (let i = 0; i < tocItems.length; i++) { |
395 |
| - tocItems[i].classList.remove("toc-active") |
396 |
| - }; |
397 |
| - tocItems[tocItems.length - 1].classList.add("toc-active"); |
| 395 | + if(toc_items !== null) { |
| 396 | + for (let i = 0; i < toc_items.length; i++) { |
| 397 | + toc_items[i].classList.remove("toc-active") |
| 398 | + }; |
| 399 | + toc_items[toc_items.length - 1].classList.add("toc-active"); |
| 400 | + } |
398 | 401 | };
|
399 | 402 | //scroll to top
|
400 | 403 | if(window.pageYOffset === 0) {
|
401 |
| - var tocItems = $("#toc a"); |
402 |
| - for (let i = 0; i < tocItems.length; i++) { |
403 |
| - tocItems[i].classList.remove("toc-active"); |
| 404 | + for (let i = 0; i < toc_items.length; i++) { |
| 405 | + if(toc_items !== null) { |
| 406 | + toc_items[i].classList.remove("toc-active"); |
404 | 407 | };
|
405 |
| - tocItems[0].classList.add("toc-active"); |
406 |
| - }; |
407 |
| - }) |
| 408 | + toc_items[0].classList.add("toc-active"); |
| 409 | + } |
| 410 | + }; |
| 411 | + }) |
408 | 412 | </script>
|
409 | 413 |
|
410 | 414 | <!-- adjust alerts on mobile -->
|
411 | 415 | <script type="text/javascript">
|
| 416 | + alert_item = document.querySelector('#support-alert') |
412 | 417 | window.addEventListener("wheel", () => {
|
413 | 418 | if (window.innerWidth < 1425) {
|
414 | 419 | //adjust alert
|
415 | 420 | 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"; |
| 421 | + if(alert_item !== null) { |
| 422 | + alert_item.style.position = "fixed"; |
| 423 | + alert_item.style.bottom = "0px"; |
| 424 | + alert_item.style.margin = "5px"; |
| 425 | + alert_item.style.zIndex = "9999999"; |
| 426 | + } |
420 | 427 | }
|
421 | 428 | }
|
422 | 429 | });
|
423 | 430 | window.addEventListener('resize', () => {
|
424 | 431 | 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'); |
| 432 | + if(alert_item !== null) { |
| 433 | + alert_item.style.removeProperty('position'); |
| 434 | + alert_item.style.removeProperty('bottom'); |
| 435 | + alert_item.style.removeProperty('margin'); |
| 436 | + alert_item.style.removeProperty('zIndex'); |
| 437 | + } |
429 | 438 | }
|
430 | 439 | })
|
431 | 440 | </script>
|
|
0 commit comments