diff options
author | GeoSot <geo.sotis@gmail.com> | 2021-06-03 18:53:27 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-03 18:53:27 +0300 |
commit | c98657b8303150bfda3bdea750055b83a29b27a3 (patch) | |
tree | 6f7b347461e3fdd380f0d4e990440e6fc427af61 /site/content/docs/5.0 | |
parent | 4a5029ea29ac75243dfec68153051292fc70f5cf (diff) |
Add `getOrCreateInstance` method in base-component (#33276)
Co-authored-by: Rohit Sharma <rohit2sharma95@gmail.com>
Co-authored-by: XhmikosR <xhmikosr@gmail.com>
Diffstat (limited to 'site/content/docs/5.0')
-rw-r--r-- | site/content/docs/5.0/components/alerts.md | 9 | ||||
-rw-r--r-- | site/content/docs/5.0/components/buttons.md | 17 | ||||
-rw-r--r-- | site/content/docs/5.0/components/carousel.md | 17 | ||||
-rw-r--r-- | site/content/docs/5.0/components/collapse.md | 17 | ||||
-rw-r--r-- | site/content/docs/5.0/components/dropdowns.md | 15 | ||||
-rw-r--r-- | site/content/docs/5.0/components/list-group.md | 9 | ||||
-rw-r--r-- | site/content/docs/5.0/components/modal.md | 9 | ||||
-rw-r--r-- | site/content/docs/5.0/components/navs-tabs.md | 9 | ||||
-rw-r--r-- | site/content/docs/5.0/components/offcanvas.md | 1 | ||||
-rw-r--r-- | site/content/docs/5.0/components/popovers.md | 9 | ||||
-rw-r--r-- | site/content/docs/5.0/components/scrollspy.md | 9 | ||||
-rw-r--r-- | site/content/docs/5.0/components/toasts.md | 18 | ||||
-rw-r--r-- | site/content/docs/5.0/components/tooltips.md | 9 |
13 files changed, 142 insertions, 6 deletions
diff --git a/site/content/docs/5.0/components/alerts.md b/site/content/docs/5.0/components/alerts.md index d0c5685a09..a7e52f5f89 100644 --- a/site/content/docs/5.0/components/alerts.md +++ b/site/content/docs/5.0/components/alerts.md @@ -209,6 +209,15 @@ This makes an alert listen for click events on descendant elements which have th Static method which allows you to get the alert instance associated to a DOM element, you can use it like this: <code>bootstrap.Alert.getInstance(alert)</code> </td> </tr> + <tr> + <td> + <code>getOrCreateInstance</code> + </td> + <td> + Static method which returns an alert instance associated to a DOM element or create a new one in case it wasn't initialised. + You can use it like this: <code>bootstrap.Alert.getOrCreateInstance(element)</code> + </td> + </tr> </tbody> </table> diff --git a/site/content/docs/5.0/components/buttons.md b/site/content/docs/5.0/components/buttons.md index 063bae1c41..d62d6e2b65 100644 --- a/site/content/docs/5.0/components/buttons.md +++ b/site/content/docs/5.0/components/buttons.md @@ -193,6 +193,23 @@ var bsButton = new bootstrap.Button(button) Destroys an element's button. (Removes stored data on the DOM element) </td> </tr> + <tr> + <td> + <code>getInstance</code> + </td> + <td> + Static method which allows you to get the button instance associated to a DOM element, you can use it like this: <code>bootstrap.Button.getInstance(element)</code> + </td> + </tr> + <tr> + <td> + <code>getOrCreateInstance</code> + </td> + <td> + Static method which returns a button instance associated to a DOM element or create a new one in case it wasn't initialised. + You can use it like this: <code>bootstrap.Button.getOrCreateInstance(element)</code> + </td> + </tr> </tbody> </table> diff --git a/site/content/docs/5.0/components/carousel.md b/site/content/docs/5.0/components/carousel.md index 9ad7294ecc..e106e76c0e 100644 --- a/site/content/docs/5.0/components/carousel.md +++ b/site/content/docs/5.0/components/carousel.md @@ -413,8 +413,21 @@ var carousel = new bootstrap.Carousel(myCarousel, { <td>Destroys an element's carousel. (Removes stored data on the DOM element)</td> </tr> <tr> - <td><code>getInstance</code></td> - <td>Static method which allows you to get the carousel instance associated with a DOM element.</td> + <td> + <code>getInstance</code> + </td> + <td> + Static method which allows you to get the carousel instance associated to a DOM element, you can use it like this: <code>bootstrap.Carousel.getInstance(element)</code> + </td> + </tr> + <tr> + <td> + <code>getOrCreateInstance</code> + </td> + <td> + Static method which returns a carousel instance associated to a DOM element or create a new one in case it wasn't initialised. + You can use it like this: <code>bootstrap.Carousel.getOrCreateInstance(element)</code> + </td> </tr> </tbody> </table> diff --git a/site/content/docs/5.0/components/collapse.md b/site/content/docs/5.0/components/collapse.md index fe26918c1f..ac84ca9649 100644 --- a/site/content/docs/5.0/components/collapse.md +++ b/site/content/docs/5.0/components/collapse.md @@ -187,8 +187,21 @@ var bsCollapse = new bootstrap.Collapse(myCollapse, { <td>Destroys an element's collapse. (Removes stored data on the DOM element)</td> </tr> <tr> - <td><code>getInstance</code></td> - <td>Static method which allows you to get the collapse instance associated with a DOM element.</td> + <td> + <code>getInstance</code> + </td> + <td> + Static method which allows you to get the collapse instance associated to a DOM element, you can use it like this: <code>bootstrap.Collapse.getInstance(element)</code> + </td> + </tr> + <tr> + <td> + <code>getOrCreateInstance</code> + </td> + <td> + Static method which returns a collapse instance associated to a DOM element or create a new one in case it wasn't initialised. + You can use it like this: <code>bootstrap.Collapse.getOrCreateInstance(element)</code> + </td> </tr> </tbody> </table> diff --git a/site/content/docs/5.0/components/dropdowns.md b/site/content/docs/5.0/components/dropdowns.md index 3ab91f8078..e15cc0fe62 100644 --- a/site/content/docs/5.0/components/dropdowns.md +++ b/site/content/docs/5.0/components/dropdowns.md @@ -1136,9 +1136,20 @@ var dropdown = new bootstrap.Dropdown(element, { </td> </tr> <tr> - <td><code>getInstance</code></td> <td> - Static method which allows you to get the dropdown instance associated with a DOM element. + <code>getInstance</code> + </td> + <td> + Static method which allows you to get the dropdown instance associated to a DOM element, you can use it like this: <code>bootstrap.Dropdown.getInstance(element)</code> + </td> + </tr> + <tr> + <td> + <code>getOrCreateInstance</code> + </td> + <td> + Static method which returns a dropdown instance associated to a DOM element or create a new one in case it wasn't initialised. + You can use it like this: <code>bootstrap.Dropdown.getOrCreateInstance(element)</code> </td> </tr> </tbody> diff --git a/site/content/docs/5.0/components/list-group.md b/site/content/docs/5.0/components/list-group.md index 4b450939ef..76d0013e21 100644 --- a/site/content/docs/5.0/components/list-group.md +++ b/site/content/docs/5.0/components/list-group.md @@ -484,6 +484,15 @@ var triggerEl = document.querySelector('#trigger') var tab = bootstrap.Tab.getInstance(triggerEl) // Returns a Bootstrap tab instance ``` +#### getOrCreateInstance + +*Static* method which allows you to get the tab instance associated with a DOM element, or create a new one in case it wasn't initialised + +```js +var triggerEl = document.querySelector('#trigger') +var tab = bootstrap.Tab.getOrCreateInstance(triggerEl) // Returns a Bootstrap tab instance +``` + ### Events When showing a new tab, the events fire in the following order: diff --git a/site/content/docs/5.0/components/modal.md b/site/content/docs/5.0/components/modal.md index 9917656a57..d19957f3e7 100644 --- a/site/content/docs/5.0/components/modal.md +++ b/site/content/docs/5.0/components/modal.md @@ -952,6 +952,15 @@ var myModalEl = document.getElementById('myModal') var modal = bootstrap.Modal.getInstance(myModalEl) // Returns a Bootstrap modal instance ``` +#### 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 initialised + +```js +var myModalEl = document.querySelector('#myModal') +var modal = bootstrap.Modal.getOrCreateInstance(myModalEl) // Returns a Bootstrap modal instance +``` + ### Events Bootstrap's modal class exposes a few events for hooking into modal functionality. All modal events are fired at the modal itself (i.e. at the `<div class="modal">`). diff --git a/site/content/docs/5.0/components/navs-tabs.md b/site/content/docs/5.0/components/navs-tabs.md index 830f71c257..b839f9754f 100644 --- a/site/content/docs/5.0/components/navs-tabs.md +++ b/site/content/docs/5.0/components/navs-tabs.md @@ -624,6 +624,15 @@ var triggerEl = document.querySelector('#trigger') var tab = bootstrap.Tab.getInstance(triggerEl) // Returns a Bootstrap tab instance ``` +#### getOrCreateInstance + +*Static* method which allows you to get the tab instance associated with a DOM element, or create a new one in case it wasn't initialised + +```js +var triggerEl = document.querySelector('#trigger') +var tab = bootstrap.Tab.getOrCreateInstance(triggerEl) // Returns a Bootstrap tab instance +``` + ### Events When showing a new tab, the events fire in the following order: diff --git a/site/content/docs/5.0/components/offcanvas.md b/site/content/docs/5.0/components/offcanvas.md index b9dbd7ce8d..d0c60db2b2 100644 --- a/site/content/docs/5.0/components/offcanvas.md +++ b/site/content/docs/5.0/components/offcanvas.md @@ -241,6 +241,7 @@ var bsOffcanvas = new bootstrap.Offcanvas(myOffcanvas) | `show` | Shows an offcanvas element. **Returns to the caller before the offcanvas element has actually been shown** (i.e. before the `shown.bs.offcanvas` event occurs).| | `hide` | Hides an offcanvas element. **Returns to the caller before the offcanvas element has actually been hidden** (i.e. before the `hidden.bs.offcanvas` event occurs).| | `getInstance` | *Static* method which allows you to get the offcanvas instance associated with a DOM element | +| `getOrCreateInstance` | *Static* method which allows you to get the offcanvas instance associated with a DOM element, or create a new one in case it wasn't initialised | {{< /bs-table >}} ### Events diff --git a/site/content/docs/5.0/components/popovers.md b/site/content/docs/5.0/components/popovers.md index 039a47cc1f..06aa656d96 100644 --- a/site/content/docs/5.0/components/popovers.md +++ b/site/content/docs/5.0/components/popovers.md @@ -393,6 +393,15 @@ var exampleTriggerEl = document.getElementById('example') var popover = bootstrap.Popover.getInstance(exampleTriggerEl) // Returns a Bootstrap popover instance ``` +#### getOrCreateInstance + +*Static* method which allows you to get the popover instance associated with a DOM element, or create a new one in case it wasn't initialised + +```js +var exampleTriggerEl = document.getElementById('example') +var popover = bootstrap.Popover.getOrCreateInstance(exampleTriggerEl) // Returns a Bootstrap popover instance +``` + ### Events <table class="table"> diff --git a/site/content/docs/5.0/components/scrollspy.md b/site/content/docs/5.0/components/scrollspy.md index e1d748bca0..580a1e2d55 100644 --- a/site/content/docs/5.0/components/scrollspy.md +++ b/site/content/docs/5.0/components/scrollspy.md @@ -298,6 +298,15 @@ var scrollSpyContentEl = document.getElementById('content') var scrollSpy = bootstrap.ScrollSpy.getInstance(scrollSpyContentEl) // Returns a Bootstrap scrollspy instance ``` +#### getOrCreateInstance + +*Static* method which allows you to get the scrollspy instance associated with a DOM element, or create a new one in case it wasn't initialised + +```js +var scrollSpyContentEl = document.getElementById('content') +var scrollSpy = bootstrap.ScrollSpy.getOrCreateInstance(scrollSpyContentEl) // Returns a Bootstrap scrollspy instance +``` + ### Options Options can be passed via data attributes or JavaScript. For data attributes, append the option name to `data-bs-`, as in `data-bs-offset=""`. diff --git a/site/content/docs/5.0/components/toasts.md b/site/content/docs/5.0/components/toasts.md index 75713050c8..2dde09f5ba 100644 --- a/site/content/docs/5.0/components/toasts.md +++ b/site/content/docs/5.0/components/toasts.md @@ -391,6 +391,24 @@ Hides an element's toast. Your toast will remain on the DOM but won't show anymo toast.dispose() ``` +#### getInstance + +*Static* method which allows you to get the scrollspy instance associated with a DOM element + +```js +var myToastEl = document.getElementById('myToastEl') +var myToast = bootstrap.Toast.getInstance(myToastEl) // Returns a Bootstrap toast instance +``` + +#### getOrCreateInstance + +*Static* method which allows you to get the scrollspy instance associated with a DOM element, or create a new one in case it wasn't initialised + +```js +var myToastEl = document.getElementById('myToastEl') +var myToast = bootstrap.Toast.getOrCreateInstance(myToastEl) // Returns a Bootstrap toast instance +``` + ### Events <table class="table"> diff --git a/site/content/docs/5.0/components/tooltips.md b/site/content/docs/5.0/components/tooltips.md index 6af594ee34..386d3e9f18 100644 --- a/site/content/docs/5.0/components/tooltips.md +++ b/site/content/docs/5.0/components/tooltips.md @@ -417,6 +417,15 @@ var exampleTriggerEl = document.getElementById('example') var tooltip = bootstrap.Tooltip.getInstance(exampleTriggerEl) // Returns a Bootstrap tooltip instance ``` +#### getOrCreateInstance + +*Static* method which allows you to get the tooltip instance associated with a DOM element, or create a new one in case it wasn't initialised + +```js +var exampleTriggerEl = document.getElementById('example') +var tooltip = bootstrap.Tooltip.getOrCreateInstance(exampleTriggerEl) // Returns a Bootstrap tooltip instance +``` + ### Events <table class="table"> |