2022-05-26 23:29:08 +02:00
|
|
|
// NOTICE!!! Initially embedded in our docs this JavaScript
|
|
|
|
// file contains elements that can help you create reproducible
|
|
|
|
// use cases in StackBlitz for instance.
|
|
|
|
// In a real project please adapt this content to your needs.
|
2022-05-04 00:48:30 +02:00
|
|
|
// ++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* JavaScript for Bootstrap's docs (https://getbootstrap.com/)
|
2023-01-02 01:30:53 +01:00
|
|
|
* Copyright 2011-2023 The Bootstrap Authors
|
2022-05-04 00:48:30 +02:00
|
|
|
* Licensed under the Creative Commons Attribution 3.0 Unported License.
|
|
|
|
* For details, see https://creativecommons.org/licenses/by/3.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* global bootstrap: false */
|
|
|
|
|
|
|
|
(() => {
|
|
|
|
'use strict'
|
|
|
|
|
2022-05-26 23:29:08 +02:00
|
|
|
// --------
|
|
|
|
// Tooltips
|
|
|
|
// --------
|
2022-07-17 20:54:34 +02:00
|
|
|
// Instantiate all tooltips in a docs or StackBlitz page
|
2022-05-04 10:05:15 +02:00
|
|
|
document.querySelectorAll('[data-bs-toggle="tooltip"]')
|
2022-05-04 00:48:30 +02:00
|
|
|
.forEach(tooltip => {
|
2022-05-04 10:05:15 +02:00
|
|
|
new bootstrap.Tooltip(tooltip)
|
2022-05-04 00:48:30 +02:00
|
|
|
})
|
|
|
|
|
2022-05-26 23:29:08 +02:00
|
|
|
// --------
|
|
|
|
// Popovers
|
|
|
|
// --------
|
2022-07-17 20:54:34 +02:00
|
|
|
// Instantiate all popovers in a docs or StackBlitz page
|
2022-05-04 00:48:30 +02:00
|
|
|
document.querySelectorAll('[data-bs-toggle="popover"]')
|
|
|
|
.forEach(popover => {
|
|
|
|
new bootstrap.Popover(popover)
|
|
|
|
})
|
|
|
|
|
2022-05-26 23:29:08 +02:00
|
|
|
// -------------------------------
|
|
|
|
// Toasts
|
|
|
|
// -------------------------------
|
|
|
|
// Used by 'Placement' example in docs or StackBlitz
|
2022-05-04 00:48:30 +02:00
|
|
|
const toastPlacement = document.getElementById('toastPlacement')
|
|
|
|
if (toastPlacement) {
|
|
|
|
document.getElementById('selectToastPlacement').addEventListener('change', function () {
|
|
|
|
if (!toastPlacement.dataset.originalClass) {
|
|
|
|
toastPlacement.dataset.originalClass = toastPlacement.className
|
|
|
|
}
|
|
|
|
|
|
|
|
toastPlacement.className = `${toastPlacement.dataset.originalClass} ${this.value}`
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-07-17 20:54:34 +02:00
|
|
|
// Instantiate all toasts in a docs page only
|
2022-05-04 00:48:30 +02:00
|
|
|
document.querySelectorAll('.bd-example .toast')
|
|
|
|
.forEach(toastNode => {
|
|
|
|
const toast = new bootstrap.Toast(toastNode, {
|
|
|
|
autohide: false
|
|
|
|
})
|
|
|
|
|
|
|
|
toast.show()
|
|
|
|
})
|
|
|
|
|
2022-07-17 20:54:34 +02:00
|
|
|
// Instantiate all toasts in a docs page only
|
2022-05-04 00:48:30 +02:00
|
|
|
const toastTrigger = document.getElementById('liveToastBtn')
|
|
|
|
const toastLiveExample = document.getElementById('liveToast')
|
|
|
|
if (toastTrigger) {
|
|
|
|
toastTrigger.addEventListener('click', () => {
|
|
|
|
const toast = new bootstrap.Toast(toastLiveExample)
|
|
|
|
|
|
|
|
toast.show()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-05-26 23:29:08 +02:00
|
|
|
// -------------------------------
|
|
|
|
// Alerts
|
|
|
|
// -------------------------------
|
|
|
|
// Used in 'Show live toast' example in docs or StackBlitz
|
2022-05-04 00:48:30 +02:00
|
|
|
const alertPlaceholder = document.getElementById('liveAlertPlaceholder')
|
|
|
|
const alertTrigger = document.getElementById('liveAlertBtn')
|
|
|
|
|
|
|
|
const appendAlert = (message, type) => {
|
|
|
|
const wrapper = document.createElement('div')
|
|
|
|
wrapper.innerHTML = [
|
|
|
|
`<div class="alert alert-${type} alert-dismissible" role="alert">`,
|
|
|
|
` <div>${message}</div>`,
|
|
|
|
' <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>',
|
|
|
|
'</div>'
|
|
|
|
].join('')
|
|
|
|
|
|
|
|
alertPlaceholder.append(wrapper)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alertTrigger) {
|
|
|
|
alertTrigger.addEventListener('click', () => {
|
|
|
|
appendAlert('Nice, you triggered this alert message!', 'success')
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
Docs: rewrite/reorganise carousel docs page (#37354)
* Instantiate/initialize all non-autoplaying carousels in docs pages
* Rewrite/reorganise carousel docs page
* start with static/non-autoplaying examples
* explicitly mention that carousels currently need to be manually initialized
* split out and explain autoplaying and the weird "autoplay after first interaction" behaviour, as well as the pause on hover/focus
* Add callout about autoplaying and accessibility
* Don't have the dark variant example autoplay
* Add "autoplaying" to cspell custom dictionary
* Tweal wording, move Page Visibility API to autoplay section
* Tweak explanation for methods, add line break in js code for consistency with last code block on the page
* Tweak method descriptions
* Tweak headings (plural "carousels")
* Move some paragraphs out of intro and into basic example, reword the nested and accessibility paragraph
* Tweak warning about `.active` slide
* Tweak callout wording
* Further prose tweaks
move the sentence about not double-initialising autoplaying carousels to the callout right at the top
instead of talking about `data-bs...` attributes, talk about the "option" instead, as authors may be setting these not via data attributes, but at instatiation time with options in the constructor
remove the incorrect statement about pausing when keyboard focus is in the carousel
* Instantiate/initialize all non-autoplaying carousels in docs pages
* Rewrite/reorganise carousel docs page
* start with static/non-autoplaying examples
* explicitly mention that carousels currently need to be manually initialized
* split out and explain autoplaying and the weird "autoplay after first interaction" behaviour, as well as the pause on hover/focus
* Add callout about autoplaying and accessibility
* Don't have the dark variant example autoplay
* Add "autoplaying" to cspell custom dictionary
* Tweal wording, move Page Visibility API to autoplay section
* Tweak explanation for methods, add line break in js code for consistency with last code block on the page
* Tweak method descriptions
* Tweak headings (plural "carousels")
* Move some paragraphs out of intro and into basic example, reword the nested and accessibility paragraph
* Tweak warning about `.active` slide
* Tweak callout wording
* Further prose tweaks
move the sentence about not double-initialising autoplaying carousels to the callout right at the top
instead of talking about `data-bs...` attributes, talk about the "option" instead, as authors may be setting these not via data attributes, but at instatiation time with options in the constructor
remove the incorrect statement about pausing when keyboard focus is in the carousel
* Fix relative link
* Update site/assets/js/snippets.js
Co-authored-by: GeoSot <geo.sotis@gmail.com>
* Fix snippet.js
* Tweak content organisation just a bit
Co-authored-by: GeoSot <geo.sotis@gmail.com>
Co-authored-by: Julien Déramond <juderamond@gmail.com>
Co-authored-by: Julien Déramond <julien.deramond@orange.com>
Co-authored-by: Mark Otto <markdotto@gmail.com>
2022-11-29 08:20:35 +01:00
|
|
|
// --------
|
|
|
|
// Carousels
|
|
|
|
// --------
|
|
|
|
// Instantiate all non-autoplaying carousels in a docs or StackBlitz page
|
|
|
|
document.querySelectorAll('.carousel:not([data-bs-ride="carousel"])')
|
|
|
|
.forEach(carousel => {
|
|
|
|
bootstrap.Carousel.getOrCreateInstance(carousel)
|
|
|
|
})
|
|
|
|
|
2022-05-26 23:29:08 +02:00
|
|
|
// -------------------------------
|
|
|
|
// Checks & Radios
|
|
|
|
// -------------------------------
|
|
|
|
// Indeterminate checkbox example in docs and StackBlitz
|
2022-05-04 00:48:30 +02:00
|
|
|
document.querySelectorAll('.bd-example-indeterminate [type="checkbox"]')
|
|
|
|
.forEach(checkbox => {
|
2022-07-06 07:43:38 +02:00
|
|
|
if (checkbox.id.includes('Indeterminate')) {
|
|
|
|
checkbox.indeterminate = true
|
|
|
|
}
|
2022-05-04 00:48:30 +02:00
|
|
|
})
|
|
|
|
|
2022-05-26 23:29:08 +02:00
|
|
|
// -------------------------------
|
|
|
|
// Links
|
|
|
|
// -------------------------------
|
|
|
|
// Disable empty links in docs examples only
|
2022-05-04 00:48:30 +02:00
|
|
|
document.querySelectorAll('.bd-content [href="#"]')
|
|
|
|
.forEach(link => {
|
|
|
|
link.addEventListener('click', event => {
|
|
|
|
event.preventDefault()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-05-26 23:29:08 +02:00
|
|
|
// -------------------------------
|
|
|
|
// Modal
|
|
|
|
// -------------------------------
|
|
|
|
// Modal 'Varying modal content' example in docs and StackBlitz
|
2022-05-04 00:48:30 +02:00
|
|
|
const exampleModal = document.getElementById('exampleModal')
|
|
|
|
if (exampleModal) {
|
|
|
|
exampleModal.addEventListener('show.bs.modal', event => {
|
|
|
|
// Button that triggered the modal
|
|
|
|
const button = event.relatedTarget
|
|
|
|
// Extract info from data-bs-* attributes
|
|
|
|
const recipient = button.getAttribute('data-bs-whatever')
|
|
|
|
|
|
|
|
// Update the modal's content.
|
|
|
|
const modalTitle = exampleModal.querySelector('.modal-title')
|
|
|
|
const modalBodyInput = exampleModal.querySelector('.modal-body input')
|
|
|
|
|
|
|
|
modalTitle.textContent = `New message to ${recipient}`
|
|
|
|
modalBodyInput.value = recipient
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-05-26 23:29:08 +02:00
|
|
|
// -------------------------------
|
|
|
|
// Offcanvas
|
|
|
|
// -------------------------------
|
|
|
|
// 'Offcanvas components' example in docs only
|
2022-06-15 16:41:39 +02:00
|
|
|
const myOffcanvas = document.querySelectorAll('.bd-example-offcanvas .offcanvas')
|
2022-05-04 00:48:30 +02:00
|
|
|
if (myOffcanvas) {
|
2022-06-15 16:41:39 +02:00
|
|
|
myOffcanvas.forEach(offcanvas => {
|
|
|
|
offcanvas.addEventListener('show.bs.offcanvas', event => {
|
|
|
|
event.preventDefault()
|
|
|
|
}, false)
|
|
|
|
})
|
2022-05-04 00:48:30 +02:00
|
|
|
}
|
|
|
|
})()
|