|
286 | 286 | <!-- remove toc active class when page is loaded --> |
287 | 287 | <script type="text/javascript"> |
288 | 288 | window.addEventListener('DOMContentLoaded', () => { |
289 | | - toc_items = document.querySelectorAll('#toc a') |
| 289 | + var tocItems = $("#toc a"); |
290 | 290 |
|
291 | | - for (let i = 0; i < toc_items.length; i++) { |
292 | | - toc_items[i].classList.remove("toc-active"); |
| 291 | + for (let i = 0; i < tocItems.length; i++) { |
| 292 | + tocItems[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 | | - toc_items = document.querySelectorAll('#toc a') |
333 | | - for (let i = 0; i < toc_items.length; i++) { |
334 | | - toc_items[i].classList.remove("toc-active"); |
| 332 | + var tocItems = $("#toc a"); |
| 333 | + for (let i = 0; i < tocItems.length; i++) { |
| 334 | + tocItems[i].classList.remove("toc-active"); |
335 | 335 | } |
336 | 336 | this.classList.add("toc-active"); |
337 | 337 | }); |
338 | 338 | </script> |
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 | | - toc_item = document.querySelector(`#toc li a[href="#${i.target.id}"]`) |
369 | | - if(toc_item !== null) toc_item.classList.add('toc-active'); |
370 | | - } |
371 | | - }); |
372 | | - }; |
373 | 357 |
|
374 | | - //make clicked toc item active and stop IntersectionObserver |
375 | | - $("#toc a").click(function() { |
376 | | - //stop tracking all h1-4 headings that have an id |
| 358 | + //track all h1-4 headings that have an id |
377 | 359 | document.querySelectorAll('.main h2[id], .main h3[id]').forEach((h) => { |
378 | | - observer.unobserve(h); |
| 360 | + observer.observe(h); |
379 | 361 | }); |
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"); |
383 | | - } |
384 | | - 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 | + }) |
385 | 390 | }) |
386 | 391 | }) |
387 | 392 | </script> |
388 | 393 |
|
389 | 394 | <!--handle page scroll top and bottom, add toc-active --> |
390 | 395 | <script type="text/javascript"> |
391 | | - toc_items = document.querySelectorAll('#toc a') |
392 | 396 | document.addEventListener('scroll', () => { |
393 | 397 | //scroll to bottom |
394 | 398 | if(document.documentElement.scrollHeight === window.pageYOffset + window.innerHeight) { |
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 | | - } |
| 399 | + var tocItems = $("#toc a"); |
| 400 | + for (let i = 0; i < tocItems.length; i++) { |
| 401 | + tocItems[i].classList.remove("toc-active") |
| 402 | + }; |
| 403 | + tocItems[tocItems.length - 1].classList.add("toc-active"); |
401 | 404 | }; |
402 | 405 | //scroll to top |
403 | 406 | if(window.pageYOffset === 0) { |
404 | | - for (let i = 0; i < toc_items.length; i++) { |
405 | | - if(toc_items !== null) { |
406 | | - toc_items[i].classList.remove("toc-active"); |
| 407 | + var tocItems = $("#toc a"); |
| 408 | + for (let i = 0; i < tocItems.length; i++) { |
| 409 | + tocItems[i].classList.remove("toc-active"); |
407 | 410 | }; |
408 | | - toc_items[0].classList.add("toc-active"); |
| 411 | + tocItems[0].classList.add("toc-active"); |
| 412 | + }; |
| 413 | + }) |
| 414 | + </script> |
| 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 | + } |
409 | 441 | } |
410 | | - }; |
| 442 | + } |
411 | 443 | }) |
412 | 444 | </script> |
413 | 445 |
|
414 | 446 | <!-- adjust alerts on mobile --> |
415 | 447 | <script type="text/javascript"> |
416 | | - alert_item = document.querySelector('#support-alert') |
| 448 | + alert = document.querySelector('#support-alert') |
417 | 449 | window.addEventListener("wheel", () => { |
418 | 450 | if (window.innerWidth < 1425) { |
419 | 451 | //adjust alert |
420 | 452 | if(window.pageYOffset > 0) { |
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 | | - } |
| 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 | + } |
427 | 459 | } |
428 | 460 | } |
429 | 461 | }); |
430 | 462 | window.addEventListener('resize', () => { |
431 | 463 | if (window.innerWidth >= 1425) { |
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'); |
| 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'); |
437 | 469 | } |
438 | 470 | } |
439 | 471 | }) |
|
0 commit comments