2018-03-12 18:34:09 +01:00
|
|
|
$(document).ready(function() {
|
2020-06-27 18:47:40 +02:00
|
|
|
let $carousel = $(".carousel");
|
2018-03-12 18:34:09 +01:00
|
|
|
$carousel.carousel();
|
2023-09-02 20:00:20 +02:00
|
|
|
let carousels = {0: "user-voices-carousel"};
|
2020-06-27 18:47:40 +02:00
|
|
|
let paused = {};
|
|
|
|
for (let key in carousels) {
|
2018-03-12 18:34:09 +01:00
|
|
|
if (!carousels.hasOwnProperty(key)) continue;
|
|
|
|
paused[key] = false;
|
|
|
|
}
|
2020-06-27 18:47:40 +02:00
|
|
|
let w, wTop, fTop, fHeight;
|
2018-03-12 18:34:09 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Prevent jumping page on small screens
|
|
|
|
* caused by a not-fixed height of the F-Droid carousel
|
|
|
|
*/
|
|
|
|
function preventSingleCarouselJumping() {
|
|
|
|
w = $(window).width();
|
|
|
|
wTop = $(window).scrollTop();
|
2020-06-27 18:47:40 +02:00
|
|
|
for (let c in carousels) {
|
|
|
|
let $ca = $("#" + carousels[c]);
|
2018-03-12 18:34:09 +01:00
|
|
|
fTop = $ca.offset().top;
|
|
|
|
fHeight = $ca.outerHeight();
|
|
|
|
if (w < 768 && !paused[c] && wTop > fTop + fHeight) { // pause cycling when slides are not displayed
|
|
|
|
paused[c] = true;
|
|
|
|
$ca.carousel('pause');
|
|
|
|
} else if (w < 768 && paused[c] && wTop <= fTop + fHeight // enable cycling when they are displayed
|
|
|
|
|| w >= 768 && paused) { // enable cycling when window got resized
|
|
|
|
paused[c] = false;
|
|
|
|
$ca.carousel('cycle');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$(window).scroll(preventSingleCarouselJumping);
|
|
|
|
$(window).resize(preventSingleCarouselJumping);
|
|
|
|
preventSingleCarouselJumping();
|
|
|
|
|
2020-06-27 18:47:40 +02:00
|
|
|
});
|