application.js 4.14 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

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

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

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

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

Mark Otto's avatar
Mark Otto committed
29
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
36

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

      $sideBar.affix({
Mark Otto's avatar
Mark Otto committed
41
        offset: {
fat's avatar
fat committed
42
43
44
45
46
47
          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)
48
49
          },
          bottom: function () {
50
            return (this.bottom = $('.bs-docs-footer').outerHeight(true))
fat's avatar
fat committed
51
          }
Mark Otto's avatar
Mark Otto committed
52
53
54
        }
      })
    }, 100)
55

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

60
61
62
    // theme toggler
    ;(function () {
      var stylesheetLink = $('#bs-theme-stylesheet')
Mark Otto's avatar
Mark Otto committed
63
      var themeBtn = $('.bs-docs-theme-toggle')
64
      themeBtn.click(function () {
65
66
        var href = stylesheetLink.attr('href');
        if (!href || href.indexOf('data') === 0) {
67
          stylesheetLink.attr('href', stylesheetLink.attr('data-href'))
Mark Otto's avatar
Mark Otto committed
68
          themeBtn.text('Disable theme preview')
69
        }
70
71
        else {
          stylesheetLink.attr('href', '')
Mark Otto's avatar
Mark Otto committed
72
          themeBtn.text('Preview theme')
73
        }
74
75
76
      })
    })();

Mark Otto's avatar
Mark Otto committed
77
    // Tooltip and popover demos
78
    $('.tooltip-demo').tooltip({
79
      selector: '[data-toggle="tooltip"]',
XhmikosR's avatar
XhmikosR committed
80
      container: 'body'
Jacob Thornton's avatar
Jacob Thornton committed
81
    })
82

83
84
    $('.tooltip-test').tooltip()
    $('.popover-test').popover()
Jacob Thornton's avatar
Jacob Thornton committed
85

Mark Otto's avatar
Mark Otto committed
86
    $('.bs-docs-navbar').tooltip({
87
      selector: 'a[data-toggle="tooltip"]',
XhmikosR's avatar
XhmikosR committed
88
      container: '.bs-docs-navbar .nav'
Mark Otto's avatar
Mark Otto committed
89
90
    })

Mark Otto's avatar
Mark Otto committed
91
    // Default popover demo
Mark Otto's avatar
Mark Otto committed
92
93
    $('.bs-docs-popover').popover()

Mark Otto's avatar
Mark Otto committed
94
95
96
97
98
99
100
    // Button state demo
    $('#loading-example-btn').click(function () {
      var btn = $(this)
      btn.button('loading')
      setTimeout(function () {
        btn.button('reset')
      }, 3000)
Mark Otto's avatar
Mark Otto committed
101
    })
Jacob Thornton's avatar
Jacob Thornton committed
102

Mark Otto's avatar
Mark Otto committed
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

    // Config ZeroClipboard
    ZeroClipboard.config({
      moviePath: '/assets/flash/zero-clipboard.swf',
      hoverClass: 'btn-clipboard-hover'
    })

    // Insert copy to clipboard button before .highlight or .bs-example
    $('.highlight').each(function() {
      var highlight = $(this)
      var previous = highlight.prev()
      var btnHtml = '<div class="zero-clipboard"><span class="btn-clipboard">Copy</span></div>'

      if (previous.hasClass('bs-example')) {
        previous.before(btnHtml.replace(/btn-clipboard/, 'btn-clipboard with-example'))
      } else {
        highlight.before(btnHtml)
      }
    })
    var zeroClipboard = new ZeroClipboard($('.btn-clipboard'))
    var htmlBridge = $('#global-zeroclipboard-html-bridge')
124
125
126
127

    // Handlers for ZeroClipboard
    zeroClipboard.on('load', function(client) {
      htmlBridge
Mark Otto's avatar
Mark Otto committed
128
129
        .data('placement', 'top')
        .attr('title', 'Copy to clipboard')
130
131
132
133
134
135
136
137
138
139
140
141
        .tooltip()
    })

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

    // Notify copy success and reset tooltip title
    zeroClipboard.on('complete', function(client) {
      htmlBridge
Mark Otto's avatar
Mark Otto committed
142
        .attr('title', 'Copied!')
143
144
        .tooltip('fixTitle')
        .tooltip('show')
Mark Otto's avatar
Mark Otto committed
145
        .attr('title', 'Copy')
146
147
148
149
150
151
        .tooltip('fixTitle')
    })

    // Notify copy failure
    zeroClipboard.on('noflash wrongflash', function(client) {
      htmlBridge
Mark Otto's avatar
Mark Otto committed
152
        .attr('title', 'Flash required')
153
154
155
156
        .tooltip('fixTitle')
        .tooltip('show')
    })

157
  })
158

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