application.js 4.98 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
19
20
21
  function makeArray(list) {
    return [].slice.call(list)
  }

XhmikosR's avatar
XhmikosR committed
22
  // Tooltip and popover demos
23
  makeArray(document.querySelectorAll('.tooltip-demo'))
XhmikosR's avatar
XhmikosR committed
24
25
26
    .forEach(function (tooltip) {
      new bootstrap.Tooltip(tooltip, {
        selector: '[data-toggle="tooltip"]'
Johann-S's avatar
Johann-S committed
27
      })
XhmikosR's avatar
XhmikosR committed
28
    })
Jacob Thornton's avatar
Jacob Thornton committed
29

30
  makeArray(document.querySelectorAll('[data-toggle="popover"]'))
XhmikosR's avatar
XhmikosR committed
31
32
33
    .forEach(function (popover) {
      new bootstrap.Popover(popover)
    })
Johann-S's avatar
Johann-S committed
34

35
  makeArray(document.querySelectorAll('.toast'))
XhmikosR's avatar
XhmikosR committed
36
37
38
    .forEach(function (toastNode) {
      var toast = new bootstrap.Toast(toastNode, {
        autohide: false
Johann-S's avatar
Johann-S committed
39
40
      })

XhmikosR's avatar
XhmikosR committed
41
42
      toast.show()
    })
43

XhmikosR's avatar
XhmikosR committed
44
  // Demos within modals
45
  makeArray(document.querySelectorAll('.tooltip-test'))
XhmikosR's avatar
XhmikosR committed
46
47
48
    .forEach(function (tooltip) {
      new bootstrap.Tooltip(tooltip)
    })
Jacob Thornton's avatar
Jacob Thornton committed
49

50
  makeArray(document.querySelectorAll('.popover-test'))
XhmikosR's avatar
XhmikosR committed
51
52
53
    .forEach(function (popover) {
      new bootstrap.Popover(popover)
    })
54

XhmikosR's avatar
XhmikosR committed
55
  // Indeterminate checkbox example
56
  makeArray(document.querySelectorAll('.bd-example-indeterminate [type="checkbox"]'))
XhmikosR's avatar
XhmikosR committed
57
58
59
    .forEach(function (checkbox) {
      checkbox.indeterminate = true
    })
Mark Otto's avatar
Mark Otto committed
60

XhmikosR's avatar
XhmikosR committed
61
  // Disable empty links in docs examples
62
  makeArray(document.querySelectorAll('.bd-content [href="#"]'))
XhmikosR's avatar
XhmikosR committed
63
64
65
66
67
    .forEach(function (link) {
      link.addEventListener('click', function (e) {
        e.preventDefault()
      })
    })
68

XhmikosR's avatar
XhmikosR committed
69
70
71
72
73
74
  // Modal relatedTarget demo
  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
75

XhmikosR's avatar
XhmikosR committed
76
77
78
      // Update the modal's content.
      var modalTitle = exampleModal.querySelector('.modal-title')
      var modalBodyInput = exampleModal.querySelector('.modal-body input')
79

XhmikosR's avatar
XhmikosR committed
80
81
82
83
84
85
      modalTitle.innerHTML = 'New message to ' + recipient
      modalBodyInput.value = recipient
    })
  }

  // Activate animated progress bar
86
  makeArray(document.querySelectorAll('.bd-toggle-animated-progress > .progress-bar-striped'))
XhmikosR's avatar
XhmikosR committed
87
88
89
90
91
92
93
    .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')
        }
94
      })
XhmikosR's avatar
XhmikosR committed
95
    })
Mark Otto's avatar
Mark Otto committed
96

XhmikosR's avatar
XhmikosR committed
97
98
  // Insert copy to clipboard button before .highlight
  var btnHtml = '<div class="bd-clipboard"><button type="button" class="btn-clipboard" title="Copy to clipboard">Copy</button></div>'
99
  makeArray(document.querySelectorAll('figure.highlight, div.highlight'))
XhmikosR's avatar
XhmikosR committed
100
101
102
    .forEach(function (element) {
      element.insertAdjacentHTML('beforebegin', btnHtml)
    })
103

104
  makeArray(document.querySelectorAll('.btn-clipboard'))
XhmikosR's avatar
XhmikosR committed
105
106
    .forEach(function (btn) {
      var tooltipBtn = new bootstrap.Tooltip(btn)
107

XhmikosR's avatar
XhmikosR committed
108
109
110
111
112
      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()
113
      })
114
    })
115

XhmikosR's avatar
XhmikosR committed
116
117
118
119
120
  var clipboard = new ClipboardJS('.btn-clipboard', {
    target: function (trigger) {
      return trigger.parentNode.nextElementSibling
    }
  })
121

XhmikosR's avatar
XhmikosR committed
122
123
  clipboard.on('success', function (e) {
    var tooltipBtn = bootstrap.Tooltip._getInstance(e.trigger)
124

XhmikosR's avatar
XhmikosR committed
125
126
127
    e.trigger.setAttribute('title', 'Copied!')
    tooltipBtn._fixTitle()
    tooltipBtn.show()
128

XhmikosR's avatar
XhmikosR committed
129
130
131
132
    e.trigger.setAttribute('title', 'Copy to clipboard')
    tooltipBtn._fixTitle()
    e.clearSelection()
  })
133

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

XhmikosR's avatar
XhmikosR committed
139
140
141
    e.trigger.setAttribute('title', fallbackMsg)
    tooltipBtn._fixTitle()
    tooltipBtn.show()
Jacob Thornton's avatar
Jacob Thornton committed
142

XhmikosR's avatar
XhmikosR committed
143
144
145
    e.trigger.setAttribute('title', 'Copy to clipboard')
    tooltipBtn._fixTitle()
  })
146

XhmikosR's avatar
XhmikosR committed
147
148
149
150
  anchors.options = {
    icon: '#'
  }
  anchors.add('.bd-content > h2, .bd-content > h3, .bd-content > h4, .bd-content > h5')
151

XhmikosR's avatar
XhmikosR committed
152
  // Wrap inner
153
  makeArray(document.querySelectorAll('.bd-content > h2, .bd-content > h3, .bd-content > h4, .bd-content > h5'))
XhmikosR's avatar
XhmikosR committed
154
155
156
157
158
    .forEach(function (hEl) {
      hEl.innerHTML = '<span class="bd-content-title">' + hEl.innerHTML + '</span>'
    })

  bsCustomFileInput.init()
159
}())