application.js 4.4 KB

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