application.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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-2019 Twitter, Inc.
  7. * Licensed under the Creative Commons Attribution 3.0 Unported License. For
  8. * details, see https://creativecommons.org/licenses/by/3.0/.
  9. */
  10. /* global ClipboardJS: false, anchors: false */
  11. !function ($) {
  12. 'use strict';
  13. $(function () {
  14. // Scrollspy
  15. var $window = $(window)
  16. var $body = $(document.body)
  17. $body.scrollspy({
  18. target: '.bs-docs-sidebar'
  19. })
  20. $window.on('load', function () {
  21. $body.scrollspy('refresh')
  22. })
  23. // Kill links
  24. $('.bs-docs-container [href="#"]').click(function (e) {
  25. e.preventDefault()
  26. })
  27. // Sidenav affixing
  28. setTimeout(function () {
  29. var $sideBar = $('.bs-docs-sidebar')
  30. $sideBar.affix({
  31. offset: {
  32. top: function () {
  33. var offsetTop = $sideBar.offset().top
  34. var sideBarMargin = parseInt($sideBar.children(0).css('margin-top'), 10)
  35. var navOuterHeight = $('.bs-docs-nav').height()
  36. return (this.top = offsetTop - navOuterHeight - sideBarMargin)
  37. },
  38. bottom: function () {
  39. return (this.bottom = $('.bs-docs-footer').outerHeight(true))
  40. }
  41. }
  42. })
  43. }, 100)
  44. setTimeout(function () {
  45. $('.bs-top').affix()
  46. }, 100)
  47. // Theme toggler
  48. ;(function () {
  49. var $stylesheetLink = $('#bs-theme-stylesheet')
  50. var $themeBtn = $('.bs-docs-theme-toggle')
  51. var activateTheme = function () {
  52. $stylesheetLink.attr('href', $stylesheetLink.attr('data-href'))
  53. $themeBtn.text('Disable theme preview')
  54. localStorage.setItem('previewTheme', true)
  55. }
  56. if (localStorage.getItem('previewTheme')) {
  57. activateTheme()
  58. }
  59. $themeBtn.click(function () {
  60. var href = $stylesheetLink.attr('href')
  61. if (!href || href.indexOf('data') === 0) {
  62. activateTheme()
  63. } else {
  64. $stylesheetLink.attr('href', '')
  65. $themeBtn.text('Preview theme')
  66. localStorage.removeItem('previewTheme')
  67. }
  68. })
  69. })();
  70. // Tooltip and popover demos
  71. $('.tooltip-demo').tooltip({
  72. selector: '[data-toggle="tooltip"]',
  73. container: 'body'
  74. })
  75. $('.popover-demo').popover({
  76. selector: '[data-toggle="popover"]',
  77. container: 'body'
  78. })
  79. // Demos within modals
  80. $('.tooltip-test').tooltip()
  81. $('.popover-test').popover()
  82. // Popover demos
  83. $('.bs-docs-popover').popover()
  84. // Button state demo
  85. $('#loading-example-btn').on('click', function () {
  86. var $btn = $(this)
  87. $btn.button('loading')
  88. setTimeout(function () {
  89. $btn.button('reset')
  90. }, 3000)
  91. })
  92. // Modal relatedTarget demo
  93. $('#exampleModal').on('show.bs.modal', function (event) {
  94. var $button = $(event.relatedTarget) // Button that triggered the modal
  95. var recipient = $button.data('whatever') // Extract info from data-* attributes
  96. // If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
  97. // Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
  98. var $modal = $(this)
  99. $modal.find('.modal-title').text('New message to ' + recipient)
  100. $modal.find('.modal-body input').val(recipient)
  101. })
  102. // Activate animated progress bar
  103. $('.bs-docs-activate-animated-progressbar').on('click', function () {
  104. $(this).siblings('.progress').find('.progress-bar-striped').toggleClass('active')
  105. })
  106. // Insert copy to clipboard button before .highlight
  107. $('figure.highlight, div.highlight').each(function () {
  108. var btnHtml = '<div class="bs-clipboard"><button type="button" class="btn-clipboard" title="Copy to clipboard">Copy</button></div>'
  109. $(this).before(btnHtml)
  110. $('.btn-clipboard')
  111. .tooltip()
  112. .on('mouseleave', function () {
  113. // Explicitly hide tooltip, since after clicking it remains
  114. // focused (as it's a button), so tooltip would otherwise
  115. // remain visible until focus is moved away
  116. $(this).tooltip('hide')
  117. })
  118. })
  119. var clipboard = new ClipboardJS('.btn-clipboard', {
  120. target: function (trigger) {
  121. return trigger.parentNode.nextElementSibling
  122. }
  123. })
  124. clipboard.on('success', function (e) {
  125. $(e.trigger)
  126. .attr('title', 'Copied!')
  127. .tooltip('fixTitle')
  128. .tooltip('show')
  129. .attr('title', 'Copy to clipboard')
  130. .tooltip('fixTitle')
  131. e.clearSelection()
  132. })
  133. clipboard.on('error', function (e) {
  134. var modifierKey = /Mac/i.test(navigator.userAgent) ? '\u2318' : 'Ctrl-'
  135. var fallbackMsg = 'Press ' + modifierKey + 'C to copy'
  136. $(e.trigger)
  137. .attr('title', fallbackMsg)
  138. .tooltip('fixTitle')
  139. .tooltip('show')
  140. .attr('title', 'Copy to clipboard')
  141. .tooltip('fixTitle')
  142. })
  143. })
  144. }(jQuery)
  145. ;(function () {
  146. 'use strict';
  147. anchors.options.placement = 'left';
  148. anchors.add('.bs-docs-section > h1, .bs-docs-section > h2, .bs-docs-section > h3, .bs-docs-section > h4, .bs-docs-section > h5')
  149. })();