Skip to content

Commit ccb8d81

Browse files
committed
style(xbootstrap5): align carousel script with Sonar
Use optional chaining for the Bootstrap carousel guard and prefer globalThis for browser-global access in the xbootstrap5 runtime script.
1 parent 9bd2029 commit ccb8d81

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

  • htdocs/themes/xbootstrap5/js

htdocs/themes/xbootstrap5/js/js.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
function initBootstrapCarousels(options) {
44
jQuery(function ($) {
55
$('.carousel').each(function () {
6-
if (window.bootstrap && window.bootstrap.Carousel) {
7-
window.bootstrap.Carousel.getOrCreateInstance(this, options);
6+
if (globalThis.bootstrap?.Carousel) {
7+
globalThis.bootstrap.Carousel.getOrCreateInstance(this, options);
88
} else if (typeof $.fn.carousel === 'function') {
99
$(this).carousel(options);
1010
} else {
@@ -66,8 +66,8 @@ function initSlider() {
6666
}
6767

6868
// Load when browser is idle
69-
if ('requestIdleCallback' in window) {
70-
requestIdleCallback(initSlider);
69+
if ('requestIdleCallback' in globalThis) {
70+
globalThis.requestIdleCallback(initSlider);
7171
} else {
7272
setTimeout(initSlider, 200); // fallback
7373
}

0 commit comments

Comments
 (0)