application.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT
  2. // IT'S ALL JUST JUNK FOR OUR DOCS!
  3. // ++++++++++++++++++++++++++++++++++++++++++
  4. /*!
  5. * JavaScript for Bootstrap's docs (https://getbootstrap.com/)
  6. * Copyright 2011-2021 The Bootstrap Authors
  7. * Copyright 2011-2021 Twitter, Inc.
  8. * Licensed under the Creative Commons Attribution 3.0 Unported License.
  9. * For details, see https://creativecommons.org/licenses/by/3.0/.
  10. */
  11. /* global ClipboardJS: false, anchors: false, bootstrap: false */
  12. (function () {
  13. 'use strict'
  14. // Tooltip and popover demos
  15. document.querySelectorAll('.tooltip-demo')
  16. .forEach(function (tooltip) {
  17. new bootstrap.Tooltip(tooltip, {
  18. selector: '[data-bs-toggle="tooltip"]'
  19. })
  20. })
  21. document.querySelectorAll('[data-bs-toggle="popover"]')
  22. .forEach(function (popover) {
  23. new bootstrap.Popover(popover)
  24. })
  25. var toastPlacement = document.getElementById('toastPlacement')
  26. if (toastPlacement) {
  27. document.getElementById('selectToastPlacement').addEventListener('change', function () {
  28. if (!toastPlacement.dataset.originalClass) {
  29. toastPlacement.dataset.originalClass = toastPlacement.className
  30. }
  31. toastPlacement.className = toastPlacement.dataset.originalClass + ' ' + this.value
  32. })
  33. }
  34. document.querySelectorAll('.bd-example .toast')
  35. .forEach(function (toastNode) {
  36. var toast = new bootstrap.Toast(toastNode, {
  37. autohide: false
  38. })
  39. toast.show()
  40. })
  41. var toastTrigger = document.getElementById('liveToastBtn')
  42. var toastLiveExample = document.getElementById('liveToast')
  43. if (toastTrigger) {
  44. toastTrigger.addEventListener('click', function () {
  45. var toast = new bootstrap.Toast(toastLiveExample)
  46. toast.show()
  47. })
  48. }
  49. // Demos within modals
  50. document.querySelectorAll('.tooltip-test')
  51. .forEach(function (tooltip) {
  52. new bootstrap.Tooltip(tooltip)
  53. })
  54. document.querySelectorAll('.popover-test')
  55. .forEach(function (popover) {
  56. new bootstrap.Popover(popover)
  57. })
  58. // Indeterminate checkbox example
  59. document.querySelectorAll('.bd-example-indeterminate [type="checkbox"]')
  60. .forEach(function (checkbox) {
  61. checkbox.indeterminate = true
  62. })
  63. // Disable empty links in docs examples
  64. document.querySelectorAll('.bd-content [href="#"]')
  65. .forEach(function (link) {
  66. link.addEventListener('click', function (e) {
  67. e.preventDefault()
  68. })
  69. })
  70. // Modal relatedTarget demo
  71. var exampleModal = document.getElementById('exampleModal')
  72. if (exampleModal) {
  73. exampleModal.addEventListener('show.bs.modal', function (event) {
  74. // Button that triggered the modal
  75. var button = event.relatedTarget
  76. // Extract info from data-bs-* attributes
  77. var recipient = button.getAttribute('data-bs-whatever')
  78. // Update the modal's content.
  79. var modalTitle = exampleModal.querySelector('.modal-title')
  80. var modalBodyInput = exampleModal.querySelector('.modal-body input')
  81. modalTitle.textContent = 'New message to ' + recipient
  82. modalBodyInput.value = recipient
  83. })
  84. }
  85. // Activate animated progress bar
  86. var btnToggleAnimatedProgress = document.getElementById('btnToggleAnimatedProgress')
  87. if (btnToggleAnimatedProgress) {
  88. btnToggleAnimatedProgress.addEventListener('click', function () {
  89. btnToggleAnimatedProgress.parentNode
  90. .querySelector('.progress-bar-striped')
  91. .classList
  92. .toggle('progress-bar-animated')
  93. })
  94. }
  95. // Insert copy to clipboard button before .highlight
  96. var btnHtml = '<div class="bd-clipboard"><button type="button" class="btn-clipboard" title="Copy to clipboard">Copy</button></div>'
  97. document.querySelectorAll('div.highlight')
  98. .forEach(function (element) {
  99. element.insertAdjacentHTML('beforebegin', btnHtml)
  100. })
  101. document.querySelectorAll('.btn-clipboard')
  102. .forEach(function (btn) {
  103. var tooltipBtn = new bootstrap.Tooltip(btn)
  104. btn.addEventListener('mouseleave', function () {
  105. // Explicitly hide tooltip, since after clicking it remains
  106. // focused (as it's a button), so tooltip would otherwise
  107. // remain visible until focus is moved away
  108. tooltipBtn.hide()
  109. })
  110. })
  111. var clipboard = new ClipboardJS('.btn-clipboard', {
  112. target: function (trigger) {
  113. return trigger.parentNode.nextElementSibling
  114. }
  115. })
  116. clipboard.on('success', function (e) {
  117. var tooltipBtn = bootstrap.Tooltip.getInstance(e.trigger)
  118. e.trigger.setAttribute('data-bs-original-title', 'Copied!')
  119. tooltipBtn.show()
  120. e.trigger.setAttribute('data-bs-original-title', 'Copy to clipboard')
  121. e.clearSelection()
  122. })
  123. clipboard.on('error', function (e) {
  124. var modifierKey = /mac/i.test(navigator.userAgent) ? '\u2318' : 'Ctrl-'
  125. var fallbackMsg = 'Press ' + modifierKey + 'C to copy'
  126. var tooltipBtn = bootstrap.Tooltip.getInstance(e.trigger)
  127. e.trigger.setAttribute('data-bs-original-title', fallbackMsg)
  128. tooltipBtn.show()
  129. e.trigger.setAttribute('data-bs-original-title', 'Copy to clipboard')
  130. })
  131. anchors.options = {
  132. icon: '#'
  133. }
  134. anchors.add('.bd-content > h2, .bd-content > h3, .bd-content > h4, .bd-content > h5')
  135. })()