|
@@ -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,7 +903,6 @@ let NEWSITEEDITOR = (function () {
|
|
|
}
|
|
}
|
|
|
//Fin du nseImageEditor
|
|
//Fin du nseImageEditor
|
|
|
|
|
|
|
|
- //nseBgImageEditor
|
|
|
|
|
//nseBgImageEditor
|
|
//nseBgImageEditor
|
|
|
function nseBgImageEditor() {
|
|
function nseBgImageEditor() {
|
|
|
const elems = document.querySelectorAll(".bgimageeditor");
|
|
const elems = document.querySelectorAll(".bgimageeditor");
|
|
@@ -971,13 +1010,323 @@ let NEWSITEEDITOR = (function () {
|
|
|
|
|
|
|
|
// éviter la sélection de texte/image native
|
|
// éviter la sélection de texte/image native
|
|
|
elem.addEventListener("dragstart", (e) => e.preventDefault());
|
|
elem.addEventListener("dragstart", (e) => e.preventDefault());
|
|
|
-
|
|
|
|
|
},
|
|
},
|
|
|
{ once: true }
|
|
{ once: true }
|
|
|
);
|
|
);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ let posterUppy = null;
|
|
|
|
|
+ let videoUppy = null;
|
|
|
|
|
+
|
|
|
|
|
+ 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");
|
|
|
|
|
+
|
|
|
|
|
+ //Si le nse est désactivé
|
|
|
|
|
+ if (!enable) {
|
|
|
|
|
+ closeUppy();
|
|
|
|
|
+ hideModal();
|
|
|
|
|
+ document.getElementById(buttonId).remove();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ createReplaceButton();
|
|
|
|
|
+ setupEventListeners();
|
|
|
|
|
+
|
|
|
|
|
+ if (!posterUppy || !videoUppy) {
|
|
|
|
|
+ [posterUppy, videoUppy] = initializeUppy();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //Fonctions pour les Modals
|
|
|
|
|
+ function showModal() {
|
|
|
|
|
+ document.getElementById(videoBackgroundID).style.display = "flex";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function hideModal() {
|
|
|
|
|
+ document.getElementById(videoBackgroundID).style.display = "none";
|
|
|
|
|
+ posterUppy?.cancelAll();
|
|
|
|
|
+ videoUppy?.cancelAll();
|
|
|
|
|
+ showPosterStep();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //Fonctions pour le stepper
|
|
|
|
|
+ function showPosterStep() {
|
|
|
|
|
+ document.querySelector("#modalPosterNse").style.display = "block";
|
|
|
|
|
+ document.querySelector("#modalVideoNse").style.display = "none";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //Initialiser les event listeners
|
|
|
|
|
+ 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();
|
|
|
|
|
+ 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();
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //Récuperer les infos des vidéos
|
|
|
|
|
+ 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,
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //On crée le bouton une seule fois
|
|
|
|
|
+ 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);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //Quand l'utilisateur click sur une video ca met a jour la position
|
|
|
|
|
+ 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);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //On initialise le uppy de la vidéo et du poster
|
|
|
|
|
+ function initializeUppy() {
|
|
|
|
|
+ const poster = createPosterUppy();
|
|
|
|
|
+ const video = createVideoUppy();
|
|
|
|
|
+ return [poster, video];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // On détruit les instances de Uppy
|
|
|
|
|
+ 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 = "";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function getCurrentButtonInfo() {
|
|
|
|
|
+ const button = document.getElementById(buttonId);
|
|
|
|
|
+ const currentId = button.getAttribute("data-currentId");
|
|
|
|
|
+ const info = videoInfos.get(currentId);
|
|
|
|
|
+ return info;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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();
|
|
|
|
|
+
|
|
|
|
|
+ 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);
|
|
|
|
|
+
|
|
|
|
|
+ await fetch("http://localhost/php/test.php", {
|
|
|
|
|
+ method: "POST",
|
|
|
|
|
+ body: formData,
|
|
|
|
|
+ })
|
|
|
|
|
+ .then((res) => res.json())
|
|
|
|
|
+ .then(console.log)
|
|
|
|
|
+ .then(hideModal())
|
|
|
|
|
+ .catch(console.error);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 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);
|