1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-20 04:11:39 +02:00

Add js-docs shortcode to ensure consistency between doc and js code (#38316)

Co-authored-by: XhmikosR <xhmikosr@gmail.com>
This commit is contained in:
Hannah Issermann
2023-03-27 11:10:25 +02:00
committed by GitHub
parent 31f93e2aff
commit 06f7c3b6c7
7 changed files with 56 additions and 92 deletions

View File

@@ -38,28 +38,7 @@ Click the button below to show an alert (hidden with inline styles to start), th
We use the following JavaScript to trigger our live alert demo:
```js
const alertPlaceholder = document.getElementById('liveAlertPlaceholder')
const alert = (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)
}
const alertTrigger = document.getElementById('liveAlertBtn')
if (alertTrigger) {
alertTrigger.addEventListener('click', () => {
alert('Nice, you triggered this alert message!', 'success')
})
}
```
{{< js-docs name="live-alert" file="site/assets/js/snippets.js" >}}
### Link color

View File

@@ -481,24 +481,7 @@ Below is a live demo followed by example HTML and JavaScript. For more informati
</div>
{{< /example >}}
```js
const exampleModal = document.getElementById('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')
// If necessary, you could initiate an Ajax request here
// and then do the updating in a callback.
//
// 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
})
```
{{< js-docs name="varying-modal-content" file="site/assets/js/snippets.js" >}}
### Toggle between modals

View File

@@ -87,17 +87,7 @@ Click the button below to show a toast (positioned with our utilities in the low
We use the following JavaScript to trigger our live toast demo:
```js
const toastTrigger = document.getElementById('liveToastBtn')
const toastLiveExample = document.getElementById('liveToast')
if (toastTrigger) {
const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toastLiveExample)
toastTrigger.addEventListener('click', () => {
toastBootstrap.show()
})
}
```
{{< js-docs name="live-toast" file="site/assets/js/snippets.js" >}}
### Translucent