application.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 (http://getbootstrap.com)
  6. * Copyright 2011-2016 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 ZeroClipboard, anchors */
  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. // Config ZeroClipboard
  107. ZeroClipboard.config({
  108. moviePath: '/assets/flash/ZeroClipboard.swf',
  109. hoverClass: 'btn-clipboard-hover'
  110. })
  111. // Insert copy to clipboard button before .highlight
  112. $('.highlight').each(function () {
  113. var btnHtml = '<div class="zero-clipboard"><span class="btn-clipboard">Copy</span></div>'
  114. $(this).before(btnHtml)
  115. })
  116. var zeroClipboard = new ZeroClipboard($('.btn-clipboard'))
  117. var $htmlBridge = $('#global-zeroclipboard-html-bridge')
  118. // Handlers for ZeroClipboard
  119. zeroClipboard.on('load', function () {
  120. $htmlBridge
  121. .data('placement', 'top')
  122. .attr('title', 'Copy to clipboard')
  123. .tooltip()
  124. // Copy to clipboard
  125. zeroClipboard.on('dataRequested', function (client) {
  126. var highlight = $(this).parent().nextAll('.highlight').first()
  127. client.setText(highlight.text())
  128. })
  129. // Notify copy success and reset tooltip title
  130. zeroClipboard.on('complete', function () {
  131. $htmlBridge
  132. .attr('title', 'Copied!')
  133. .tooltip('fixTitle')
  134. .tooltip('show')
  135. .attr('title', 'Copy to clipboard')
  136. .tooltip('fixTitle')
  137. })
  138. })
  139. // Hide copy button when no Flash is found
  140. // or wrong Flash version is present
  141. zeroClipboard.on('noflash wrongflash', function () {
  142. $('.zero-clipboard').remove()
  143. ZeroClipboard.destroy()
  144. })
  145. })
  146. }(jQuery)
  147. ;(function () {
  148. 'use strict';
  149. anchors.options.placement = 'left';
  150. anchors.add('.bs-docs-section > h1, .bs-docs-section > h2, .bs-docs-section > h3, .bs-docs-section > h4, .bs-docs-section > h5')
  151. })();