芝麻web文件管理V1.00
编辑当前文件:/home/asmplong/www/sdfoiuhzufgh/js/script_modif.js
function saveForm (url, callback, suffixe) { // FONCTION DE SAUVEGARDE FORULAIRE TEXTE var formulaire = 'formulaire'+suffixe; formulaire = document.getElementById(formulaire); data = new FormData(formulaire); ajaxPost('traitement_maj.php'+url, data, callback); } var tableModif = document.getElementById('tableCacheText').value; var idModif = document.getElementById('idCacheText').value; function recupererHtml () { // RECUP AUTO DU HTML DE L'EDITEUR POUR CHRGMT BDD document.getElementById('mirroirModif').textContent = contenu.innerHTML; } setInterval(recupererHtml, 1); /* ------------------------------------------------------------------------ */ /* ------------------------------- EDITEUR -------------------------------- */ var divBoutons = document.getElementById("divBoutons"); var contenu = document.getElementById("contenuModif"); function toucheEntree (e) { if (e.charCode === 13) { var listeBalise = document.getElementById("formatBlock"); listeBalise.classList.add(listeBalise.value); if (listeBalise.classList.contains("p")) { commande("formatBlock", "p"); } else { document.getElementById("formatBlock").value = "p"; } listeBalise.classList.remove("p"); listeBalise.classList.remove("h2"); listeBalise.classList.remove("h3"); listeBalise.classList.remove("h4"); } } function commande(nom, argument) { if (typeof argument === 'undefined') { argument = ""; } switch (nom) { case "createLink": argument = prompt("Quelle est l'adresse du lien ?"); var regexUrl = /^(http|https):\/\//; if (!regexUrl.test(argument)) { argument = "http://" + argument; } break; case "insertImage": var nomPhoto = prompt("Quelle image souhaitez-vous inserer ?"); argument = "../images/" + tableModif + "/" + idModif + "/" + nomPhoto; break; } document.execCommand(nom, false, argument); if (!document.getElementById(nom).classList.contains("actif")) { document.getElementById(nom).src = "../images/editeur/" + nom + "Actif.png"; document.getElementById(nom).classList.add("actif"); } else { document.getElementById(nom).src = "../images/editeur/" + nom + ".png"; document.getElementById(nom).classList.remove("actif"); } } var commandesBouton = [ "bold", "italic", "underline", "insertUnorderedList", "insertOrderedList", "createLink", "insertImage", "justifyLeft", "justifyCenter", "justifyRight", "justifyFull", "insertHorizontalRule"]; var commandesListe = [ "foreColor", "formatBlock"]; commandesBouton.forEach(function(commandeBouton) { document.getElementById(commandeBouton).addEventListener("click", function(e) { commande(e.target.id); }); }); /* document.getElementById("insertImage").addEventListener("click", function(e) { /*popIn.init(); popIn2(); });*/ commandesListe.forEach(function(commandeListe) { document.getElementById(commandeListe).addEventListener("change", function(e) { commande(e.target.id, e.target.value); }); }); commandesBouton.forEach(function(commandeBouton) { contenu.addEventListener("click", function () { var boutonClique = document.getElementById(commandeBouton) if(document.queryCommandState(commandeBouton)) { boutonClique.src = "../images/editeur/" + commandeBouton + "Actif.png"; boutonClique.classList.add("actif"); boutonClique.style.margin = "auto 1 auto 1"; } else { boutonClique.src = "../images/editeur/" + commandeBouton + ".png"; boutonClique.classList.remove("actif"); boutonClique.style.margin = "auto 2 auto 2"; } }); }); document.addEventListener("keypress", toucheEntree); /* --------------------------------- FIN ---------------------------------- */ /* ------------------------------------------------------------------------ */ document.getElementById('validerText').addEventListener('click', function(e){ // MAJ BDD DEPUIS PAGE MODIF e.preventDefault(); saveForm('', function(reponse){ alert ('Article sauvegardé'); if (tableModif === 'contact' || tableModif === 'partenaire') { document.location.href="liste_modif.php"; } else { document.location.href="liste_modif.php?table="+tableModif; } }, 'Text'); }); var supprElts = document.querySelectorAll("#imagesModif a"); // SUPPRESSION DE PHOTO + MAJ BDD supprElts.forEach(function(supprElt) { supprElt.addEventListener('click', function(e){ e.preventDefault(); if (confirm('Etes-vous sur de vouloir supprimer la photo ' + this.id + ' ?')) { saveForm ('?url='+this.id, function (reponse){ location.reload(); }, 'Text'); } }); }); document.getElementById('envoyerPhoto').addEventListener('click', function(e){ // UPLOAD PHOTO e.preventDefault(); saveForm('', function(reponse){ saveForm('', function(reponse){ }, 'Text'); location.reload(); }, 'Image'); }); if (document.getElementById('lienEncadrant') !== null) { // AFFICHAGE GESTION VIGNETTE ENCADRANT document.getElementById('lienEncadrant').addEventListener('click', function(e){ e.preventDefault(); var encadrantElt = document.getElementById('divFormulaireCreaEncadrant'); if (encadrantElt.style.display == 'none') { encadrantElt.style.display = 'block'; } else { encadrantElt.style.display = 'none'; } }); document.getElementById('validerEncadrant').addEventListener('click', function(e){ // CREATION VIGNETTE ENCADRANT e.preventDefault(); var encadrantPhotoElt = document.getElementById('encadrantPhoto'); var encadrantNomElt = document.getElementById('encadrantNom'); if (encadrantNomElt.value !== '' && encadrantPhotoElt.files.length !== 0) { saveForm('', function(reponse){ saveForm('', function(reponse){}, 'Text'); alert ('Vignette(s) créée(s)'); location.reload(); }, 'CreaEncadrant'); } else { if (encadrantNomElt.value == '') { encadrantNomElt.style.border = '3px red solid'; } if (encadrantPhotoElt.files.length == 0) { encadrantPhotoElt.style.border = '3px red solid'; } alert('Merci de renseigner tout les champs'); } encadrantPhotoElt.addEventListener('change', function(e) { encadrantPhotoElt.style.border = ''; }); encadrantNomElt.addEventListener('change', function(e) { encadrantNomElt.style.border = ''; }); }); } /* ------------------------------------------------------------ */ /* ------------------ PREVISUALISATION IMAGE ----------------- */ /* ------------------------------------------------------------ */ function previsualisationPhoto (divPrev, fichierCharge, zonePrev, largeurPrev, extensionsAutorisee) { function createThumbnail2(file) { var reader = new FileReader(); reader.addEventListener('load', function() { if(document.getElementById(divPrev) !== null) { prev.removeChild(document.getElementById(divPrev)); } var imgElement = document.createElement('img'); imgElement.style.maxHeight = '100px'; imgElement.src = this.result; imgElement.id = divPrev; prev.appendChild(imgElement); }); reader.readAsDataURL(file); } var allowedTypes = extensionsAutorisee, fileInput = document.querySelector(fichierCharge), prev = document.querySelector(zonePrev); var files = fileInput.files, filesLen = files.length, imgType; for (var i = 0; i < filesLen; i++) { imgType = files[i].name.split('.'); imgType = imgType[imgType.length - 1]; imgType = imgType.toLowerCase(); if (allowedTypes.indexOf(imgType) != -1) { createThumbnail2(files[i]); } else { alert ('l\'extension de la photo n\'est pas supportée'); } } } var extensionsAutorisee = ['png', 'jpg', 'jpeg', 'gif']; if (document.querySelector('#encadrantPhoto') !== null) { document.querySelector('#encadrantPhoto').addEventListener('change', function() { previsualisationPhoto ('prevPhotoEncadrant', '#encadrantPhoto', '#divPrevPhotoEncadrant', '99px', extensionsAutorisee); }); } document.querySelector('#recupPhoto').addEventListener('change', function() { previsualisationPhoto ('prevPhoto', '#recupPhoto', '#divPrevPhoto2', '150px', extensionsAutorisee); }); /* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */ document.getElementById('bouttonAnnuler').addEventListener('click', function(e){ // CLIC SUR BOUTON ANNULER e.preventDefault(); var tableRedirect = document.getElementById('tableCacheText').value; if (tableRedirect === 'contact' || tableRedirect === 'partenaire') { document.location.href="liste_modif.php"; } else{ document.location.href="liste_modif.php?table="+tableRedirect; } }); var popIn = { init: function(){ document.getElementById('popin').style.display = "block"; var dimH = this.dimensionH(); var dimW = this.dimensionW(); document.getElementById('popin-contenu').style.top = (dimH/2)-300+"px"; document.getElementById('popin-contenu').style.left = (dimW/2)-500+"px"; let photoElts = document.querySelectorAll("#popinImagesModif img"); photoElts.forEach(function(photoElt) { photoElt.addEventListener('click', function(e){ popIn.insertImage(photoElt.src); console.log(photoElt); photoElt = ''; return; }); }); this.close(); console.log(photoElts); return; }, insertImage: function(lienImage){ commande("insertImage", lienImage); document.getElementById('popin').style.display = "none"; photoElts = ''; return; }, close: function(){ document.getElementById('popin-close').addEventListener('click', function(){ document.getElementById('popin').style.display = "none"; return; }); document.getElementById('popin-aplat').addEventListener('click', function(){ document.getElementById('popin').style.display = "none"; return; }); return; }, dimensionW: function(){ if (window.innerWidth) return window.innerWidth; else{return document.window.width();} }, dimensionH: function(){ if (window.innerHeight) return window.innerHeight; else{return document.window.height();} } }; function popIn2 () { document.getElementById('popin').style.display = "block"; if (window.innerHeight){ var dimH = window.innerHeight; } else{ var dimH = document.window.height(); } if (window.innerWidth){ var dimW = window.innerWidth; } else{ var dimW = document.window.Width(); } document.getElementById('popin-contenu').style.top = (dimH/2)-300+"px"; document.getElementById('popin-contenu').style.left = (dimW/2)-500+"px"; var photoElts = document.querySelectorAll("#popinImagesModif img"); photoElts.forEach(function(photoElt) { photoElt.addEventListener('click', function(e){ commande("insertImage", photoElt.src); document.getElementById('popin').style.display = "none"; }); }); document.getElementById('popin-close').addEventListener('click', function(){ document.getElementById('popin').style.display = "none"; }); document.getElementById('popin-aplat').addEventListener('click', function(){ document.getElementById('popin').style.display = "none"; }); return false; }