PHP Classes

File: js/main.min.js

Recommend this page to a friend!
  Classes of Victor Andeloci   WordPress Attachments Plugin for Posts and Pages   js/main.min.js   Download  
File: js/main.min.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: WordPress Attachments Plugin for Posts and Pages
Attach files to WordPress posts with a metabox
Author: By
Last change:
Date: 10 months ago
Size: 4,309 bytes
 

Contents

Class file image Download
var fappAtachments=[];function docReady(t){"complete"===document.readyState||"interactive"===document.readyState?setTimeout(t,1):document.addEventListener("DOMContentLoaded",t)}function loader(t,e="start"){if(document.getElementById(t))switch(e){case"start":document.getElementById(t).innerHTML+='<div class="lds-ring"><div></div><div></div><div></div><div></div></div>';break;case"stop":document.getElementById(t).querySelector(".lds-ring").remove()}}function getAttachmentDetails(t,e,a=null,n=null,c=null){let i=document.getElementById("attachmentDialog");i.querySelector("#fapp_attachmentTitle").value=e,i.querySelector("#fapp_attachmentDescription").value=a,i.querySelector("#fapp_attachmentTitleShow").innerHTML=e,i.querySelector("#fapp_attachmentFileUrl").value=t,null!=n&&i.querySelector("#fapp_attachmentSend").setAttribute("data-key",n),null!=c&&i.querySelector("#fapp_attachmentCoverImageShow").setAttribute("src",c),i.classList.add("attach-dialog-show")}function uploadAttachCover(t){loader("fapp_attachmentSend");let e=new FormData;e.append("file",t,t.name),e.append("action","fappUploadImage");let a=new XMLHttpRequest;a.open("POST",wpApiUrl,!0),a.onload=function(){if(this.status>=200&&this.status<400){let t=this.response;null!=t&&""!=t&&(document.getElementById("fapp_attachmentCoverImageShow").setAttribute("src",t),loader("fapp_attachmentSend","stop"))}else console.log("Internal Server Error!\n"+this.response)},a.onerror=function(){console.log("Request error...")},a.send(e)}function closeAttachmentDialog(){document.getElementById("fapp_attachmentSend").removeAttribute("data-key"),document.getElementById("attachmentDialog").classList.remove("attach-dialog-show")}Dropzone.autoDiscover=!1,docReady(function(){null!=fileList&&""!=fileList&&(fappAtachments=JSON.parse(fileList));new Dropzone("div#attachmentDropzone",{dictDefaultMessage:"Drop files here",init:function(){this.on("success",function(t,e){getAttachmentDetails(e,t.name)})}});if(document.getElementById("attachmentDialog")){document.getElementById("fapp_attachmentTitle").addEventListener("change",function(){document.getElementById("fapp_attachmentTitleShow").innerHTML=this.value});let t=document.getElementById("fapp_attachmentCoverImage");t.addEventListener("change",function(){uploadAttachCover(t.files[0])}),document.getElementById("fapp_attachmentSend").addEventListener("click",function(){let t={name:document.getElementById("fapp_attachmentTitle").value,description:document.getElementById("fapp_attachmentDescription").value,cover_image:document.getElementById("fapp_attachmentCoverImageShow").getAttribute("src"),url:document.getElementById("fapp_attachmentFileUrl").value};if(this.getAttribute("data-key")){let e=this.getAttribute("data-key");fappAtachments[e]=t,console.log(e);let a=document.getElementById("attachment_"+e);console.log(a),a.querySelector("span").innerHTML=t.name}else{fappAtachments.push(t);let e='<li class="att-item" id="attachment_'+(fappAtachments.length-1)+'"><span>'+t.name+'</span><div class="action-btns"><a title="Open" class="link-btn" href="'+t.url+'" target="blank" rel="noopener noreferrer"><i>?</i></a><i title="Details" data-key="'+(fappAtachments.length-1)+'" class="edit-btn">&#128393;</i><i title="Remove" data-key="'+(fappAtachments.length-1)+'" class="remove-btn">?</i></div></li>';document.getElementById("attachmentsContainer").innerHTML+=e}document.getElementById("fapp_attachment_list").value=JSON.stringify(fappAtachments),closeAttachmentDialog()}),document.getElementById("closeAttachmentDialog").addEventListener("click",function(){closeAttachmentDialog()})}document.addEventListener("click",function(t){for(var e=t.target;e&&e!=this;e=e.parentNode)if(e.matches(".remove-btn"))fappAtachments.splice(e.getAttribute("data-key"),1),document.getElementById("fapp_attachment_list").value=JSON.stringify(fappAtachments),e.parentNode.parentNode.remove(),document.getElementById("attachmentsContainer").querySelectorAll("li").forEach((t,e)=>{t.setAttribute("id","attachment_"+e),t.querySelector(".edit-btn").setAttribute("data-key",e),t.querySelector(".remove-btn").setAttribute("data-key",e)});else if(e.matches(".edit-btn")){let t=fappAtachments[e.getAttribute("data-key")];getAttachmentDetails(t.url,t.name,t.description,e.getAttribute("data-key"),t.cover_image)}})});