|
@@ -15,6 +15,7 @@ import {
|
|
|
Uppy,
|
|
Uppy,
|
|
|
Dashboard,
|
|
Dashboard,
|
|
|
XHRUpload,
|
|
XHRUpload,
|
|
|
|
|
+ ImageEditor,
|
|
|
} from "https://releases.transloadit.com/uppy/v4.13.3/uppy.min.mjs";
|
|
} from "https://releases.transloadit.com/uppy/v4.13.3/uppy.min.mjs";
|
|
|
let current = {};
|
|
let current = {};
|
|
|
|
|
|
|
@@ -139,8 +140,8 @@ let NEWSITEEDITOR = (function () {
|
|
|
function view() {
|
|
function view() {
|
|
|
$("#view").click(function () {
|
|
$("#view").click(function () {
|
|
|
//remove attr conteneditable sinon bug avec tinyMCE
|
|
//remove attr conteneditable sinon bug avec tinyMCE
|
|
|
- tinymce.remove();
|
|
|
|
|
- tinymce.activeEditor.remove();
|
|
|
|
|
|
|
+ //tinymce.remove();
|
|
|
|
|
+ //tinymce.activeEditor.remove();
|
|
|
$(".mce-item-table").removeClass("mce-item-table");
|
|
$(".mce-item-table").removeClass("mce-item-table");
|
|
|
|
|
|
|
|
$("#undo, #redo, #sidebarToggle, #manager, #view").css(
|
|
$("#undo, #redo, #sidebarToggle, #manager, #view").css(
|
|
@@ -164,6 +165,7 @@ let NEWSITEEDITOR = (function () {
|
|
|
sidebar(false);
|
|
sidebar(false);
|
|
|
linkEnabled(true);
|
|
linkEnabled(true);
|
|
|
nseImageEditor(false);
|
|
nseImageEditor(false);
|
|
|
|
|
+ nseVideoEditor(false);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -236,6 +238,7 @@ let NEWSITEEDITOR = (function () {
|
|
|
sidebar(true);
|
|
sidebar(true);
|
|
|
linkEnabled(false);
|
|
linkEnabled(false);
|
|
|
nseImageEditor(true);
|
|
nseImageEditor(true);
|
|
|
|
|
+ nseVideoEditor(true);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -855,6 +858,43 @@ let NEWSITEEDITOR = (function () {
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
reader.readAsDataURL(file.data);
|
|
reader.readAsDataURL(file.data);
|
|
|
|
|
+
|
|
|
|
|
+ document.getElementById("cropper-cancel").addEventListener("click", () => {
|
|
|
|
|
+ document.getElementById("cropper-modal").classList.remove("active");
|
|
|
|
|
+ if (cropper) {
|
|
|
|
|
+ cropper.destroy();
|
|
|
|
|
+ cropper = null;
|
|
|
|
|
+ }
|
|
|
|
|
+ pendingFile = null;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ document.getElementById("cropper-confirm").addEventListener("click", () => {
|
|
|
|
|
+ if (!cropper || !pendingFile) return;
|
|
|
|
|
+
|
|
|
|
|
+ cropper.getCroppedCanvas().toBlob((blob) => {
|
|
|
|
|
+ uppy.removeFile(pendingFile.id);
|
|
|
|
|
+
|
|
|
|
|
+ const ts = new Date()
|
|
|
|
|
+ .toISOString()
|
|
|
|
|
+ .replace(/[-:.]/g, "")
|
|
|
|
|
+ .replace("Z", "");
|
|
|
|
|
+
|
|
|
|
|
+ uppy.addFile({
|
|
|
|
|
+ name: ts + ".png",
|
|
|
|
|
+ type: pendingFile.type,
|
|
|
|
|
+ data: blob,
|
|
|
|
|
+ meta: {
|
|
|
|
|
+ isCropped: true,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // Nettoyage
|
|
|
|
|
+ document.getElementById("cropper-modal").classList.remove("active");
|
|
|
|
|
+ cropper.destroy();
|
|
|
|
|
+ cropper = null;
|
|
|
|
|
+ pendingFile = null;
|
|
|
|
|
+ }, pendingFile.type);
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function showNseModal(shouldShow) {
|
|
function showNseModal(shouldShow) {
|
|
@@ -863,6 +903,508 @@ let NEWSITEEDITOR = (function () {
|
|
|
}
|
|
}
|
|
|
//Fin du nseImageEditor
|
|
//Fin du nseImageEditor
|
|
|
|
|
|
|
|
|
|
+ //nseBgImageEditor
|
|
|
|
|
+ function nseBgImageEditor() {
|
|
|
|
|
+ const elems = document.querySelectorAll(".bgimageeditor");
|
|
|
|
|
+
|
|
|
|
|
+ elems.forEach((elem) => {
|
|
|
|
|
+ // 1) Extraction de l'URL du background
|
|
|
|
|
+ elem.addEventListener(
|
|
|
|
|
+ "click",
|
|
|
|
|
+ (e) => {
|
|
|
|
|
+ elem.style.borderTop = "10px solid red";
|
|
|
|
|
+ elem.style.borderBottom = "10px solid red";
|
|
|
|
|
+
|
|
|
|
|
+ const bg = getComputedStyle(elem).backgroundImage; // ex: 'url("…/votre-image.jpg")'
|
|
|
|
|
+ const urlMatch = bg.match(/url\(["']?(.*?)["']?\)/);
|
|
|
|
|
+ if (!urlMatch) return; // pas d'image → on skip
|
|
|
|
|
+ const imgUrl = urlMatch[1];
|
|
|
|
|
+
|
|
|
|
|
+ // 2) Chargement de l'image pour lire sa taille naturelle
|
|
|
|
|
+ const img = new Image();
|
|
|
|
|
+ let Iw, Ih;
|
|
|
|
|
+ img.onload = () => {
|
|
|
|
|
+ Iw = img.naturalWidth;
|
|
|
|
|
+ Ih = img.naturalHeight;
|
|
|
|
|
+ elem.style.backgroundSize = "cover";
|
|
|
|
|
+ };
|
|
|
|
|
+ img.src = imgUrl;
|
|
|
|
|
+
|
|
|
|
|
+ // 3) Variables de drag
|
|
|
|
|
+ let isDragging = false;
|
|
|
|
|
+ let startX, startY;
|
|
|
|
|
+ let origX = 0,
|
|
|
|
|
+ origY = 0;
|
|
|
|
|
+
|
|
|
|
|
+ //Gestion du zoom
|
|
|
|
|
+ let zoom = 1;
|
|
|
|
|
+ const zoomStep = 0.05;
|
|
|
|
|
+ const minZoom = 0.5;
|
|
|
|
|
+ const maxZoom = 3;
|
|
|
|
|
+
|
|
|
|
|
+ // Récupérer la pos courante (px → nombre)
|
|
|
|
|
+ function getBgPos() {
|
|
|
|
|
+ const [x, y] = getComputedStyle(elem).backgroundPosition.split(" ");
|
|
|
|
|
+ return [parseFloat(x) || 0, parseFloat(y) || 0];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function calculateBackgroundSize(zoom, size, elem) {
|
|
|
|
|
+ elem.style.backgroundSize = zoom * size + "px";
|
|
|
|
|
+ console.log(zoom * size);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ elem.addEventListener("mousedown", (e) => {
|
|
|
|
|
+ e.preventDefault();
|
|
|
|
|
+ isDragging = true;
|
|
|
|
|
+ [origX, origY] = getBgPos();
|
|
|
|
|
+ startX = e.clientX;
|
|
|
|
|
+ startY = e.clientY;
|
|
|
|
|
+ elem.style.cursor = "grabbing";
|
|
|
|
|
+ // on fixe no-repeat pour éviter la répétition
|
|
|
|
|
+ elem.style.backgroundRepeat = "no-repeat";
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ document.addEventListener("mousemove", (e) => {
|
|
|
|
|
+ if (!isDragging) return;
|
|
|
|
|
+ const dx = e.clientX - startX;
|
|
|
|
|
+ const dy = e.clientY - startY;
|
|
|
|
|
+ let nx = origX + dx;
|
|
|
|
|
+ let ny = origY + dy;
|
|
|
|
|
+
|
|
|
|
|
+ // 4) Clamp : une fois l'image chargée
|
|
|
|
|
+ const Cw = elem.clientWidth;
|
|
|
|
|
+ const Ch = elem.clientHeight;
|
|
|
|
|
+ if (Iw && Ih) {
|
|
|
|
|
+ console.log(
|
|
|
|
|
+ `Cadre largeur : ${Cw}, Cadre hauteur : ${Ch}\nImage largeur ${Iw}, Image hauteur ${Ih}`
|
|
|
|
|
+ );
|
|
|
|
|
+ // bornes horizontales
|
|
|
|
|
+
|
|
|
|
|
+ /*
|
|
|
|
|
+ * Ih et Iw : Height et width de l'image d'origine (source)
|
|
|
|
|
+ * Ch et Cw : Height et width du cadre (canvas)
|
|
|
|
|
+ * minX : Taille minimale de la position du background-position sur l'axe horizontal en px.
|
|
|
|
|
+ * maxX : Taille maximale de la position du background-position sur l'axe horizontal en px.
|
|
|
|
|
+ * minY : Taille minimale de la position du background-position sur l'axe vertical en px.
|
|
|
|
|
+ * maxY : Taille minimale de la position du background-position sur l'axe vertical en px.
|
|
|
|
|
+ * nx et ny : Position du background-position manipulé par l'utilisateur.
|
|
|
|
|
+ */
|
|
|
|
|
+ const minX = Math.min(Cw - Iw * zoom, 0);
|
|
|
|
|
+ const maxX = 0;
|
|
|
|
|
+ // bornes verticales
|
|
|
|
|
+ const minY = Math.min(Ch - Ih * zoom, 0);
|
|
|
|
|
+ const maxY = 0;
|
|
|
|
|
+ // clamp X et Y
|
|
|
|
|
+ nx = Math.max(minX, Math.min(maxX, nx));
|
|
|
|
|
+ ny = Math.max(minY, Math.min(maxY, ny));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ elem.style.backgroundPosition = `${0}px ${ny}px`;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ document.addEventListener("mouseup", () => {
|
|
|
|
|
+ if (!isDragging) return;
|
|
|
|
|
+ isDragging = false;
|
|
|
|
|
+ elem.style.cursor = "";
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // éviter la sélection de texte/image native
|
|
|
|
|
+ elem.addEventListener("dragstart", (e) => e.preventDefault());
|
|
|
|
|
+ },
|
|
|
|
|
+ { once: true }
|
|
|
|
|
+ );
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ let posterUppy = null;
|
|
|
|
|
+ let videoUppy = null;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Editeur vidéo du newSiteEditor, permet de modifier la source, le poster, le titre et l'ariaLabel
|
|
|
|
|
+ * @param {boolean} enable - Active ou désactive l'éditeur vidéo.
|
|
|
|
|
+ */
|
|
|
|
|
+ function nseVideoEditor(enable) {
|
|
|
|
|
+ //C'est un truc plus ou moins comme les records en typescript
|
|
|
|
|
+ const videoInfos = new Map();
|
|
|
|
|
+
|
|
|
|
|
+ const buttonId = "videoEditorButton";
|
|
|
|
|
+ const videoBackgroundID = "modalNseVideoBackground";
|
|
|
|
|
+ const nextToVideo = "nextToVideo";
|
|
|
|
|
+ const backToPoster = "backToPoster";
|
|
|
|
|
+ const videoTitleInput = "videoTitle";
|
|
|
|
|
+ const closeButtonID = "closeVideoModal";
|
|
|
|
|
+ const ariaLabelInput = "ariaLabel";
|
|
|
|
|
+ const submitVideoEditorID = "submitVideoEditor";
|
|
|
|
|
+ const posterPreview = document.getElementById("posterPreview");
|
|
|
|
|
+ const videoPreview = document.getElementById("videoPreview");
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Affiche la modal à l'écran
|
|
|
|
|
+ */
|
|
|
|
|
+ function showModal() {
|
|
|
|
|
+ document.getElementById(videoBackgroundID).style.display = "flex";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Cache la modal et réinitialise tout les uppys
|
|
|
|
|
+ */
|
|
|
|
|
+ function hideModal() {
|
|
|
|
|
+ document.getElementById(videoBackgroundID).style.display = "none";
|
|
|
|
|
+ posterUppy?.cancelAll();
|
|
|
|
|
+ videoUppy?.cancelAll();
|
|
|
|
|
+ showPosterStep();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Affiche l'étape du poster
|
|
|
|
|
+ */
|
|
|
|
|
+ function showPosterStep() {
|
|
|
|
|
+ document.querySelector("#modalPosterNse").style.display = "block";
|
|
|
|
|
+ document.querySelector("#modalVideoNse").style.display = "none";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Affiche l'étape d'édition de vidéo avec les infos actuelles.
|
|
|
|
|
+ * @param {Object} info - Informations sur la vidéo.
|
|
|
|
|
+ * @param {string} info.title - Titre de la vidéo.
|
|
|
|
|
+ * @param {string} info.aria - Aria-label de la vidéo.
|
|
|
|
|
+ */
|
|
|
|
|
+ function showVideoStep(info) {
|
|
|
|
|
+ document.querySelector("#modalPosterNse").style.display = "none";
|
|
|
|
|
+ document.querySelector("#modalVideoNse").style.display = "block";
|
|
|
|
|
+ document.getElementById("videoTitle").value = info.title;
|
|
|
|
|
+ document.getElementById("ariaLabel").value = info.aria;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Initialise les écouteurs d'évenements nécessaires à l'éditeur.
|
|
|
|
|
+ */
|
|
|
|
|
+ function setupEventListeners() {
|
|
|
|
|
+ document.getElementById(buttonId).addEventListener("click", () => {
|
|
|
|
|
+ const button = document.getElementById(buttonId);
|
|
|
|
|
+ button.style.display = "none";
|
|
|
|
|
+
|
|
|
|
|
+ const currentId = button.getAttribute("data-currentId");
|
|
|
|
|
+ const info = videoInfos.get(currentId);
|
|
|
|
|
+
|
|
|
|
|
+ showModal();
|
|
|
|
|
+ document.body.addEventListener("keyup", (e) => {
|
|
|
|
|
+ if (e.code === "Escape") {
|
|
|
|
|
+ hideModal();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ posterPreview.src = info.poster;
|
|
|
|
|
+ videoPreview.src = info.src;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ document
|
|
|
|
|
+ .getElementById(videoBackgroundID)
|
|
|
|
|
+ .addEventListener("click", (event) => {
|
|
|
|
|
+ if (event.target.id === videoBackgroundID) {
|
|
|
|
|
+ hideModal();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ document.getElementById(closeButtonID).addEventListener("click", () => {
|
|
|
|
|
+ hideModal();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ document.getElementById(nextToVideo).addEventListener("click", () => {
|
|
|
|
|
+ const info = getCurrentButtonInfo();
|
|
|
|
|
+ showVideoStep(info);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ document.getElementById(backToPoster).addEventListener("click", () => {
|
|
|
|
|
+ showPosterStep();
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ document.querySelectorAll(".videoeditor").forEach((el) => {
|
|
|
|
|
+ const videoInfo = extractVideoInfo(videojs(el.id));
|
|
|
|
|
+ videoInfos.set(el.id, videoInfo);
|
|
|
|
|
+
|
|
|
|
|
+ el.addEventListener("click", (event) => {
|
|
|
|
|
+ event.stopPropagation();
|
|
|
|
|
+ event.stopImmediatePropagation();
|
|
|
|
|
+ updateReplaceButtonPositionAndDataId(event.pageX, event.pageY, el.id);
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ document
|
|
|
|
|
+ .getElementById(submitVideoEditorID)
|
|
|
|
|
+ .addEventListener("click", () => {
|
|
|
|
|
+ submitModal();
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Extrait les informations d'une vidéo à partir du player video.js.
|
|
|
|
|
+ * @param {Object} player - Instance du lecteur video.js.
|
|
|
|
|
+ * @returns {{poster: string, title: string, aria: string, src: string}} - Informations extraites.
|
|
|
|
|
+ */
|
|
|
|
|
+ function extractVideoInfo(player) {
|
|
|
|
|
+ const sources = Array.from(player.el().querySelectorAll("source")).map(
|
|
|
|
|
+ (s) => ({ src: s.src, type: s.type })
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ return {
|
|
|
|
|
+ poster: player.poster(),
|
|
|
|
|
+ title: player.el().title,
|
|
|
|
|
+ aria: player.el().getAttribute("aria-label"),
|
|
|
|
|
+ src: sources[0]?.src,
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Crée le bouton flottant "Edit video" s'il n'existe pas déjà.
|
|
|
|
|
+ */
|
|
|
|
|
+ function createReplaceButton() {
|
|
|
|
|
+ const replaceButton = document.createElement("button");
|
|
|
|
|
+ replaceButton.innerText = "Edit video";
|
|
|
|
|
+ replaceButton.id = buttonId;
|
|
|
|
|
+ replaceButton.classList.add("defaultNseButton");
|
|
|
|
|
+ replaceButton.setAttribute("data-movable", true);
|
|
|
|
|
+ replaceButton.style.display = "none";
|
|
|
|
|
+ document.body.append(replaceButton);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Met à jour la position du bouton "Edit video" et le data-id courant.
|
|
|
|
|
+ * @param {number} x - Position X du clic.
|
|
|
|
|
+ * @param {number} y - Position Y du clic.
|
|
|
|
|
+ * @param {string} videoId - ID de la vidéo cliquée.
|
|
|
|
|
+ */
|
|
|
|
|
+ function updateReplaceButtonPositionAndDataId(x, y, videoId) {
|
|
|
|
|
+ const replaceButton = document.getElementById(buttonId);
|
|
|
|
|
+ if (!replaceButton) return;
|
|
|
|
|
+
|
|
|
|
|
+ Object.assign(replaceButton.style, {
|
|
|
|
|
+ display: "block",
|
|
|
|
|
+ left: x + "px",
|
|
|
|
|
+ top: y + "px",
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ replaceButton.setAttribute("data-currentId", videoId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Initialise les instances Uppy pour le poster et la vidéo.
|
|
|
|
|
+ * @returns {[Uppy, Uppy]} - Instances Uppy pour le poster et la vidéo.
|
|
|
|
|
+ */
|
|
|
|
|
+ function initializeUppy() {
|
|
|
|
|
+ const poster = createPosterUppy();
|
|
|
|
|
+ const video = createVideoUppy();
|
|
|
|
|
+ return [poster, video];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Détruit les instances Uppy existantes (poster et vidéo).
|
|
|
|
|
+ */
|
|
|
|
|
+ function closeUppy() {
|
|
|
|
|
+ if (posterUppy) {
|
|
|
|
|
+ const posterDash = posterUppy.getPlugin("Dashboard");
|
|
|
|
|
+ if (posterDash && typeof posterDash.destroy === "function") {
|
|
|
|
|
+ posterDash.destroy();
|
|
|
|
|
+ }
|
|
|
|
|
+ posterUppy = null;
|
|
|
|
|
+
|
|
|
|
|
+ const posterContainer = document.querySelector("#uppy-poster");
|
|
|
|
|
+ if (posterContainer) posterContainer.innerHTML = "";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (videoUppy) {
|
|
|
|
|
+ const videoDash = videoUppy.getPlugin("Dashboard");
|
|
|
|
|
+ if (videoDash && typeof videoDash.destroy === "function") {
|
|
|
|
|
+ videoDash.destroy();
|
|
|
|
|
+ }
|
|
|
|
|
+ videoUppy = null;
|
|
|
|
|
+
|
|
|
|
|
+ const videoContainer = document.querySelector("#uppy-video");
|
|
|
|
|
+ if (videoContainer) videoContainer.innerHTML = "";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Crée l'instance Uppy pour le poster.
|
|
|
|
|
+ * @returns {Uppy} - Instance Uppy configurée pour les images.
|
|
|
|
|
+ */
|
|
|
|
|
+ function createPosterUppy() {
|
|
|
|
|
+ const uppy = new Uppy({
|
|
|
|
|
+ restrictions: {
|
|
|
|
|
+ maxNumberOfFiles: 1,
|
|
|
|
|
+ allowedFileTypes: [".jpg", ".jpeg", ".png", ".webp"],
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ uppy.use(Dashboard, {
|
|
|
|
|
+ inline: true,
|
|
|
|
|
+ target: "#uppy-poster",
|
|
|
|
|
+ showAddFilesButton: false,
|
|
|
|
|
+ hideUploadButton: true,
|
|
|
|
|
+ height: 400,
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ uppy.use(ImageEditor, {
|
|
|
|
|
+ target: Dashboard,
|
|
|
|
|
+ cropperOptions: {
|
|
|
|
|
+ viewMode: 1,
|
|
|
|
|
+ autoCropArea: 1,
|
|
|
|
|
+ aspectRatio: 16 / 9,
|
|
|
|
|
+ },
|
|
|
|
|
+ actions: {
|
|
|
|
|
+ revert: false,
|
|
|
|
|
+ rotate: false,
|
|
|
|
|
+ flip: false,
|
|
|
|
|
+ granularRotate: false,
|
|
|
|
|
+ cropSquare: false,
|
|
|
|
|
+ cropWidescreen: false,
|
|
|
|
|
+ cropWidescreenVertical: false,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ uppy.on("file-added", (file) => {
|
|
|
|
|
+ uppy.getPlugin("Dashboard").openFileEditor(file);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ uppy.on("file-editor:complete", (file) => {
|
|
|
|
|
+ const objectURL = URL.createObjectURL(file.data);
|
|
|
|
|
+ posterPreview.src = objectURL;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ uppy.on("file-removed", () => {
|
|
|
|
|
+ const info = getCurrentButtonInfo();
|
|
|
|
|
+ posterPreview.src = info.poster;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ uppy.on("cancel-all", () => {
|
|
|
|
|
+ if (!enable) return;
|
|
|
|
|
+ const info = getCurrentButtonInfo();
|
|
|
|
|
+ posterPreview.src = info.poster;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ return uppy;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Crée l'instance Uppy pour la vidéo.
|
|
|
|
|
+ * @returns {Uppy} - Instance Uppy configurée pour les vidéos.
|
|
|
|
|
+ */
|
|
|
|
|
+ function createVideoUppy() {
|
|
|
|
|
+ const uppy = new Uppy({
|
|
|
|
|
+ restrictions: {
|
|
|
|
|
+ maxNumberOfFiles: 1,
|
|
|
|
|
+ allowedFileTypes: [".mp4", ".webm"],
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ uppy.use(Dashboard, {
|
|
|
|
|
+ inline: true,
|
|
|
|
|
+ target: "#uppy-video",
|
|
|
|
|
+ showAddFilesButton: false,
|
|
|
|
|
+ hideUploadButton: true,
|
|
|
|
|
+ height: 200,
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ uppy.on("file-added", (file) => {
|
|
|
|
|
+ videoPreview.src = URL.createObjectURL(file.data);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ uppy.on("file-removed", () => {
|
|
|
|
|
+ const info = getCurrentButtonInfo();
|
|
|
|
|
+ videoPreview.src = info.src;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ uppy.on("cancel-all", () => {
|
|
|
|
|
+ if (!enable) return;
|
|
|
|
|
+ const info = getCurrentButtonInfo();
|
|
|
|
|
+ videoPreview.src = info.src;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ return uppy;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Récupère les informations de la vidéo actuellement sélectionnée.
|
|
|
|
|
+ * @returns {{poster: string, title: string, aria: string, src: string}} - Infos vidéo actuelle.
|
|
|
|
|
+ */
|
|
|
|
|
+ function getCurrentButtonInfo() {
|
|
|
|
|
+ const button = document.getElementById(buttonId);
|
|
|
|
|
+ const currentId = button.getAttribute("data-currentId");
|
|
|
|
|
+ const info = videoInfos.get(currentId);
|
|
|
|
|
+ return info;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Soumet les données modifiées du modal au serveur.
|
|
|
|
|
+ * Met à jour les infos de la Map et le player video.js en conséquence.
|
|
|
|
|
+ */
|
|
|
|
|
+ async function submitModal() {
|
|
|
|
|
+ const poster = posterUppy.getFiles()[0];
|
|
|
|
|
+ const video = videoUppy.getFiles()[0];
|
|
|
|
|
+ const title = document.getElementById(videoTitleInput)?.value?.trim();
|
|
|
|
|
+ const ariaLabel = document.getElementById(ariaLabelInput)?.value?.trim();
|
|
|
|
|
+
|
|
|
|
|
+ const button = document.getElementById(buttonId);
|
|
|
|
|
+ const currentId = button.getAttribute("data-currentId");
|
|
|
|
|
+
|
|
|
|
|
+ if (!poster && !video && !title && !ariaLabel) {
|
|
|
|
|
+ hideModal();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const formData = new FormData();
|
|
|
|
|
+
|
|
|
|
|
+ if (poster) formData.append("poster", poster.data, poster.name);
|
|
|
|
|
+ if (video) formData.append("video", video.data, video.name);
|
|
|
|
|
+ if (title) formData.append("title", title);
|
|
|
|
|
+ if (ariaLabel) formData.append("ariaLabel", ariaLabel);
|
|
|
|
|
+ formData.append("videoId", Math.random() * 10000000);
|
|
|
|
|
+
|
|
|
|
|
+ const response = await fetch("http://localhost/php/test.php", {
|
|
|
|
|
+ method: "POST",
|
|
|
|
|
+ body: formData,
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ const result = await response.json();
|
|
|
|
|
+
|
|
|
|
|
+ const videoOldInfo = videoInfos.get(currentId);
|
|
|
|
|
+
|
|
|
|
|
+ videoInfos.set(currentId, {
|
|
|
|
|
+ poster: result.files.poster
|
|
|
|
|
+ ? "http://localhost/php/" + result.files.poster
|
|
|
|
|
+ : videoOldInfo.poster,
|
|
|
|
|
+ src: result.files.video
|
|
|
|
|
+ ? "http://localhost/php/" + result.files.video
|
|
|
|
|
+ : videoOldInfo.src,
|
|
|
|
|
+ title: result.title ?? videoOldInfo.title,
|
|
|
|
|
+ aria: result.text ?? videoOldInfo.aria,
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ const player = videojs(currentId);
|
|
|
|
|
+ player.poster("http://localhost/php/" + result.files.poster);
|
|
|
|
|
+ player.src({
|
|
|
|
|
+ src: "http://localhost/php/" + result.files.video,
|
|
|
|
|
+ type: "video/mp4",
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ hideModal();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!enable) {
|
|
|
|
|
+ closeUppy();
|
|
|
|
|
+ hideModal();
|
|
|
|
|
+ document.getElementById(buttonId).remove();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ createReplaceButton();
|
|
|
|
|
+ setupEventListeners();
|
|
|
|
|
+
|
|
|
|
|
+ if (!posterUppy || !videoUppy) {
|
|
|
|
|
+ [posterUppy, videoUppy] = initializeUppy();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// to set data-data for every element when opening the page
|
|
// to set data-data for every element when opening the page
|
|
|
$(".siteeditor").each(function () {
|
|
$(".siteeditor").each(function () {
|
|
|
dataData(this);
|
|
dataData(this);
|
|
@@ -888,6 +1430,7 @@ let NEWSITEEDITOR = (function () {
|
|
|
|
|
|
|
|
//nseFileEditor
|
|
//nseFileEditor
|
|
|
//nseImageEditor(false);
|
|
//nseImageEditor(false);
|
|
|
|
|
+ nseBgImageEditor();
|
|
|
|
|
|
|
|
// define the public API
|
|
// define the public API
|
|
|
var API = {};
|
|
var API = {};
|