diff options
| author | Tiger Oakes <[email protected]> | 2022-04-12 08:07:25 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-04-12 18:07:25 +0300 |
| commit | fe257823ecca31cf5e582e9b8380a0ad0204075e (patch) | |
| tree | 1ebe321ce3bd30686cbd49a58272d8845d07a673 /site/content/docs/5.1 | |
| parent | f6cb4b64b57f751df4563fe80e0f4eb4c19fb8e4 (diff) | |
| download | bootstrap-fe257823ecca31cf5e582e9b8380a0ad0204075e.tar.xz bootstrap-fe257823ecca31cf5e582e9b8380a0ad0204075e.zip | |
Use Babel and ES6 in docs JS files (#31607)
* Pass docs js through Babel
* Use ES6 in docs js
* Only run babel on src files
* Allow babel in Hugo
* Update scripts.html
* Inherit from the root .eslintrc.json
* Use `Array.from`
* Drop Babel from docs
* Prefer template
* replace IIFE with arrow functions
Co-authored-by: XhmikosR <[email protected]>
Co-authored-by: GeoSot <[email protected]>
Diffstat (limited to 'site/content/docs/5.1')
6 files changed, 34 insertions, 35 deletions
diff --git a/site/content/docs/5.1/examples/cheatsheet/cheatsheet.js b/site/content/docs/5.1/examples/cheatsheet/cheatsheet.js index 0a50258b9..e25a89e75 100644 --- a/site/content/docs/5.1/examples/cheatsheet/cheatsheet.js +++ b/site/content/docs/5.1/examples/cheatsheet/cheatsheet.js @@ -1,24 +1,24 @@ /* global bootstrap: false */ -(function () { +(() => { 'use strict' // Tooltip and popover demos document.querySelectorAll('.tooltip-demo') - .forEach(function (tooltip) { + .forEach(tooltip => { new bootstrap.Tooltip(tooltip, { selector: '[data-bs-toggle="tooltip"]' }) }) document.querySelectorAll('[data-bs-toggle="popover"]') - .forEach(function (popover) { + .forEach(popover => { new bootstrap.Popover(popover) }) document.querySelectorAll('.toast') - .forEach(function (toastNode) { - var toast = new bootstrap.Toast(toastNode, { + .forEach(toastNode => { + const toast = new bootstrap.Toast(toastNode, { autohide: false }) @@ -27,27 +27,27 @@ // Disable empty links and submit buttons document.querySelectorAll('[href="#"], [type="submit"]') - .forEach(function (link) { - link.addEventListener('click', function (event) { + .forEach(link => { + link.addEventListener('click', event => { event.preventDefault() }) }) function setActiveItem() { - var hash = window.location.hash + const { hash } = window.location if (hash === '') { return } - var link = document.querySelector('.bd-aside a[href="' + hash + '"]') + const link = document.querySelector(`.bd-aside a[href="${hash}"]`) if (!link) { return } - var active = document.querySelector('.bd-aside .active') - var parent = link.parentNode.parentNode.previousElementSibling + const active = document.querySelector('.bd-aside .active') + const parent = link.parentNode.parentNode.previousElementSibling link.classList.add('active') @@ -59,7 +59,7 @@ return } - var expanded = active.parentNode.parentNode.previousElementSibling + const expanded = active.parentNode.parentNode.previousElementSibling active.classList.remove('active') diff --git a/site/content/docs/5.1/examples/checkout/form-validation.js b/site/content/docs/5.1/examples/checkout/form-validation.js index f8fd583de..30ea0aa6b 100644 --- a/site/content/docs/5.1/examples/checkout/form-validation.js +++ b/site/content/docs/5.1/examples/checkout/form-validation.js @@ -1,20 +1,19 @@ // Example starter JavaScript for disabling form submissions if there are invalid fields -(function () { +(() => { 'use strict' // Fetch all the forms we want to apply custom Bootstrap validation styles to - var forms = document.querySelectorAll('.needs-validation') + const forms = document.querySelectorAll('.needs-validation') // Loop over them and prevent submission - Array.prototype.slice.call(forms) - .forEach(function (form) { - form.addEventListener('submit', function (event) { - if (!form.checkValidity()) { - event.preventDefault() - event.stopPropagation() - } + Array.from(forms).forEach(form => { + form.addEventListener('submit', event => { + if (!form.checkValidity()) { + event.preventDefault() + event.stopPropagation() + } - form.classList.add('was-validated') - }, false) - }) + form.classList.add('was-validated') + }, false) + }) })() diff --git a/site/content/docs/5.1/examples/dashboard-rtl/dashboard.js b/site/content/docs/5.1/examples/dashboard-rtl/dashboard.js index 7831fa9d0..96e0895bf 100644 --- a/site/content/docs/5.1/examples/dashboard-rtl/dashboard.js +++ b/site/content/docs/5.1/examples/dashboard-rtl/dashboard.js @@ -1,14 +1,14 @@ /* globals Chart:false, feather:false */ -(function () { +(() => { 'use strict' feather.replace({ 'aria-hidden': 'true' }) // Graphs - var ctx = document.getElementById('myChart') + const ctx = document.getElementById('myChart') // eslint-disable-next-line no-unused-vars - var myChart = new Chart(ctx, { + const myChart = new Chart(ctx, { type: 'line', data: { labels: [ diff --git a/site/content/docs/5.1/examples/dashboard/dashboard.js b/site/content/docs/5.1/examples/dashboard/dashboard.js index 7c2402ae2..e1379758b 100644 --- a/site/content/docs/5.1/examples/dashboard/dashboard.js +++ b/site/content/docs/5.1/examples/dashboard/dashboard.js @@ -1,14 +1,14 @@ /* globals Chart:false, feather:false */ -(function () { +(() => { 'use strict' feather.replace({ 'aria-hidden': 'true' }) // Graphs - var ctx = document.getElementById('myChart') + const ctx = document.getElementById('myChart') // eslint-disable-next-line no-unused-vars - var myChart = new Chart(ctx, { + const myChart = new Chart(ctx, { type: 'line', data: { labels: [ diff --git a/site/content/docs/5.1/examples/offcanvas-navbar/offcanvas.js b/site/content/docs/5.1/examples/offcanvas-navbar/offcanvas.js index 91103b1c4..b97a17164 100644 --- a/site/content/docs/5.1/examples/offcanvas-navbar/offcanvas.js +++ b/site/content/docs/5.1/examples/offcanvas-navbar/offcanvas.js @@ -1,7 +1,7 @@ -(function () { +(() => { 'use strict' - document.querySelector('#navbarSideCollapse').addEventListener('click', function () { + document.querySelector('#navbarSideCollapse').addEventListener('click', () => { document.querySelector('.offcanvas-collapse').classList.toggle('open') }) })() diff --git a/site/content/docs/5.1/examples/sidebars/sidebars.js b/site/content/docs/5.1/examples/sidebars/sidebars.js index d00bc0db1..4075f1f15 100644 --- a/site/content/docs/5.1/examples/sidebars/sidebars.js +++ b/site/content/docs/5.1/examples/sidebars/sidebars.js @@ -1,8 +1,8 @@ /* global bootstrap: false */ -(function () { +(() => { 'use strict' - var tooltipTriggerList = Array.prototype.slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')) - tooltipTriggerList.forEach(function (tooltipTriggerEl) { + const tooltipTriggerList = Array.from(document.querySelectorAll('[data-bs-toggle="tooltip"]')) + tooltipTriggerList.forEach(tooltipTriggerEl => { new bootstrap.Tooltip(tooltipTriggerEl) }) })() |
