2021-08-03 18:05:39 +02:00
|
|
|
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) {
|
2021-08-04 18:16:02 +02:00
|
|
|
if ((firstVideo !== undefined && firstVideo !== "" && this._vContainers.findIndex(function (video) { return video.id === firstVideo; }) !== -1) || (firstVideo === ""))
|
2021-08-03 18:05:39 +02:00
|
|
|
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;
|
2022-01-18 18:22:58 +01:00
|
|
|
if (vCarousel._playFirstVideo)
|
2021-08-03 18:05:39 +02:00
|
|
|
video.play();
|
|
|
|
}
|
|
|
|
nbTurn = 0;
|
|
|
|
video.addEventListener("ended", function () {
|
2022-01-18 18:22:58 +01:00
|
|
|
if (nbTurn < (vCarousel.nbVContainers - 1) || vCarousel._noStop) {
|
2021-08-03 18:05:39 +02:00
|
|
|
vContainer.style.display = "none";
|
2021-08-04 18:16:02 +02:00
|
|
|
var nextVContainer = void 0, nextVideo = void 0, nextHash = void 0, nextOne = 0;
|
|
|
|
if (i < (vCarousel.nbVContainers - 1))
|
|
|
|
nextOne = i + 1;
|
|
|
|
nextVContainer = vCarousel._vContainers[nextOne].containerElt;
|
|
|
|
nextVideo = vCarousel._vContainers[nextOne].videoElt;
|
|
|
|
nextHash = vCarousel._vContainers[nextOne].id;
|
2021-08-03 18:05:39 +02:00
|
|
|
nextVContainer.style.display = "block";
|
|
|
|
vCarousel._currentVideo = nextVideo;
|
2022-01-18 18:22:58 +01:00
|
|
|
nextVideo.currentTime = 0;
|
2021-08-03 18:05:39 +02:00
|
|
|
window.location.assign("#" + nextHash);
|
2022-01-18 18:22:58 +01:00
|
|
|
if (vCarousel._playNextVideos)
|
2021-08-03 18:05:39 +02:00
|
|
|
nextVideo.play();
|
|
|
|
nbTurn++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
var nbTurn;
|
|
|
|
for (var i = 0; i < vCarousel.nbVContainers; i++) {
|
|
|
|
_loop_1(i);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return vCarousel;
|
|
|
|
}());
|
|
|
|
export { vCarousel };
|