application.js 5.44 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
23
24
25
26
27
28
29
30
31
  (function () {
    var checkbox = document.getElementById('flexCheckIndeterminate')

    if (!checkbox) {
      return
    }

    checkbox.indeterminate = true
  })()

XhmikosR's avatar
XhmikosR committed
32
33
34
35
36
37
38
39
40
41
42
43
  makeArray(document.querySelectorAll('.js-sidenav-group'))
    .forEach(function (sidenavGroup) {
      var groupHasLinks = Boolean(sidenavGroup.querySelector('li'))
      var groupLink = sidenavGroup.querySelector('a')

      if (groupHasLinks) {
        groupLink.addEventListener('click', function (e) {
          e.preventDefault()
          e.target.parentNode.classList.toggle('active')
        }, true)
      }
    })
Mark Otto's avatar
Mark Otto committed
44

XhmikosR's avatar
XhmikosR committed
45
  // Tooltip and popover demos
46
  makeArray(document.querySelectorAll('.tooltip-demo'))
XhmikosR's avatar
XhmikosR committed
47
48
49
    .forEach(function (tooltip) {
      new bootstrap.Tooltip(tooltip, {
        selector: '[data-toggle="tooltip"]'
Johann-S's avatar
Johann-S committed
50
      })
XhmikosR's avatar
XhmikosR committed
51
    })
Jacob Thornton's avatar
Jacob Thornton committed
52

53
  makeArray(document.querySelectorAll('[data-toggle="popover"]'))
XhmikosR's avatar
XhmikosR committed
54
55
56
    .forEach(function (popover) {
      new bootstrap.Popover(popover)
    })
Johann-S's avatar
Johann-S committed
57

58
  makeArray(document.querySelectorAll('.toast'))
XhmikosR's avatar
XhmikosR committed
59
60
61
    .forEach(function (toastNode) {
      var toast = new bootstrap.Toast(toastNode, {
        autohide: false
Johann-S's avatar
Johann-S committed
62
63
      })

XhmikosR's avatar
XhmikosR committed
64
65
      toast.show()
    })
66

XhmikosR's avatar
XhmikosR committed
67
  // Demos within modals
68
  makeArray(document.querySelectorAll('.tooltip-test'))
XhmikosR's avatar
XhmikosR committed
69
70
71
    .forEach(function (tooltip) {
      new bootstrap.Tooltip(tooltip)
    })
Jacob Thornton's avatar
Jacob Thornton committed
72

73
  makeArray(document.querySelectorAll('.popover-test'))
XhmikosR's avatar
XhmikosR committed
74
75
76
    .forEach(function (popover) {
      new bootstrap.Popover(popover)
    })
77

XhmikosR's avatar
XhmikosR committed
78
  // Indeterminate checkbox example
79
  makeArray(document.querySelectorAll('.bd-example-indeterminate [type="checkbox"]'))
XhmikosR's avatar
XhmikosR committed
80
81
82
    .forEach(function (checkbox) {
      checkbox.indeterminate = true
    })
Mark Otto's avatar
Mark Otto committed
83

XhmikosR's avatar
XhmikosR committed
84
  // Disable empty links in docs examples
85
  makeArray(document.querySelectorAll('.bd-content [href="#"]'))
XhmikosR's avatar
XhmikosR committed
86
87
88
89
90
    .forEach(function (link) {
      link.addEventListener('click', function (e) {
        e.preventDefault()
      })
    })
91

XhmikosR's avatar
XhmikosR committed
92
93
94
95
96
97
  // 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
98

XhmikosR's avatar
XhmikosR committed
99
100
101
      // Update the modal's content.
      var modalTitle = exampleModal.querySelector('.modal-title')
      var modalBodyInput = exampleModal.querySelector('.modal-body input')
102

XhmikosR's avatar
XhmikosR committed
103
104
105
106
107
108
      modalTitle.innerHTML = 'New message to ' + recipient
      modalBodyInput.value = recipient
    })
  }

  // Activate animated progress bar
109
  var btnToggleAnimatedProgress = document.getElementById('btnToggleAnimatedProgress')
110
111
112
113
114
115
  if (btnToggleAnimatedProgress) {
    btnToggleAnimatedProgress.addEventListener('click', function () {
      btnToggleAnimatedProgress.parentNode
        .querySelector('.progress-bar-striped')
        .classList
        .toggle('progress-bar-animated')
XhmikosR's avatar
XhmikosR committed
116
    })
117
  }
Mark Otto's avatar
Mark Otto committed
118

XhmikosR's avatar
XhmikosR committed
119
120
  // 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>'
121
  makeArray(document.querySelectorAll('figure.highlight, div.highlight'))
XhmikosR's avatar
XhmikosR committed
122
123
124
    .forEach(function (element) {
      element.insertAdjacentHTML('beforebegin', btnHtml)
    })
125

126
  makeArray(document.querySelectorAll('.btn-clipboard'))
XhmikosR's avatar
XhmikosR committed
127
128
    .forEach(function (btn) {
      var tooltipBtn = new bootstrap.Tooltip(btn)
129

XhmikosR's avatar
XhmikosR committed
130
131
132
133
134
      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()
135
      })
136
    })
137

XhmikosR's avatar
XhmikosR committed
138
139
140
141
142
  var clipboard = new ClipboardJS('.btn-clipboard', {
    target: function (trigger) {
      return trigger.parentNode.nextElementSibling
    }
  })
143

XhmikosR's avatar
XhmikosR committed
144
  clipboard.on('success', function (e) {
145
    var tooltipBtn = bootstrap.Tooltip.getInstance(e.trigger)
146

147
    e.trigger.setAttribute('data-original-title', 'Copied!')
XhmikosR's avatar
XhmikosR committed
148
    tooltipBtn.show()
149

150
    e.trigger.setAttribute('data-original-title', 'Copy to clipboard')
XhmikosR's avatar
XhmikosR committed
151
152
    e.clearSelection()
  })
153

XhmikosR's avatar
XhmikosR committed
154
155
156
  clipboard.on('error', function (e) {
    var modifierKey = /Mac/i.test(navigator.userAgent) ? '\u2318' : 'Ctrl-'
    var fallbackMsg = 'Press ' + modifierKey + 'C to copy'
157
    var tooltipBtn = bootstrap.Tooltip.getInstance(e.trigger)
158

159
    e.trigger.setAttribute('data-original-title', fallbackMsg)
XhmikosR's avatar
XhmikosR committed
160
    tooltipBtn.show()
Jacob Thornton's avatar
Jacob Thornton committed
161

162
    e.trigger.setAttribute('data-original-title', 'Copy to clipboard')
XhmikosR's avatar
XhmikosR committed
163
  })
164

XhmikosR's avatar
XhmikosR committed
165
166
167
168
  anchors.options = {
    icon: '#'
  }
  anchors.add('.bd-content > h2, .bd-content > h3, .bd-content > h4, .bd-content > h5')
169

XhmikosR's avatar
XhmikosR committed
170
  // Wrap inner
171
  makeArray(document.querySelectorAll('.bd-content > h2, .bd-content > h3, .bd-content > h4, .bd-content > h5'))
XhmikosR's avatar
XhmikosR committed
172
173
174
175
176
    .forEach(function (hEl) {
      hEl.innerHTML = '<span class="bd-content-title">' + hEl.innerHTML + '</span>'
    })

  bsCustomFileInput.init()
XhmikosR's avatar
XhmikosR committed
177
})()