0
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-02-28 00:54:30 +01:00
Bootstrap/site/docs/4.3/assets/js/src/application.js

159 lines
5.7 KiB
JavaScript
Raw Normal View History

2015-08-12 19:59:55 -07:00
// NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT
// IT'S ALL JUST JUNK FOR OUR DOCS!
// ++++++++++++++++++++++++++++++++++++++++++
/*!
* JavaScript for Bootstrap's docs (https://getbootstrap.com/)
2019-01-08 08:05:26 +02:00
* Copyright 2011-2019 The Bootstrap Authors
* Copyright 2011-2019 Twitter, Inc.
* Licensed under the Creative Commons Attribution 3.0 Unported License.
* For details, see https://creativecommons.org/licenses/by/3.0/.
2015-08-12 19:59:55 -07:00
*/
2018-07-19 19:48:52 +03:00
/* global ClipboardJS: false, anchors: false, bootstrap: false, bsCustomFileInput: false */
2015-08-12 19:59:55 -07:00
2018-07-19 19:48:52 +03:00
(function () {
'use strict'
2015-08-12 19:59:55 -07:00
2018-07-19 19:48:52 +03:00
document.addEventListener('DOMContentLoaded', function () {
2015-08-12 19:59:55 -07:00
// Tooltip and popover demos
2018-09-14 14:27:30 +02:00
var tooltipDemoList = [].slice.call(document.querySelectorAll('.tooltip-demo'))
2018-07-19 19:48:52 +03:00
tooltipDemoList.forEach(function (tooltip) {
new bootstrap.Tooltip(tooltip, {
selector: '[data-toggle="tooltip"]'
})
})
2018-09-14 14:27:30 +02:00
var popoverList = [].slice.call(document.querySelectorAll('[data-toggle="popover"]'))
2018-07-19 19:48:52 +03:00
popoverList.forEach(function (popover) {
new bootstrap.Popover(popover)
2015-08-12 19:59:55 -07:00
})
2018-08-23 21:06:35 +02:00
$('.toast')
.toast({
autohide: false
})
.toast('show')
2015-08-12 19:59:55 -07:00
// Demos within modals
2018-09-14 14:27:30 +02:00
var tooltipTestList = [].slice.call(document.querySelectorAll('.tooltip-test'))
2018-07-19 19:48:52 +03:00
tooltipTestList.forEach(function (tooltip) {
new bootstrap.Tooltip(tooltip)
})
2018-09-14 14:27:30 +02:00
var popoverTestList = [].slice.call(document.querySelectorAll('.popover-test'))
2018-07-19 19:48:52 +03:00
popoverTestList.forEach(function (popover) {
new bootstrap.Popover(popover)
})
2015-08-12 19:59:55 -07:00
// Indeterminate checkbox example
2018-09-14 14:27:30 +02:00
var indeterminateCheckboxList = [].slice.call(document.querySelectorAll('.bd-example-indeterminate [type="checkbox"]'))
2018-07-19 19:48:52 +03:00
indeterminateCheckboxList.forEach(function (checkbox) {
checkbox.indeterminate = true
})
2015-08-17 21:21:39 -07:00
// Disable empty links in docs examples
2018-09-14 14:27:30 +02:00
var emptyLinkList = [].slice.call(document.querySelectorAll('.bd-content [href="#"]'))
2018-07-19 19:48:52 +03:00
emptyLinkList.forEach(function (link) {
link.addEventListener('click', function (e) {
e.preventDefault()
})
2015-08-17 21:21:39 -07:00
})
// Modal relatedTarget demo
2018-07-19 19:48:52 +03:00
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
})
}
2016-12-29 15:50:18 -08:00
// Activate animated progress bar
2018-09-14 14:27:30 +02:00
var animatedProgressBarList = [].slice.call(document.querySelectorAll('.bd-toggle-animated-progress > .progress-bar-striped'))
2018-07-19 19:48:52 +03:00
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')
}
})
2016-12-29 15:50:18 -08:00
})
2015-08-12 19:59:55 -07:00
// Insert copy to clipboard button before .highlight
2018-07-19 19:48:52 +03:00
var btnHtml = '<div class="bd-clipboard"><button type="button" class="btn-clipboard" title="Copy to clipboard">Copy</button></div>'
2018-09-14 14:27:30 +02:00
var highList = [].slice.call(document.querySelectorAll('figure.highlight, div.highlight'))
highList.forEach(function (element) {
2018-07-19 19:48:52 +03:00
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()
})
2015-08-12 19:59:55 -07:00
})
2018-03-14 01:22:38 +02:00
var clipboard = new ClipboardJS('.btn-clipboard', {
target: function (trigger) {
return trigger.parentNode.nextElementSibling
}
})
clipboard.on('success', function (e) {
2018-07-19 19:48:52 +03:00
var tooltipBtn = bootstrap.Tooltip._getInstance(e.trigger)
e.trigger.setAttribute('title', 'Copied!')
tooltipBtn._fixTitle()
tooltipBtn.show()
2018-07-19 19:48:52 +03:00
e.trigger.setAttribute('title', 'Copy to clipboard')
tooltipBtn._fixTitle()
e.clearSelection()
})
clipboard.on('error', function (e) {
var modifierKey = /Mac/i.test(navigator.userAgent) ? '\u2318' : 'Ctrl-'
var fallbackMsg = 'Press ' + modifierKey + 'C to copy'
2018-07-19 19:48:52 +03:00
var tooltipBtn = bootstrap.Tooltip._getInstance(e.trigger)
e.trigger.setAttribute('title', fallbackMsg)
tooltipBtn._fixTitle()
tooltipBtn.show()
2018-07-19 19:48:52 +03:00
e.trigger.setAttribute('title', 'Copy to clipboard')
tooltipBtn._fixTitle()
})
2015-08-12 19:59:55 -07:00
anchors.options = {
icon: '#'
}
anchors.add('.bd-content > h2, .bd-content > h3, .bd-content > h4, .bd-content > h5')
2018-07-19 19:48:52 +03:00
// 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)
})
bsCustomFileInput.init()
2015-08-12 19:59:55 -07:00
})
2018-07-19 19:48:52 +03:00
}())