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