application.js 5 KB
Newer Older
1
2
3
// NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT
// IT'S ALL JUST JUNK FOR OUR DOCS!
// ++++++++++++++++++++++++++++++++++++++++++
4

5
/*!
6
 * JavaScript for Bootstrap's docs (http://getbootstrap.com)
7
 * Copyright 2011-2014 Twitter, Inc.
8
9
 * Licensed under the Creative Commons Attribution 3.0 Unported License. For
 * details, see http://creativecommons.org/licenses/by/3.0/.
10
11
 */

12
/* global ZeroClipboard */
13

14
!function ($) {
XhmikosR's avatar
XhmikosR committed
15
  'use strict';
16

17
  $(function () {
Jacob Thornton's avatar
Jacob Thornton committed
18

Mark Otto's avatar
Mark Otto committed
19
    // Scrollspy
20
    var $window = $(window)
Jacob Thornton's avatar
Jacob Thornton committed
21
    var $body   = $(document.body)
22

Jacob Thornton's avatar
Jacob Thornton committed
23
    $body.scrollspy({
XhmikosR's avatar
XhmikosR committed
24
      target: '.bs-docs-sidebar'
fat's avatar
fat committed
25
    })
26
27
28
29
    $window.on('load', function () {
      $body.scrollspy('refresh')
    })

Mark Otto's avatar
Mark Otto committed
30
    // Kill links
Jacob Thornton's avatar
Jacob Thornton committed
31
    $('.bs-docs-container [href=#]').click(function (e) {
32
33
34
      e.preventDefault()
    })

Mark Otto's avatar
Mark Otto committed
35
    // Sidenav affixing
Mark Otto's avatar
Mark Otto committed
36
    setTimeout(function () {
37
      var $sideBar = $('.bs-docs-sidebar')
fat's avatar
fat committed
38
39

      $sideBar.affix({
Mark Otto's avatar
Mark Otto committed
40
        offset: {
fat's avatar
fat committed
41
42
43
44
45
46
          top: function () {
            var offsetTop      = $sideBar.offset().top
            var sideBarMargin  = parseInt($sideBar.children(0).css('margin-top'), 10)
            var navOuterHeight = $('.bs-docs-nav').height()

            return (this.top = offsetTop - navOuterHeight - sideBarMargin)
47
48
          },
          bottom: function () {
49
            return (this.bottom = $('.bs-docs-footer').outerHeight(true))
fat's avatar
fat committed
50
          }
Mark Otto's avatar
Mark Otto committed
51
52
53
        }
      })
    }, 100)
54

55
    setTimeout(function () {
Mark Otto's avatar
Mark Otto committed
56
      $('.bs-top').affix()
57
58
    }, 100)

59
60
61
    // theme toggler
    ;(function () {
      var stylesheetLink = $('#bs-theme-stylesheet')
Mark Otto's avatar
Mark Otto committed
62
      var themeBtn = $('.bs-docs-theme-toggle')
63
64
65
66
67
68
69
70
71
72
73

      var activateTheme = function () {
        stylesheetLink.attr('href', stylesheetLink.attr('data-href'))
        themeBtn.text('Disable theme preview')
        localStorage.setItem('previewTheme', true)
      }

      if (localStorage.getItem('previewTheme')) {
        activateTheme()
      }

74
      themeBtn.click(function () {
75
        var href = stylesheetLink.attr('href')
76
        if (!href || href.indexOf('data') === 0) {
77
78
          activateTheme()
        } else {
79
          stylesheetLink.attr('href', '')
Mark Otto's avatar
Mark Otto committed
80
          themeBtn.text('Preview theme')
81
          localStorage.removeItem('previewTheme')
82
        }
83
84
85
      })
    })();

Mark Otto's avatar
Mark Otto committed
86
    // Tooltip and popover demos
87
    $('.tooltip-demo').tooltip({
88
      selector: '[data-toggle="tooltip"]',
XhmikosR's avatar
XhmikosR committed
89
      container: 'body'
Jacob Thornton's avatar
Jacob Thornton committed
90
    })
91
92
93
94
    $('.popover-demo').popover({
      selector: '[data-toggle="popover"]',
      container: 'body'
    })
95

96
    // Demos within modals
97
98
    $('.tooltip-test').tooltip()
    $('.popover-test').popover()
Jacob Thornton's avatar
Jacob Thornton committed
99

100
    // Popover demos
Mark Otto's avatar
Mark Otto committed
101
102
    $('.bs-docs-popover').popover()

Mark Otto's avatar
Mark Otto committed
103
    // Button state demo
104
    $('#loading-example-btn').on('click', function () {
Mark Otto's avatar
Mark Otto committed
105
106
107
108
109
      var btn = $(this)
      btn.button('loading')
      setTimeout(function () {
        btn.button('reset')
      }, 3000)
Mark Otto's avatar
Mark Otto committed
110
    })
Jacob Thornton's avatar
Jacob Thornton committed
111

112
113
114
115
116
117
118
119
120
121
122
    // Modal relatedTarget demo
    $('#exampleModal').on('show.bs.modal', function (event) {
      var button = $(event.relatedTarget) // Button that triggered the modal
      var recipient = button.data('whatever') // Extract info from data-* attributes
      // If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
      // Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
      var modal = $(this)
      modal.find('.modal-title').text('New message to ' + recipient)
      modal.find('.modal-body input').val(recipient)
    })

123
124
125
126
    // Activate animated progress bar
    $('.bs-docs-activate-animated-progressbar').on('click', function () {
      $(this).siblings('.progress').find('.progress-bar-striped').toggleClass('active')
    })
Mark Otto's avatar
Mark Otto committed
127
128
129

    // Config ZeroClipboard
    ZeroClipboard.config({
XhmikosR's avatar
XhmikosR committed
130
      moviePath: '/assets/flash/ZeroClipboard.swf',
Mark Otto's avatar
Mark Otto committed
131
132
133
      hoverClass: 'btn-clipboard-hover'
    })

XhmikosR's avatar
XhmikosR committed
134
    // Insert copy to clipboard button before .highlight
135
    $('.highlight').each(function () {
Mark Otto's avatar
Mark Otto committed
136
      var btnHtml = '<div class="zero-clipboard"><span class="btn-clipboard">Copy</span></div>'
XhmikosR's avatar
XhmikosR committed
137
      $(this).before(btnHtml)
Mark Otto's avatar
Mark Otto committed
138
139
140
    })
    var zeroClipboard = new ZeroClipboard($('.btn-clipboard'))
    var htmlBridge = $('#global-zeroclipboard-html-bridge')
141
142

    // Handlers for ZeroClipboard
143
    zeroClipboard.on('load', function () {
144
      htmlBridge
Mark Otto's avatar
Mark Otto committed
145
146
        .data('placement', 'top')
        .attr('title', 'Copy to clipboard')
147
148
149
150
        .tooltip()
    })

    // Copy to clipboard
151
    zeroClipboard.on('dataRequested', function (client) {
152
153
154
155
156
      var highlight = $(this).parent().nextAll('.highlight').first()
      client.setText(highlight.text())
    })

    // Notify copy success and reset tooltip title
157
    zeroClipboard.on('complete', function () {
158
      htmlBridge
Mark Otto's avatar
Mark Otto committed
159
        .attr('title', 'Copied!')
160
161
        .tooltip('fixTitle')
        .tooltip('show')
Mark Otto's avatar
Mark Otto committed
162
        .attr('title', 'Copy to clipboard')
163
164
165
166
        .tooltip('fixTitle')
    })

    // Notify copy failure
167
    zeroClipboard.on('noflash wrongflash', function () {
168
      htmlBridge
Mark Otto's avatar
Mark Otto committed
169
        .attr('title', 'Flash required')
170
171
172
173
        .tooltip('fixTitle')
        .tooltip('show')
    })

174
  })
175

Zlatan Vasović's avatar
Zlatan Vasović committed
176
}(jQuery)