Skip to content

Commit

Permalink
Update after feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoSot committed May 16, 2022
1 parent b1e4bc2 commit 1ff4449
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
20 changes: 9 additions & 11 deletions site/content/docs/5.2/getting-started/javascript.md
Expand Up @@ -51,9 +51,9 @@ Our dropdowns, popovers and tooltips also depend on [Popper](https://popper.js.o

Nearly all Bootstrap plugins can be enabled and configured through HTML alone with data attributes (our preferred way of using JavaScript functionality). Be sure to **only use one set of data attributes on a single element** (e.g., you cannot trigger a tooltip and modal from the same button.)

Make sure to change the case type of the option name from camelCase to kebab-case when passing the options via data attributes. For example, use `data-bs-custom-class="beautifier"` instead of `data-bs-customClass="beautifier"`.

As of Bootstrap 5.2.0, all components support an **experimental** reserved data attribute `data-bs-config` that can house simple component configuration as a JSON string. When an element has `data-bs-config='{"delay":0, "title":123}'` and `data-bs-title="456"` attributes, the final `title` value will be `456` and the separate data attributes will override values given on `data-bs-config`. In addition, existing data attributes are able to house JSON values like `data-bs-delay='{"show":0,"hide":150}'`.
{{< markdown >}}
{{< partial "js-data-attributes.md" >}}
{{< /markdown >}}


{{< callout warning >}}
Expand Down Expand Up @@ -96,12 +96,12 @@ const modal1 = new bootstrap.Modal(myModalEl, configObject) // initialized with
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)`.
This method will return `null` if an instance is not initiated over the requested element

Alternatively `getOrCreateInstance` can be used to get the instance associated with a DOM element, or create a new one in case it wasn't initialized. `bootstrap.Popover.getOrCreateInstance(myPopoverEl, configObject)`.
In case an instance wasn't initialized, it may accept and use an optional configuration object as second argument
Alternatively `getOrCreateInstance` can be used to get the instance associated with a DOM element, or create a new one in case it wasn't initialized: `bootstrap.Popover.getOrCreateInstance(myPopoverEl, configObject)`.
In case an instance wasn't initialized, it may accept and use an optional configuration object as second argument.

### CSS selectors in constructors

All plugin constructors, and in addition methods `getInstance` & `getOrCreateInstance`, can accept as first argument, a DOM element or a valid [CSS selector](#selectors).
All plugin constructors, and in addition `getInstance` and `getOrCreateInstance` methods, can accept as first argument, a DOM element or a valid [CSS selector](#selectors).

Currently, the element for the plugin is found by the `querySelector` method since our plugins support a single element only.

Expand Down Expand Up @@ -142,12 +142,11 @@ carousel.to('2') // !! Will be ignored, as the transition to the slide 1 is not

{{< callout warning >}}
##### `dispose` method
Special care on `dispose` usage. It may seem right to use it directly after `hide()`, it will lead to wrong results
Special care on `dispose` usage. It may seem right to use it directly after `hide()` but it will lead to wrong results.

So the proper use would be something like:

```js

const myModal = document.querySelector('#myModal')
myModal.hide() // it is asynchronous

Expand All @@ -171,16 +170,16 @@ bootstrap.Modal.Default.keyboard = false
{{< bs-table "table" >}}
| Method | Description |
| --- | --- |
| `dispose` | Destroys an element's modal. (Removes stored data on the DOM element) |
| `getInstance` | *Static* method which allows you to get the modal instance associated with a DOM element. |
| `getOrCreateInstance` | *Static* method which allows you to get the modal instance associated with a DOM element, or create a new one in case it wasn't initialized. |
| `dispose` | Destroys an element's modal. (Removes stored data on the DOM element) |
{{< /bs-table >}}

{{< bs-table "table" >}}
| Static Properties | Description |
| --- | --- |
| `VERSION` | The version of each of Bootstrap's plugins can be accessed via the `VERSION` property of the plugin's constructor (Example: `bootstrap.Tooltip.VERSION`) |
| `NAME` | Returns the plugin name. (Example: `bootstrap.Tooltip.NAME`) |
| `VERSION` | The version of each of Bootstrap's plugins can be accessed via the `VERSION` property of the plugin's constructor (Example: `bootstrap.Tooltip.VERSION`) |
{{< /bs-table >}}

## Sanitizer
Expand Down Expand Up @@ -268,7 +267,6 @@ $('[data-bs-toggle="tooltip"]').tooltip() // to enable tooltips, with default co
$('[data-bs-toggle="tooltip"]').tooltip({ boundary: 'clippingParents', customClass: 'myClass' }) // to initialize tooltips with given configuration

$('#myTooltip').tooltip('show') // to trigger `show` method

```

The same goes for our other components.
Expand Down
2 changes: 1 addition & 1 deletion site/layouts/partials/js-data-attributes.md
@@ -1,3 +1,3 @@
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to `data-bs-`, as in `data-bs-animation=""`. Make sure to change the case type of the option name from camelCase to kebab-case when passing the options via data attributes. For example, use `data-bs-custom-class="beautifier"` instead of `data-bs-customClass="beautifier"`.
As options can be passed via data attributes or JavaScript, you can append an option name to `data-bs-`, as in `data-bs-animation="{value}"`. Make sure to change the case type of the option name from "_camelCase_" to "_kebab-case_" when passing the options via data attributes. For example, use `data-bs-custom-class="beautifier"` instead of `data-bs-customClass="beautifier"`.

As of Bootstrap 5.2.0, all components support an **experimental** reserved data attribute `data-bs-config` that can house simple component configuration as a JSON string. When an element has `data-bs-config='{"delay":0, "title":123}'` and `data-bs-title="456"` attributes, the final `title` value will be `456` and the separate data attributes will override values given on `data-bs-config`. In addition, existing data attributes are able to house JSON values like `data-bs-delay='{"show":0,"hide":150}'`.

0 comments on commit 1ff4449

Please sign in to comment.