From 2be97bd3928d26e16d6afc490aaa33809557eaa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabrice=20PENHO=C3=8BT?= Date: Tue, 3 Aug 2021 18:05:39 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20d'un=20sous-r=C3=A9pertoire=20pour=20la?= =?UTF-8?q?=20version=20compil=C3=A9e=20par=20TypeScript=20des=20fichiers?= =?UTF-8?q?=20source?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/build/example.js | 24 +++++++ src/build/exampleFlickity.js | 60 +++++++++++++++++ src/build/vCarousel.js | 121 +++++++++++++++++++++++++++++++++++ 3 files changed, 205 insertions(+) create mode 100644 src/build/example.js create mode 100644 src/build/exampleFlickity.js create mode 100644 src/build/vCarousel.js diff --git a/src/build/example.js b/src/build/example.js new file mode 100644 index 0000000..6fd0a5b --- /dev/null +++ b/src/build/example.js @@ -0,0 +1,24 @@ +import { vCarousel } from "./vCarousel"; +try { + var videosContainers = ["vFunanbule", "vForgeron", "vCircuit"]; + var testvCarousel_1 = new vCarousel(); + testvCarousel_1.vContainers = videosContainers; + if (window.location.hash !== undefined && window.location.hash !== "") + testvCarousel_1.firstVideoId = window.location.hash.replace("#", ""); + testvCarousel_1.run(); + var selectLinks = document.querySelectorAll(".selectVideo"); + var _loop_1 = function (i) { + var link = selectLinks[i]; + link.addEventListener("click", function (e) { + testvCarousel_1.firstVideoId = link.hash.replace("#", ""); + testvCarousel_1.playFirstVideo = true; + testvCarousel_1.run(); + }); + }; + for (var i = 0; i < selectLinks.length; i++) { + _loop_1(i); + } +} +catch (e) { + console.error(e); +} diff --git a/src/build/exampleFlickity.js b/src/build/exampleFlickity.js new file mode 100644 index 0000000..930c298 --- /dev/null +++ b/src/build/exampleFlickity.js @@ -0,0 +1,60 @@ +var Flickity = require("flickity"); +import { vCarousel } from "./vCarousel"; +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); + 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, + wrapAround: true, + }); + var videosContainers = ["vFunanbule", "vForgeron", "vCircuit"]; + var testvCarousel_1 = new vCarousel(); + testvCarousel_1.vContainers = videosContainers; + if (window.location.hash !== undefined && window.location.hash !== "") { + testvCarousel_1.firstVideoId = window.location.hash.replace("#", ""); + selectFlickityForHash(flktyCarousel_1, location.hash); + } + else + testvCarousel_1.firstVideoId = ""; + testvCarousel_1.run(); + var selectLinks = document.querySelectorAll(".selectVideo"); + var _loop_1 = function (i) { + var link = selectLinks[i]; + link.addEventListener("click", function (e) { + testvCarousel_1.firstVideoId = link.hash.replace("#", ""); + testvCarousel_1.playFirstVideo = true; + testvCarousel_1.playNextVideos = true; + testvCarousel_1.run(); + }); + }; + 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); +} diff --git a/src/build/vCarousel.js b/src/build/vCarousel.js new file mode 100644 index 0000000..d1c7bd8 --- /dev/null +++ b/src/build/vCarousel.js @@ -0,0 +1,121 @@ +var errors = require("./errors.js"); +var vCarousel = (function () { + function vCarousel() { + this._vContainers = []; + this._firstVideoId = undefined; + this._playFirstVideo = false; + this._playNextVideos = false; + this._noStop = false; + this.nbVContainers = 0; + this._currentVideo = undefined; + } + Object.defineProperty(vCarousel.prototype, "vContainers", { + set: function (vContainersIds) { + for (var _i = 0, vContainersIds_1 = vContainersIds; _i < vContainersIds_1.length; _i++) { + var containerId = vContainersIds_1[_i]; + var checkContainerExist = document.getElementById(containerId); + if (checkContainerExist === null) + throw new Error(errors.elementNotFound + containerId); + else { + var checkVideoExist = document.querySelector("#" + containerId + " video"); + if (checkVideoExist === null) + throw new Error(errors.videoNotFound + containerId); + else + this._vContainers.push({ id: containerId, containerElt: checkContainerExist, videoElt: checkVideoExist }); + } + } + this.nbVContainers = this._vContainers.length; + if (this.nbVContainers < 2) + throw new Error(errors.need2Videos); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(vCarousel.prototype, "firstVideoId", { + get: function () { + return this._firstVideoId; + }, + set: function (firstVideo) { + if ((firstVideo !== "" && this._vContainers.findIndex(function (video) { return video.id === firstVideo; }) !== -1) || (firstVideo === "")) + this._firstVideoId = firstVideo; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(vCarousel.prototype, "playFirstVideo", { + set: function (playFirstVideo) { + this._playFirstVideo = playFirstVideo; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(vCarousel.prototype, "playNextVideos", { + set: function (playNextVideos) { + this._playNextVideos = playNextVideos; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(vCarousel.prototype, "noStop", { + set: function (noStop) { + this._noStop = noStop; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(vCarousel.prototype, "currentVideo", { + get: function () { + return this._currentVideo; + }, + enumerable: true, + configurable: true + }); + vCarousel.prototype.run = function () { + var vCarousel = this; + if (vCarousel.nbVContainers < 2) + throw new Error(errors.needVideosProvided); + var _loop_1 = function (i) { + var vContainer = vCarousel._vContainers[i].containerElt; + var video = vCarousel._vContainers[i].videoElt; + if ((vCarousel._firstVideoId !== undefined && vCarousel._vContainers[i].id !== vCarousel._firstVideoId) || (vCarousel._firstVideoId === undefined && i !== 0) || vCarousel._firstVideoId === "") + vContainer.style.display = "none"; + else { + if (vCarousel._currentVideo !== undefined && !vCarousel._currentVideo.paused) + vCarousel._currentVideo.pause(); + vContainer.style.display = "block"; + vCarousel._currentVideo = video; + if (vCarousel._playFirstVideo === true) + video.play(); + } + nbTurn = 0; + video.addEventListener("ended", function () { + if (nbTurn < (vCarousel.nbVContainers - 1) || vCarousel._noStop === true) { + vContainer.style.display = "none"; + var nextVContainer = void 0, nextVideo = void 0, nextHash = void 0; + if (i < (vCarousel.nbVContainers - 1)) { + nextVContainer = vCarousel._vContainers[i + 1].containerElt; + nextVideo = vCarousel._vContainers[i + 1].videoElt; + nextHash = vCarousel._vContainers[i + 1].id; + } + else { + nextVContainer = vCarousel._vContainers[0].containerElt; + nextVideo = vCarousel._vContainers[0].videoElt; + nextHash = vCarousel._vContainers[0].id; + } + nextVContainer.style.display = "block"; + vCarousel._currentVideo = nextVideo; + window.location.assign("#" + nextHash); + if (vCarousel._playNextVideos === true) + nextVideo.play(); + nbTurn++; + } + }); + }; + var nbTurn; + for (var i = 0; i < vCarousel.nbVContainers; i++) { + _loop_1(i); + } + }; + return vCarousel; +}()); +export { vCarousel };