aboutsummaryrefslogtreecommitdiff
path: root/site/content/docs
diff options
context:
space:
mode:
authorHannah Issermann <[email protected]>2023-03-27 11:10:25 +0200
committerGitHub <[email protected]>2023-03-27 12:10:25 +0300
commit06f7c3b6c73580cd05b131bdab4d156a864d418c (patch)
tree910759161d3155be5559f1a4d331a0ad40c1674b /site/content/docs
parent31f93e2aff5050877f499faca05dc4341942a40a (diff)
downloadbootstrap-06f7c3b6c73580cd05b131bdab4d156a864d418c.tar.xz
bootstrap-06f7c3b6c73580cd05b131bdab4d156a864d418c.zip
Add js-docs shortcode to ensure consistency between doc and js code (#38316)
Co-authored-by: XhmikosR <[email protected]>
Diffstat (limited to 'site/content/docs')
-rw-r--r--site/content/docs/5.3/components/alerts.md23
-rw-r--r--site/content/docs/5.3/components/modal.md19
-rw-r--r--site/content/docs/5.3/components/toasts.md12
-rw-r--r--site/content/docs/5.3/getting-started/javascript.md37
4 files changed, 4 insertions, 87 deletions
diff --git a/site/content/docs/5.3/components/alerts.md b/site/content/docs/5.3/components/alerts.md
index 7ea5b9b42..b6e78ea42 100644
--- a/site/content/docs/5.3/components/alerts.md
+++ b/site/content/docs/5.3/components/alerts.md
@@ -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
diff --git a/site/content/docs/5.3/components/modal.md b/site/content/docs/5.3/components/modal.md
index f556ed9f8..55272b33f 100644
--- a/site/content/docs/5.3/components/modal.md
+++ b/site/content/docs/5.3/components/modal.md
@@ -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
diff --git a/site/content/docs/5.3/components/toasts.md b/site/content/docs/5.3/components/toasts.md
index d882fc04b..a7d1cb713 100644
--- a/site/content/docs/5.3/components/toasts.md
+++ b/site/content/docs/5.3/components/toasts.md
@@ -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
diff --git a/site/content/docs/5.3/getting-started/javascript.md b/site/content/docs/5.3/getting-started/javascript.md
index 827cd2199..739e9ef63 100644
--- a/site/content/docs/5.3/getting-started/javascript.md
+++ b/site/content/docs/5.3/getting-started/javascript.md
@@ -231,42 +231,7 @@ Tooltips and Popovers use our built-in sanitizer to sanitize options which accep
The default `allowList` value is the following:
-```js
-const ARIA_ATTRIBUTE_PATTERN = /^aria-[\w-]*$/i
-const DefaultAllowlist = {
- // Global attributes allowed on any supplied element below.
- '*': ['class', 'dir', 'id', 'lang', 'role', ARIA_ATTRIBUTE_PATTERN],
- a: ['target', 'href', 'title', 'rel'],
- area: [],
- b: [],
- br: [],
- col: [],
- code: [],
- div: [],
- em: [],
- hr: [],
- h1: [],
- h2: [],
- h3: [],
- h4: [],
- h5: [],
- h6: [],
- i: [],
- img: ['src', 'srcset', 'alt', 'title', 'width', 'height'],
- li: [],
- ol: [],
- p: [],
- pre: [],
- s: [],
- small: [],
- span: [],
- sub: [],
- sup: [],
- strong: [],
- u: [],
- ul: []
-}
-```
+{{< js-docs name="allow-list" file="js/src/util/sanitizer.js" >}}
If you want to add new values to this default `allowList` you can do the following: