application.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT
  2. // IT'S ALL JUST JUNK FOR OUR DOCS!
  3. // ++++++++++++++++++++++++++++++++++++++++++
  4. !function ($) {
  5. $(function(){
  6. // Disable certain links in docs
  7. $('section [href^=#]').click(function (e) {
  8. e.preventDefault()
  9. })
  10. // make code pretty
  11. window.prettyPrint && prettyPrint()
  12. // add-ons
  13. $('.add-on :checkbox').on('click', function () {
  14. var $this = $(this)
  15. , method = $this.attr('checked') ? 'addClass' : 'removeClass'
  16. $(this).parents('.add-on')[method]('active')
  17. })
  18. // position static twipsies for components page
  19. if ($(".twipsies a").length) {
  20. $(window).on('load resize', function () {
  21. $(".twipsies a").each(function () {
  22. $(this)
  23. .tooltip({
  24. placement: $(this).attr('title')
  25. , trigger: 'manual'
  26. })
  27. .tooltip('show')
  28. })
  29. })
  30. }
  31. // add tipsies to grid for scaffolding
  32. if ($('#grid-system').length) {
  33. $('#grid-system').tooltip({
  34. selector: '.show-grid > div'
  35. , title: function () { return $(this).width() + 'px' }
  36. })
  37. }
  38. // fix sub nav on scroll
  39. var $win = $(window)
  40. , $nav = $('.subnav')
  41. , navTop = $('.subnav').length && $('.subnav').offset().top - 40
  42. , isFixed = 0
  43. processScroll()
  44. $win.on('scroll', processScroll)
  45. function processScroll() {
  46. var i, scrollTop = $win.scrollTop()
  47. if (scrollTop >= navTop && !isFixed) {
  48. isFixed = 1
  49. $nav.addClass('subnav-fixed')
  50. } else if (scrollTop <= navTop && isFixed) {
  51. isFixed = 0
  52. $nav.removeClass('subnav-fixed')
  53. }
  54. }
  55. // tooltip demo
  56. $('.tooltip-demo.well').tooltip({
  57. selector: "a[rel=tooltip]"
  58. })
  59. $('.tooltip-test').tooltip()
  60. $('.popover-test').popover()
  61. // popover demo
  62. $("a[rel=popover]")
  63. .popover()
  64. .click(function(e) {
  65. e.preventDefault()
  66. })
  67. // button state demo
  68. $('#fat-btn')
  69. .click(function () {
  70. var btn = $(this)
  71. btn.button('loading')
  72. setTimeout(function () {
  73. btn.button('reset')
  74. }, 3000)
  75. })
  76. // carousel demo
  77. $('#myCarousel').carousel()
  78. // javascript build logic
  79. var inputsComponent = $("#components.download input")
  80. , inputsPlugin = $("#plugins.download input")
  81. , inputsVariables = $("#variables.download input")
  82. // toggle all plugin checkboxes
  83. $('#components.download .toggle-all').on('click', function (e) {
  84. e.preventDefault()
  85. inputsComponent.attr('checked', !inputsComponent.is(':checked'))
  86. })
  87. $('#plugins.download .toggle-all').on('click', function (e) {
  88. e.preventDefault()
  89. inputsPlugin.attr('checked', !inputsPlugin.is(':checked'))
  90. })
  91. $('#variables.download .toggle-all').on('click', function (e) {
  92. e.preventDefault()
  93. inputsVariables.val('')
  94. })
  95. // request built javascript
  96. $('.download-btn').on('click', function () {
  97. var css = $("#components.download input:checked")
  98. .map(function () { return this.value })
  99. .toArray()
  100. , js = $("#plugins.download input:checked")
  101. .map(function () { return this.value })
  102. .toArray()
  103. , vars = {}
  104. , img = ['glyphicons-halflings.png', 'glyphicons-halflings-white.png']
  105. $("#variables.download input")
  106. .each(function () {
  107. $(this).val() && (vars[ $(this).prev().text() ] = $(this).val())
  108. })
  109. $.ajax({
  110. type: 'POST'
  111. , url: 'http://bootstrap.herokuapp.com'
  112. , dataType: 'jsonpi'
  113. , params: {
  114. js: js
  115. , css: css
  116. , vars: vars
  117. , img: img
  118. }
  119. })
  120. })
  121. })
  122. // Modified from the original jsonpi https://github.com/benvinegar/jquery-jsonpi
  123. $.ajaxTransport('jsonpi', function(opts, originalOptions, jqXHR) {
  124. var url = opts.url;
  125. return {
  126. send: function(_, completeCallback) {
  127. var name = 'jQuery_iframe_' + jQuery.now()
  128. , iframe, form
  129. iframe = $('<iframe>')
  130. .attr('name', name)
  131. .appendTo('head')
  132. form = $('<form>')
  133. .attr('method', opts.type) // GET or POST
  134. .attr('action', url)
  135. .attr('target', name)
  136. $.each(opts.params, function(k, v) {
  137. $('<input>')
  138. .attr('type', 'hidden')
  139. .attr('name', k)
  140. .attr('value', typeof v == 'string' ? v : JSON.stringify(v))
  141. .appendTo(form)
  142. })
  143. form.appendTo('body').submit()
  144. }
  145. }
  146. })
  147. }(window.jQuery)