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

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

XhmikosR's avatar
XhmikosR committed
26
27
28
29
  bootstrap.Util.makeArray(document.querySelectorAll('[data-toggle="popover"]'))
    .forEach(function (popover) {
      new bootstrap.Popover(popover)
    })
Johann-S's avatar
Johann-S committed
30

XhmikosR's avatar
XhmikosR committed
31
32
33
34
  bootstrap.Util.makeArray(document.querySelectorAll('.toast'))
    .forEach(function (toastNode) {
      var toast = new bootstrap.Toast(toastNode, {
        autohide: false
Johann-S's avatar
Johann-S committed
35
36
      })

XhmikosR's avatar
XhmikosR committed
37
38
      toast.show()
    })
39

XhmikosR's avatar
XhmikosR committed
40
41
42
43
44
  // Demos within modals
  bootstrap.Util.makeArray(document.querySelectorAll('.tooltip-test'))
    .forEach(function (tooltip) {
      new bootstrap.Tooltip(tooltip)
    })
Jacob Thornton's avatar
Jacob Thornton committed
45

XhmikosR's avatar
XhmikosR committed
46
47
48
49
  bootstrap.Util.makeArray(document.querySelectorAll('.popover-test'))
    .forEach(function (popover) {
      new bootstrap.Popover(popover)
    })
50

XhmikosR's avatar
XhmikosR committed
51
52
53
54
55
  // Indeterminate checkbox example
  bootstrap.Util.makeArray(document.querySelectorAll('.bd-example-indeterminate [type="checkbox"]'))
    .forEach(function (checkbox) {
      checkbox.indeterminate = true
    })
Mark Otto's avatar
Mark Otto committed
56

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

XhmikosR's avatar
XhmikosR committed
65
66
67
68
69
70
  // 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
71

XhmikosR's avatar
XhmikosR committed
72
73
74
      // Update the modal's content.
      var modalTitle = exampleModal.querySelector('.modal-title')
      var modalBodyInput = exampleModal.querySelector('.modal-body input')
75

XhmikosR's avatar
XhmikosR committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
      modalTitle.innerHTML = 'New message to ' + recipient
      modalBodyInput.value = recipient
    })
  }

  // Activate animated progress bar
  bootstrap.Util.makeArray(document.querySelectorAll('.bd-toggle-animated-progress > .progress-bar-striped'))
    .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')
        }
90
      })
XhmikosR's avatar
XhmikosR committed
91
    })
Mark Otto's avatar
Mark Otto committed
92

XhmikosR's avatar
XhmikosR committed
93
94
95
96
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>'
  bootstrap.Util.makeArray(document.querySelectorAll('figure.highlight, div.highlight'))
    .forEach(function (element) {
      element.insertAdjacentHTML('beforebegin', btnHtml)
    })
99

XhmikosR's avatar
XhmikosR committed
100
101
102
  bootstrap.Util.makeArray(document.querySelectorAll('.btn-clipboard'))
    .forEach(function (btn) {
      var tooltipBtn = new bootstrap.Tooltip(btn)
103

XhmikosR's avatar
XhmikosR committed
104
105
106
107
108
      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()
109
      })
110
    })
111

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

XhmikosR's avatar
XhmikosR committed
118
119
  clipboard.on('success', function (e) {
    var tooltipBtn = bootstrap.Tooltip._getInstance(e.trigger)
120

XhmikosR's avatar
XhmikosR committed
121
122
123
    e.trigger.setAttribute('title', 'Copied!')
    tooltipBtn._fixTitle()
    tooltipBtn.show()
124

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

XhmikosR's avatar
XhmikosR committed
130
131
132
133
  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)
134

XhmikosR's avatar
XhmikosR committed
135
136
137
    e.trigger.setAttribute('title', fallbackMsg)
    tooltipBtn._fixTitle()
    tooltipBtn.show()
Jacob Thornton's avatar
Jacob Thornton committed
138

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

XhmikosR's avatar
XhmikosR committed
143
144
145
146
  anchors.options = {
    icon: '#'
  }
  anchors.add('.bd-content > h2, .bd-content > h3, .bd-content > h4, .bd-content > h5')
147

XhmikosR's avatar
XhmikosR committed
148
149
150
151
152
153
154
  // Wrap inner
  bootstrap.Util.makeArray(document.querySelectorAll('.bd-content > h2, .bd-content > h3, .bd-content > h4, .bd-content > h5'))
    .forEach(function (hEl) {
      hEl.innerHTML = '<span class="bd-content-title">' + hEl.innerHTML + '</span>'
    })

  bsCustomFileInput.init()
155
}())