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

/*!
6
 * JavaScript for Bootstrap's docs (https://getbootstrap.com/)
XhmikosR's avatar
XhmikosR committed
7
8
 * Copyright 2011-2019 The Bootstrap Authors
 * Copyright 2011-2019 Twitter, Inc.
9
10
 * Licensed under the Creative Commons Attribution 3.0 Unported License.
 * For details, see https://creativecommons.org/licenses/by/3.0/.
Jacob Thornton's avatar
Jacob Thornton committed
11
12
 */

13
/* global ClipboardJS: false, anchors: false, bootstrap: false, bsCustomFileInput: false */
Jacob Thornton's avatar
Jacob Thornton committed
14

15
(function () {
16
  'use strict'
Jacob Thornton's avatar
Jacob Thornton committed
17

18
  document.addEventListener('DOMContentLoaded', function () {
Jacob Thornton's avatar
Jacob Thornton committed
19
    // Tooltip and popover demos
20
    var tooltipDemoList = [].slice.call(document.querySelectorAll('.tooltip-demo'))
21
22
23
24
25
    tooltipDemoList.forEach(function (tooltip) {
      new bootstrap.Tooltip(tooltip, {
        selector: '[data-toggle="tooltip"]'
      })
    })
26
27

    var popoverList = [].slice.call(document.querySelectorAll('[data-toggle="popover"]'))
28
29
    popoverList.forEach(function (popover) {
      new bootstrap.Popover(popover)
Jacob Thornton's avatar
Jacob Thornton committed
30
31
    })

Johann-S's avatar
Johann-S committed
32
33
34
35
36
37
    $('.toast')
      .toast({
        autohide: false
      })
      .toast('show')

Jacob Thornton's avatar
Jacob Thornton committed
38
    // Demos within modals
39
    var tooltipTestList = [].slice.call(document.querySelectorAll('.tooltip-test'))
40
41
42
43
    tooltipTestList.forEach(function (tooltip) {
      new bootstrap.Tooltip(tooltip)
    })

44
    var popoverTestList = [].slice.call(document.querySelectorAll('.popover-test'))
45
46
47
    popoverTestList.forEach(function (popover) {
      new bootstrap.Popover(popover)
    })
Jacob Thornton's avatar
Jacob Thornton committed
48

49
    // Indeterminate checkbox example
50
    var indeterminateCheckboxList = [].slice.call(document.querySelectorAll('.bd-example-indeterminate [type="checkbox"]'))
51
52
53
    indeterminateCheckboxList.forEach(function (checkbox) {
      checkbox.indeterminate = true
    })
54

Mark Otto's avatar
Mark Otto committed
55
    // Disable empty links in docs examples
56
    var emptyLinkList = [].slice.call(document.querySelectorAll('.bd-content [href="#"]'))
57
58
59
60
    emptyLinkList.forEach(function (link) {
      link.addEventListener('click', function (e) {
        e.preventDefault()
      })
Mark Otto's avatar
Mark Otto committed
61
62
    })

63
    // Modal relatedTarget demo
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
    var exampleModal = document.getElementById('exampleModal')
    if (exampleModal) {
      exampleModal.addEventListener('show.bs.modal', function (event) {
        var button = event.relatedTarget                     // Button that triggered the modal
        var recipient = button.getAttribute('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 modalTitle = exampleModal.querySelector('.modal-title')
        var modalBodyInput = exampleModal.querySelector('.modal-body input')

        modalTitle.innerHTML = 'New message to ' + recipient
        modalBodyInput.value = recipient
      })
    }
79

Mark Otto's avatar
Mark Otto committed
80
    // Activate animated progress bar
81
    var animatedProgressBarList = [].slice.call(document.querySelectorAll('.bd-toggle-animated-progress > .progress-bar-striped'))
82
83
84
85
86
87
88
89
    animatedProgressBarList.forEach(function (progressBar) {
      progressBar.addEventListener('click', function () {
        if (progressBar.classList.contains('progress-bar-animated')) {
          progressBar.classList.remove('progress-bar-animated')
        } else {
          progressBar.classList.add('progress-bar-animated')
        }
      })
Mark Otto's avatar
Mark Otto committed
90
91
    })

Jacob Thornton's avatar
Jacob Thornton committed
92
    // Insert copy to clipboard button before .highlight
93
    var btnHtml = '<div class="bd-clipboard"><button type="button" class="btn-clipboard" title="Copy to clipboard">Copy</button></div>'
94
95
    var highList = [].slice.call(document.querySelectorAll('figure.highlight, div.highlight'))
    highList.forEach(function (element) {
96
97
98
99
100
101
102
103
104
105
106
107
108
      element.insertAdjacentHTML('beforebegin', btnHtml)
    })

    var copyBtnList = [].slice.call(document.querySelectorAll('.btn-clipboard'))
    copyBtnList.forEach(function (btn) {
      var tooltipBtn = new bootstrap.Tooltip(btn)

      btn.addEventListener('mouseleave', function () {
        // Explicitly hide tooltip, since after clicking it remains
        // focused (as it's a button), so tooltip would otherwise
        // remain visible until focus is moved away
        tooltipBtn.hide()
      })
Jacob Thornton's avatar
Jacob Thornton committed
109
110
    })

XhmikosR's avatar
XhmikosR committed
111
    var clipboard = new ClipboardJS('.btn-clipboard', {
112
      target: function (trigger) {
113
        return trigger.parentNode.nextElementSibling
114
      }
115
    })
116
117

    clipboard.on('success', function (e) {
118
119
120
121
122
      var tooltipBtn = bootstrap.Tooltip._getInstance(e.trigger)

      e.trigger.setAttribute('title', 'Copied!')
      tooltipBtn._fixTitle()
      tooltipBtn.show()
123

124
125
      e.trigger.setAttribute('title', 'Copy to clipboard')
      tooltipBtn._fixTitle()
126
127
      e.clearSelection()
    })
128
129

    clipboard.on('error', function (e) {
Mark Otto's avatar
Mark Otto committed
130
131
      var modifierKey = /Mac/i.test(navigator.userAgent) ? '\u2318' : 'Ctrl-'
      var fallbackMsg = 'Press ' + modifierKey + 'C to copy'
132
133
134
135
136
      var tooltipBtn = bootstrap.Tooltip._getInstance(e.trigger)

      e.trigger.setAttribute('title', fallbackMsg)
      tooltipBtn._fixTitle()
      tooltipBtn.show()
137

138
139
      e.trigger.setAttribute('title', 'Copy to clipboard')
      tooltipBtn._fixTitle()
140
    })
Jacob Thornton's avatar
Jacob Thornton committed
141

142
143
144
145
    anchors.options = {
      icon: '#'
    }
    anchors.add('.bd-content > h2, .bd-content > h3, .bd-content > h4, .bd-content > h5')
146
147
148
149
150
151
152
153
154

    // Wrap inner
    var hList = [].slice.call(document.querySelectorAll('.bd-content > h2, .bd-content > h3, .bd-content > h4, .bd-content > h5'))
    hList.forEach(function (hEl) {
      var span = document.createElement('span')
      span.classList.add('bd-content-title')
      hEl.parentElement.insertBefore(span, hEl)
      span.appendChild(hEl)
    })
155

156
    bsCustomFileInput.init()
Jacob Thornton's avatar
Jacob Thornton committed
157
  })
158
}())