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