From 00d45b11e7088981d52027df65bebf7f5e4c6050 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Tue, 26 Apr 2022 19:38:41 +0300 Subject: Docs: update documentation js examples, using es6 (#36203) * Docs: update components documentation using es6 * Docs: update js blocks around docs, using es6 * Docs: update components documentation using es6 * Test linter --- .../content/docs/5.1/getting-started/javascript.md | 42 +++++++++++----------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'site/content/docs/5.1/getting-started/javascript.md') diff --git a/site/content/docs/5.1/getting-started/javascript.md b/site/content/docs/5.1/getting-started/javascript.md index 8ee428921..5e4321034 100644 --- a/site/content/docs/5.1/getting-started/javascript.md +++ b/site/content/docs/5.1/getting-started/javascript.md @@ -59,9 +59,9 @@ Bootstrap provides custom events for most plugins' unique actions. Generally, th All infinitive events provide [`preventDefault()`](https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault) functionality. This provides the ability to stop the execution of an action before it starts. Returning false from an event handler will also automatically call `preventDefault()`. ```js -var myModal = document.getElementById('myModal') +const myModal = document.getElementById('myModal') -myModal.addEventListener('show.bs.modal', function (event) { +myModal.addEventListener('show.bs.modal', event => { if (!data) { return event.preventDefault() // stops modal from being shown } @@ -74,7 +74,7 @@ myModal.addEventListener('show.bs.modal', function (event) { Bootstrap will detect jQuery if `jQuery` is present in the `window` object and there is no `data-bs-no-jquery` attribute set on ``. If jQuery is found, Bootstrap will emit events thanks to jQuery's event system. So if you want to listen to Bootstrap's events, you'll have to use the jQuery methods (`.on`, `.one`) instead of `addEventListener`. ```js -$('#myTab a').on('shown.bs.tab', function () { +$('#myTab a').on('shown.bs.tab', () => { // do something... }) ``` @@ -85,10 +85,10 @@ $('#myTab a').on('shown.bs.tab', function () { All constructors accept an optional options object or nothing (which initiates a plugin with its default behavior): ```js -var myModalEl = document.getElementById('myModal') +const myModalEl = document.getElementById('myModal') -var modal = new bootstrap.Modal(myModalEl) // initialized with defaults -var modal = new bootstrap.Modal(myModalEl, { keyboard: false }) // initialized with no keyboard +const modal = new bootstrap.Modal(myModalEl) // initialized with defaults +const modal1 = new bootstrap.Modal(myModalEl, { keyboard: false }) // initialized with no keyboard ``` If you'd like to get a particular plugin instance, each plugin exposes a `getInstance` method. In order to retrieve it directly from an element, do this: `bootstrap.Popover.getInstance(myPopoverEl)`. @@ -98,8 +98,8 @@ If you'd like to get a particular plugin instance, each plugin exposes a `getIns You can also use a CSS selector as the first argument instead of a DOM element to initialize the plugin. Currently the element for the plugin is found by the `querySelector` method since our plugins support a single element only. ```js -var modal = new bootstrap.Modal('#myModal') -var dropdown = new bootstrap.Dropdown('[data-bs-toggle="dropdown"]') +const modal = new bootstrap.Modal('#myModal') +const dropdown = new bootstrap.Dropdown('[data-bs-toggle="dropdown"]') ``` ### Asynchronous functions and transitions @@ -109,9 +109,9 @@ All programmatic API methods are **asynchronous** and return to the caller once In order to execute an action once the transition is complete, you can listen to the corresponding event. ```js -var myCollapseEl = document.getElementById('myCollapse') +const myCollapseEl = document.getElementById('myCollapse') -myCollapseEl.addEventListener('shown.bs.collapse', function (event) { +myCollapseEl.addEventListener('shown.bs.collapse', event => { // Action to execute once the collapsible area is expanded }) ``` @@ -119,10 +119,10 @@ myCollapseEl.addEventListener('shown.bs.collapse', function (event) { In addition a method call on a **transitioning component will be ignored**. ```js -var myCarouselEl = document.getElementById('myCarousel') -var carousel = bootstrap.Carousel.getInstance(myCarouselEl) // Retrieve a Carousel instance +const myCarouselEl = document.getElementById('myCarousel') +const carousel = bootstrap.Carousel.getInstance(myCarouselEl) // Retrieve a Carousel instance -myCarouselEl.addEventListener('slid.bs.carousel', function (event) { +myCarouselEl.addEventListener('slid.bs.carousel', event => { carousel.to('2') // Will slide to the slide 2 as soon as the transition to slide 1 is finished }) @@ -144,7 +144,7 @@ bootstrap.Modal.Default.keyboard = false Sometimes it is necessary to use Bootstrap plugins with other UI frameworks. In these circumstances, namespace collisions can occasionally occur. If this happens, you may call `.noConflict` on the plugin you wish to revert the value of. ```js -var bootstrapButton = $.fn.button.noConflict() // return $.fn.button to previously assigned value +const bootstrapButton = $.fn.button.noConflict() // return $.fn.button to previously assigned value $.fn.bootstrapBtn = bootstrapButton // give $().bootstrapBtn the Bootstrap functionality ``` @@ -173,8 +173,8 @@ Tooltips and Popovers use our built-in sanitizer to sanitize options which accep The default `allowList` value is the following: ```js -var ARIA_ATTRIBUTE_PATTERN = /^aria-[\w-]*$/i -var DefaultAllowlist = { +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'], @@ -212,7 +212,7 @@ var DefaultAllowlist = { If you want to add new values to this default `allowList` you can do the following: ```js -var myDefaultAllowList = bootstrap.Tooltip.Default.allowList +const myDefaultAllowList = bootstrap.Tooltip.Default.allowList // To allow table elements myDefaultAllowList.table = [] @@ -222,16 +222,16 @@ myDefaultAllowList.td = ['data-bs-option'] // You can push your custom regex to validate your attributes. // Be careful about your regular expressions being too lax -var myCustomRegex = /^data-my-app-[\w-]+/ +const myCustomRegex = /^data-my-app-[\w-]+/ myDefaultAllowList['*'].push(myCustomRegex) ``` If you want to bypass our sanitizer because you prefer to use a dedicated library, for example [DOMPurify](https://www.npmjs.com/package/dompurify), you should do the following: ```js -var yourTooltipEl = document.getElementById('yourTooltip') -var tooltip = new bootstrap.Tooltip(yourTooltipEl, { - sanitizeFn: function (content) { +const yourTooltipEl = document.getElementById('yourTooltip') +const tooltip = new bootstrap.Tooltip(yourTooltipEl, { + sanitizeFn(content) { return DOMPurify.sanitize(content) } }) -- cgit v1.2.3 From ebb1f485d3e750a67ac7633e5044f2fce0749afe Mon Sep 17 00:00:00 2001 From: Sam Magura Date: Fri, 29 Apr 2022 16:38:30 -0400 Subject: Document incompatibilities between Bootstrap JS and React/.etc (#36217) * Document incompatibilities between Bootstrap JS and React/.etc Closes #35665. * Remove link to reactstrap * Update javascript.md Co-authored-by: Mark Otto --- site/content/docs/5.1/getting-started/javascript.md | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'site/content/docs/5.1/getting-started/javascript.md') diff --git a/site/content/docs/5.1/getting-started/javascript.md b/site/content/docs/5.1/getting-started/javascript.md index 5e4321034..b4d8cbff1 100644 --- a/site/content/docs/5.1/getting-started/javascript.md +++ b/site/content/docs/5.1/getting-started/javascript.md @@ -12,6 +12,16 @@ Plugins can be included individually (using Bootstrap's individual `js/dist/*.js If you use a bundler (Webpack, Rollup...), you can use `/js/dist/*.js` files which are UMD ready. +## Usage with JavaScript frameworks + +While the Bootstrap CSS can be used with any framework, **the Bootstrap JavaScript is not fully compatible with frameworks like React, Vue, and Angular** which assume full knowledge of the DOM. Both Bootstrap and the framework may attempt to mutate the same DOM element, resulting in bugs like dropdowns that are stuck in the "open" position. + +A better alternative for those using React and similar frameworks is to use a framework-specific package **instead of** the Bootstrap JavaScript. Here are some of the most popular options: + +- React: [react-bootstrap](https://react-bootstrap.github.io/) +- Vue: [BootstrapVue](https://bootstrap-vue.org/) +- Angular: [ng-bootstrap](https://ng-bootstrap.github.io/) + ## Using Bootstrap as a module We provide a version of Bootstrap built as `ESM` (`bootstrap.esm.js` and `bootstrap.esm.min.js`) which allows you to use Bootstrap as a module in your browser, if your [targeted browsers support it](https://caniuse.com/es6-module). -- cgit v1.2.3 From 88a6610895c05d05f4710d0783eb5ea2f30294fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20D=C3=A9ramond?= Date: Wed, 11 May 2022 20:51:00 +0200 Subject: Minor changes in 'Usage with JavaScript frameworks' description --- site/content/docs/5.1/getting-started/javascript.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'site/content/docs/5.1/getting-started/javascript.md') diff --git a/site/content/docs/5.1/getting-started/javascript.md b/site/content/docs/5.1/getting-started/javascript.md index b4d8cbff1..fd676cf42 100644 --- a/site/content/docs/5.1/getting-started/javascript.md +++ b/site/content/docs/5.1/getting-started/javascript.md @@ -14,11 +14,11 @@ If you use a bundler (Webpack, Rollup...), you can use `/js/dist/*.js` files whi ## Usage with JavaScript frameworks -While the Bootstrap CSS can be used with any framework, **the Bootstrap JavaScript is not fully compatible with frameworks like React, Vue, and Angular** which assume full knowledge of the DOM. Both Bootstrap and the framework may attempt to mutate the same DOM element, resulting in bugs like dropdowns that are stuck in the "open" position. +While the Bootstrap CSS can be used with any framework, **the Bootstrap JavaScript is not fully compatible with JavaScript frameworks like React, Vue, and Angular** which assume full knowledge of the DOM. Both Bootstrap and the framework may attempt to mutate the same DOM element, resulting in bugs like dropdowns that are stuck in the "open" position. -A better alternative for those using React and similar frameworks is to use a framework-specific package **instead of** the Bootstrap JavaScript. Here are some of the most popular options: +A better alternative for those using this type of frameworks is to use a framework-specific package **instead of** the Bootstrap JavaScript. Here are some of the most popular options: -- React: [react-bootstrap](https://react-bootstrap.github.io/) +- React: [React Bootstrap](https://react-bootstrap.github.io/) - Vue: [BootstrapVue](https://bootstrap-vue.org/) - Angular: [ng-bootstrap](https://ng-bootstrap.github.io/) -- cgit v1.2.3 From f7e8ca91e03165abb82d4c82555dc4ef96340cc9 Mon Sep 17 00:00:00 2001 From: Mark Otto Date: Fri, 6 May 2022 23:57:58 +0300 Subject: Prepare v5.2.0-beta1 --- .../content/docs/5.1/getting-started/javascript.md | 248 --------------------- 1 file changed, 248 deletions(-) delete mode 100644 site/content/docs/5.1/getting-started/javascript.md (limited to 'site/content/docs/5.1/getting-started/javascript.md') diff --git a/site/content/docs/5.1/getting-started/javascript.md b/site/content/docs/5.1/getting-started/javascript.md deleted file mode 100644 index fd676cf42..000000000 --- a/site/content/docs/5.1/getting-started/javascript.md +++ /dev/null @@ -1,248 +0,0 @@ ---- -layout: docs -title: JavaScript -description: Bring Bootstrap to life with our optional JavaScript plugins. Learn about each plugin, our data and programmatic API options, and more. -group: getting-started -toc: true ---- - -## Individual or compiled - -Plugins can be included individually (using Bootstrap's individual `js/dist/*.js`), or all at once using `bootstrap.js` or the minified `bootstrap.min.js` (don't include both). - -If you use a bundler (Webpack, Rollup...), you can use `/js/dist/*.js` files which are UMD ready. - -## Usage with JavaScript frameworks - -While the Bootstrap CSS can be used with any framework, **the Bootstrap JavaScript is not fully compatible with JavaScript frameworks like React, Vue, and Angular** which assume full knowledge of the DOM. Both Bootstrap and the framework may attempt to mutate the same DOM element, resulting in bugs like dropdowns that are stuck in the "open" position. - -A better alternative for those using this type of frameworks is to use a framework-specific package **instead of** the Bootstrap JavaScript. Here are some of the most popular options: - -- React: [React Bootstrap](https://react-bootstrap.github.io/) -- Vue: [BootstrapVue](https://bootstrap-vue.org/) -- Angular: [ng-bootstrap](https://ng-bootstrap.github.io/) - -## Using Bootstrap as a module - -We provide a version of Bootstrap built as `ESM` (`bootstrap.esm.js` and `bootstrap.esm.min.js`) which allows you to use Bootstrap as a module in your browser, if your [targeted browsers support it](https://caniuse.com/es6-module). - -```html - -``` - -{{< callout warning >}} -## Incompatible plugins - -Due to browser limitations, some of our plugins, namely Dropdown, Tooltip and Popover plugins, cannot be used in a `