application.js 4.15 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
31

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

Mark Otto's avatar
Mark Otto committed
36
37

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

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

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

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

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

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

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

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

Mark Otto's avatar
Mark Otto committed
95
96
97
98
99
100
101
    // 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
102
    })
Jacob Thornton's avatar
Jacob Thornton committed
103

Mark Otto's avatar
Mark Otto committed
104
105
106

    // Config ZeroClipboard
    ZeroClipboard.config({
XhmikosR's avatar
XhmikosR committed
107
      moviePath: '/assets/flash/ZeroClipboard.swf',
Mark Otto's avatar
Mark Otto committed
108
109
110
111
      hoverClass: 'btn-clipboard-hover'
    })

    // Insert copy to clipboard button before .highlight or .bs-example
112
    $('.highlight').each(function () {
Mark Otto's avatar
Mark Otto committed
113
114
115
116
117
118
119
120
121
122
123
124
      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')
125
126

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

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

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

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

158
  })
159

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