application.js 3.9 KB

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