Skip to content

Commit 37d4ef0

Browse files
committed
fix(xbootstrap5): simplify carousel initialization
Remove the duplicate title element from the theme head and initialize carousels once with a single ready-time path. This avoids redundant ready callbacks, repeated warnings, and conflicting Bootstrap carousel configs.
1 parent ccb8d81 commit 37d4ef0

2 files changed

Lines changed: 27 additions & 31 deletions

File tree

htdocs/themes/xbootstrap5/js/js.js

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
// JavaScript Document
22

3-
function initBootstrapCarousels(options) {
4-
jQuery(function ($) {
5-
$('.carousel').each(function () {
6-
if (globalThis.bootstrap?.Carousel) {
7-
globalThis.bootstrap.Carousel.getOrCreateInstance(this, options);
8-
} else if (typeof $.fn.carousel === 'function') {
9-
$(this).carousel(options);
10-
} else {
11-
console.warn('Bootstrap carousel API not available.');
12-
}
3+
function initBootstrapCarousels($, options) {
4+
var $carousels = $('.carousel');
5+
6+
if (!$carousels.length) {
7+
return;
8+
}
9+
10+
if (globalThis.bootstrap?.Carousel) {
11+
$carousels.each(function () {
12+
globalThis.bootstrap.Carousel.getOrCreateInstance(this, options);
1313
});
14-
});
14+
15+
return;
16+
}
17+
18+
if (typeof $.fn.carousel === 'function') {
19+
$carousels.carousel(options);
20+
21+
return;
22+
}
23+
24+
console.warn('Bootstrap carousel API not available.');
1525
}
1626

1727
/* Scroll Top */
@@ -34,10 +44,12 @@ jQuery(function ($) {
3444
});
3545

3646
/* Bootstrap Carousel */
37-
initBootstrapCarousels({
38-
interval: 5000,
39-
pause: 'hover',
40-
wrap: true
47+
jQuery(function ($) {
48+
initBootstrapCarousels($, {
49+
interval: 5000,
50+
pause: 'hover',
51+
wrap: true
52+
});
4153
});
4254

4355
/* Masonry Grid */
@@ -56,18 +68,3 @@ jQuery(function ($) {
5668
$(".newbb-links").find('span').removeClass('forum_icon forum_button');
5769
$('.newbb-thread-attachment').find('br, hr').remove();
5870
});
59-
60-
/* Slider init */
61-
function initSlider() {
62-
initBootstrapCarousels({
63-
interval: 5000,
64-
wrap: true
65-
});
66-
}
67-
68-
// Load when browser is idle
69-
if ('requestIdleCallback' in globalThis) {
70-
globalThis.requestIdleCallback(initSlider);
71-
} else {
72-
setTimeout(initSlider, 200); // fallback
73-
}

htdocs/themes/xbootstrap5/theme.tpl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
<meta name="rating" content="<{$xoops_meta_rating}>">
1212
<meta name="author" content="<{$xoops_meta_author}>">
1313
<meta name="generator" content="XOOPS">
14-
<title><{$xoops_sitename}> - <{$xoops_pagetitle}></title>
1514
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1615
<!-- Owl Carousel Assets -->
1716
<link href="<{xoImgUrl}>js/owl/assets/owl.carousel.css" rel="stylesheet">

0 commit comments

Comments
 (0)