vCarousel/src/exampleFlickity.js

61 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-04-08 16:01:03 +02:00
var Flickity = require("flickity");
import { vCarousel } from "./vCarousel";
2021-04-08 16:01:03 +02:00
var selectFlickityForHash = function (flickityCarousel, urlHash) {
var nb = 0, find = false;
for (var _i = 0, _a = flickityCarousel.cells; _i < _a.length; _i++) {
var cel = _a[_i];
var childrens = cel.element.childNodes;
for (var i = 0, c = childrens.length; i < c; i++) {
if (childrens[i].nodeType === Node.ELEMENT_NODE) {
if (childrens[i].hash != undefined && childrens[i].hash === urlHash) {
flickityCarousel.select(nb);
2021-04-08 16:01:03 +02:00
find = true;
break;
}
}
}
nb++;
}
if (find === false)
console.error("L'ancre fournie par l'url n'a pas été trouvée dans le carrousel Flickity.");
};
try {
var imgCarousel = document.querySelector(".img-carousel");
var flktyCarousel_1 = new Flickity(imgCarousel, {
accessibility: true,
cellAlign: "center",
contain: true,
rightToLeft: true,
2021-04-29 17:40:20 +02:00
wrapAround: true,
2021-04-08 16:01:03 +02:00
});
2021-04-29 17:40:20 +02:00
var videosContainers = ["vFunanbule", "vForgeron", "vCircuit"];
var testvCarousel_1 = new vCarousel();
2021-04-29 17:40:20 +02:00
testvCarousel_1.vContainers = videosContainers;
2021-04-08 16:01:03 +02:00
if (window.location.hash !== undefined && window.location.hash !== "") {
2021-04-29 17:40:20 +02:00
testvCarousel_1.firstVideoId = window.location.hash.replace("#", "");
2021-04-08 16:01:03 +02:00
selectFlickityForHash(flktyCarousel_1, location.hash);
}
else
testvCarousel_1.firstVideoId = "";
2021-04-29 17:40:20 +02:00
testvCarousel_1.run();
2021-04-08 16:01:03 +02:00
var selectLinks = document.querySelectorAll(".selectVideo");
var _loop_1 = function (i) {
var link = selectLinks[i];
link.addEventListener("click", function (e) {
2021-04-29 17:40:20 +02:00
testvCarousel_1.firstVideoId = link.hash.replace("#", "");
testvCarousel_1.playFirstVideo = true;
testvCarousel_1.playNextVideos = true;
2021-04-29 17:40:20 +02:00
testvCarousel_1.run();
2021-04-08 16:01:03 +02:00
});
};
for (var i = 0; i < selectLinks.length; i++) {
_loop_1(i);
}
window.addEventListener('hashchange', function () {
selectFlickityForHash(flktyCarousel_1, location.hash);
});
}
catch (e) {
console.error(e);
}