cheatsheet.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* global bootstrap: false */
  2. (function () {
  3. 'use strict'
  4. // Tooltip and popover demos
  5. document.querySelectorAll('.tooltip-demo')
  6. .forEach(function (tooltip) {
  7. new bootstrap.Tooltip(tooltip, {
  8. selector: '[data-bs-toggle="tooltip"]'
  9. })
  10. })
  11. document.querySelectorAll('[data-bs-toggle="popover"]')
  12. .forEach(function (popover) {
  13. new bootstrap.Popover(popover)
  14. })
  15. document.querySelectorAll('.toast')
  16. .forEach(function (toastNode) {
  17. var toast = new bootstrap.Toast(toastNode, {
  18. autohide: false
  19. })
  20. toast.show()
  21. })
  22. // Disable empty links and submit buttons
  23. document.querySelectorAll('[href="#"], [type="submit"]')
  24. .forEach(function (link) {
  25. link.addEventListener('click', function (event) {
  26. event.preventDefault()
  27. })
  28. })
  29. function setActiveItem() {
  30. var hash = window.location.hash
  31. if (hash === '') {
  32. return
  33. }
  34. var link = document.querySelector('.bd-aside a[href="' + hash + '"]')
  35. if (!link) {
  36. return
  37. }
  38. var active = document.querySelector('.bd-aside .active')
  39. var parent = link.parentNode.parentNode.previousElementSibling
  40. link.classList.add('active')
  41. if (parent.classList.contains('collapsed')) {
  42. parent.click()
  43. }
  44. if (!active) {
  45. return
  46. }
  47. var expanded = active.parentNode.parentNode.previousElementSibling
  48. active.classList.remove('active')
  49. if (expanded && parent !== expanded) {
  50. expanded.click()
  51. }
  52. }
  53. setActiveItem()
  54. window.addEventListener('hashchange', setActiveItem)
  55. })()