Ajout d'un sous-répertoire pour la version compilée par TypeScript des fichiers source
This commit is contained in:
parent
cd362748cf
commit
2be97bd392
24
src/build/example.js
Normal file
24
src/build/example.js
Normal file
@ -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);
|
||||||
|
}
|
60
src/build/exampleFlickity.js
Normal file
60
src/build/exampleFlickity.js
Normal file
@ -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);
|
||||||
|
}
|
121
src/build/vCarousel.js
Normal file
121
src/build/vCarousel.js
Normal file
@ -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 };
|
Loading…
Reference in New Issue
Block a user