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

19
20
21
    // // Scrollspy
    // var $window = $(window)
    // var $body   = $(document.body)
22

23
24
25
26
27
28
    // $body.scrollspy({
    //   target: '.active .bs-docs-sidenav'
    // })
    // $window.on('load', function () {
    //   $body.scrollspy('refresh')
    // })
29

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

35
    // theme toggler
Mark Otto's avatar
Mark Otto committed
36
    (function () {
37
      var stylesheetLink = $('#bs-theme-stylesheet')
Mark Otto's avatar
Mark Otto committed
38
      var themeBtn = $('.bs-docs-theme-toggle')
39
40
41
42
43
44
45
46
47
48
49

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

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

50
      themeBtn.click(function () {
51
        var href = stylesheetLink.attr('href')
52
        if (!href || href.indexOf('data') === 0) {
53
54
          activateTheme()
        } else {
55
          stylesheetLink.attr('href', '')
Mark Otto's avatar
Mark Otto committed
56
          themeBtn.text('Preview theme')
57
          localStorage.removeItem('previewTheme')
58
        }
59
      })
Mark Otto's avatar
Mark Otto committed
60
    })
61

Mark Otto's avatar
Mark Otto committed
62
    // Tooltip and popover demos
63
    $('.tooltip-demo').tooltip({
64
      selector: '[data-toggle="tooltip"]',
XhmikosR's avatar
XhmikosR committed
65
      container: 'body'
Jacob Thornton's avatar
Jacob Thornton committed
66
    })
67
68
69
70
    $('.popover-demo').popover({
      selector: '[data-toggle="popover"]',
      container: 'body'
    })
71

72
    // Demos within modals
73
74
    $('.tooltip-test').tooltip()
    $('.popover-test').popover()
Jacob Thornton's avatar
Jacob Thornton committed
75

76
    // Popover demos
Mark Otto's avatar
Mark Otto committed
77
78
    $('.bs-docs-popover').popover()

Mark Otto's avatar
Mark Otto committed
79
    // Button state demo
80
    $('#loading-example-btn').on('click', function () {
Mark Otto's avatar
Mark Otto committed
81
82
83
84
85
      var btn = $(this)
      btn.button('loading')
      setTimeout(function () {
        btn.button('reset')
      }, 3000)
Mark Otto's avatar
Mark Otto committed
86
    })
Jacob Thornton's avatar
Jacob Thornton committed
87

88
89
90
91
    // 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
92
93
94

    // Config ZeroClipboard
    ZeroClipboard.config({
XhmikosR's avatar
XhmikosR committed
95
      moviePath: '/assets/flash/ZeroClipboard.swf',
Mark Otto's avatar
Mark Otto committed
96
97
98
      hoverClass: 'btn-clipboard-hover'
    })

XhmikosR's avatar
XhmikosR committed
99
    // Insert copy to clipboard button before .highlight
100
    $('.highlight').each(function () {
Mark Otto's avatar
Mark Otto committed
101
      var btnHtml = '<div class="zero-clipboard"><span class="btn-clipboard">Copy</span></div>'
XhmikosR's avatar
XhmikosR committed
102
      $(this).before(btnHtml)
Mark Otto's avatar
Mark Otto committed
103
104
105
    })
    var zeroClipboard = new ZeroClipboard($('.btn-clipboard'))
    var htmlBridge = $('#global-zeroclipboard-html-bridge')
106
107

    // Handlers for ZeroClipboard
108
    zeroClipboard.on('load', function () {
109
      htmlBridge
Mark Otto's avatar
Mark Otto committed
110
111
        .data('placement', 'top')
        .attr('title', 'Copy to clipboard')
112
113
114
115
        .tooltip()
    })

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

    // Notify copy success and reset tooltip title
122
    zeroClipboard.on('complete', function () {
123
      htmlBridge
Mark Otto's avatar
Mark Otto committed
124
        .attr('title', 'Copied!')
125
126
        .tooltip('fixTitle')
        .tooltip('show')
Mark Otto's avatar
Mark Otto committed
127
        .attr('title', 'Copy to clipboard')
128
129
130
131
        .tooltip('fixTitle')
    })

    // Notify copy failure
132
    zeroClipboard.on('noflash wrongflash', function () {
133
      htmlBridge
Mark Otto's avatar
Mark Otto committed
134
        .attr('title', 'Flash required')
135
136
137
138
        .tooltip('fixTitle')
        .tooltip('show')
    })

139
  })
140

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