You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/getting-started/javascript.md
+21-21Lines changed: 21 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -59,9 +59,9 @@ CoreUI for Bootstrap provides custom events for most plugins' unique actions. Ge
59
59
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()`.
60
60
61
61
```js
62
-
var myModal =document.getElementById('myModal')
62
+
constmyModal=document.getElementById('myModal')
63
63
64
-
myModal.addEventListener('show.coreui.modal', function (event) {
returnevent.preventDefault() // stops modal from being shown
67
67
}
@@ -74,7 +74,7 @@ myModal.addEventListener('show.coreui.modal', function (event) {
74
74
CoreUI for Bootstrap will detect jQuery if `jQuery` is present in the `window` object and there is no `data-coreui-no-jquery` attribute set on `<body>`. If jQuery is found, CoreUI for Bootstrap will emit events thanks to jQuery's event system. So if you want to listen to CoreUI's events, you'll have to use the jQuery methods (`.on`, `.one`) instead of `addEventListener`.
75
75
76
76
```js
77
-
$('#myTab a').on('shown.coreui.tab', function () {
77
+
$('#myTab a').on('shown.coreui.tab', () => {
78
78
// do something...
79
79
})
80
80
```
@@ -85,10 +85,10 @@ $('#myTab a').on('shown.coreui.tab', function () {
85
85
All constructors accept an optional options object or nothing (which initiates a plugin with its default behavior):
86
86
87
87
```js
88
-
var myModalEl =document.getElementById('myModal')
88
+
constmyModalEl=document.getElementById('myModal')
89
89
90
-
var modal =newcoreui.Modal(myModalEl) // initialized with defaults
91
-
var modal=newcoreui.Modal(myModalEl, { keyboard:false }) // initialized with no keyboard
90
+
constmodal=newcoreui.Modal(myModalEl) // initialized with defaults
91
+
constmodal1=newcoreui.Modal(myModalEl, { keyboard:false }) // initialized with no keyboard
92
92
```
93
93
94
94
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: `coreui.Popover.getInstance(myPopoverEl)`.
@@ -98,8 +98,8 @@ If you'd like to get a particular plugin instance, each plugin exposes a `getIns
98
98
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.
99
99
100
100
```js
101
-
var modal =newcoreui.Modal('#myModal')
102
-
var dropdown =newcoreui.Dropdown('[data-coreui-toggle="dropdown"]')
Sometimes it is necessary to use CoreUI for 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.
145
145
146
146
```js
147
-
var coreuiButton =$.fn.button.noConflict() // return $.fn.button to previously assigned value
147
+
constcoreuiButton=$.fn.button.noConflict() // return $.fn.button to previously assigned value
148
148
$.fn.coreuiBtn= coreuiButton // give $().coreuiBtn the CoreUI for Bootstrap functionality
149
149
```
150
150
@@ -173,8 +173,8 @@ Tooltips and Popovers use our built-in sanitizer to sanitize options which accep
173
173
The default `allowList` value is the following:
174
174
175
175
```js
176
-
varARIA_ATTRIBUTE_PATTERN=/^aria-[\w-]*$/i
177
-
var DefaultAllowlist = {
176
+
constARIA_ATTRIBUTE_PATTERN=/^aria-[\w-]*$/i
177
+
constDefaultAllowlist= {
178
178
// Global attributes allowed on any supplied element below.
// You can push your custom regex to validate your attributes.
224
224
// Be careful about your regular expressions being too lax
225
-
var myCustomRegex =/^data-my-app-[\w-]+/
225
+
constmyCustomRegex=/^data-my-app-[\w-]+/
226
226
myDefaultAllowList['*'].push(myCustomRegex)
227
227
```
228
228
229
229
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:
230
230
231
231
```js
232
-
var yourTooltipEl =document.getElementById('yourTooltip')
0 commit comments