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

18
19
20
21
22
23
24
25
26
27
28
29
30
    // 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="glyphicon glyphicon-list-alt btn-clipboard"></span></div>'

      if (previous.hasClass('bs-example')) {
        previous.before(btnHtml.replace(/btn-clipboard/, 'btn-clipboard with-example'))
      } else {
        highlight.before(btnHtml)
      }
    })

31
    var $window = $(window)
Jacob Thornton's avatar
Jacob Thornton committed
32
    var $body   = $(document.body)
33

Jacob Thornton's avatar
Jacob Thornton committed
34
    $body.scrollspy({
XhmikosR's avatar
XhmikosR committed
35
      target: '.bs-docs-sidebar'
fat's avatar
fat committed
36
37
    })

38
39
40
41
    $window.on('load', function () {
      $body.scrollspy('refresh')
    })

Jacob Thornton's avatar
Jacob Thornton committed
42
    $('.bs-docs-container [href=#]').click(function (e) {
43
44
45
      e.preventDefault()
    })

46
    // back to top
Mark Otto's avatar
Mark Otto committed
47
    setTimeout(function () {
48
      var $sideBar = $('.bs-docs-sidebar')
fat's avatar
fat committed
49
50

      $sideBar.affix({
Mark Otto's avatar
Mark Otto committed
51
        offset: {
fat's avatar
fat committed
52
53
54
55
56
57
          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)
58
59
          },
          bottom: function () {
60
            return (this.bottom = $('.bs-docs-footer').outerHeight(true))
fat's avatar
fat committed
61
          }
Mark Otto's avatar
Mark Otto committed
62
63
64
        }
      })
    }, 100)
65

66
    setTimeout(function () {
Mark Otto's avatar
Mark Otto committed
67
      $('.bs-top').affix()
68
69
    }, 100)

70
71
72
    // theme toggler
    ;(function () {
      var stylesheetLink = $('#bs-theme-stylesheet')
Mark Otto's avatar
Mark Otto committed
73
      var themeBtn = $('.bs-docs-theme-toggle')
74
      themeBtn.click(function () {
75
76
        var href = stylesheetLink.attr('href');
        if (!href || href.indexOf('data') === 0) {
77
          stylesheetLink.attr('href', stylesheetLink.attr('data-href'))
Mark Otto's avatar
Mark Otto committed
78
          themeBtn.text('Disable theme preview')
79
        }
80
81
        else {
          stylesheetLink.attr('href', '')
Mark Otto's avatar
Mark Otto committed
82
          themeBtn.text('Preview theme')
83
        }
84
85
86
      })
    })();

Jacob Thornton's avatar
Jacob Thornton committed
87
    // tooltip demo
88
    $('.tooltip-demo').tooltip({
89
      selector: '[data-toggle="tooltip"]',
XhmikosR's avatar
XhmikosR committed
90
      container: 'body'
Jacob Thornton's avatar
Jacob Thornton committed
91
    })
92

93
94
    $('.tooltip-test').tooltip()
    $('.popover-test').popover()
Jacob Thornton's avatar
Jacob Thornton committed
95

Mark Otto's avatar
Mark Otto committed
96
    $('.bs-docs-navbar').tooltip({
97
      selector: 'a[data-toggle="tooltip"]',
XhmikosR's avatar
XhmikosR committed
98
      container: '.bs-docs-navbar .nav'
Mark Otto's avatar
Mark Otto committed
99
100
    })

Jacob Thornton's avatar
Jacob Thornton committed
101
    // popover demo
Mark Otto's avatar
Mark Otto committed
102
103
104
105
106
107
    $('.bs-docs-popover').popover()

    // Popover dismiss on next click
    $('.bs-docs-popover-dismiss').popover({
      trigger: 'focus'
    })
Jacob Thornton's avatar
Jacob Thornton committed
108
109

    // button state demo
110
    $('#loading-example-btn')
Jacob Thornton's avatar
Jacob Thornton committed
111
112
113
114
115
116
117
      .click(function () {
        var btn = $(this)
        btn.button('loading')
        setTimeout(function () {
          btn.button('reset')
        }, 3000)
      })
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151

    // Handlers for ZeroClipboard
    zeroClipboard.on('load', function(client) {
      htmlBridge
        .data('placement', 'left')
        .attr('title', 'copy to clipboard')
        .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
        .attr('title', 'copied!')
        .tooltip('fixTitle')
        .tooltip('show')
        .attr('title', 'copy to clipboard')
        .tooltip('fixTitle')
    })

    // Notify copy failure
    zeroClipboard.on('noflash wrongflash', function(client) {
      htmlBridge
        .attr('title', 'flash not supported!')
        .tooltip('fixTitle')
        .tooltip('show')
    })

152
  })
153

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