ConvertForms.Helper.onReady(function(e){var i,s;"undefined"!=typeof Dropzone&&(i=ConvertForms.Helper.getBaseURL("task=field.ajax&field_type=fileupload"),s=ConvertForms.Helper.getCSRFToken(),Dropzone.autoDiscover=!1,e.forEach(function(a){var e=a.querySelectorAll(".cfupload"),l=[];e.forEach(function(o){var e=o.closest(".cf-control-input").querySelector(".cfup-tmpl"),t=e.innerHTML;e.closest(".cf-control-input").removeChild(e);var e=parseFloat(o.getAttribute("data-maxfilesize"))||null,r=parseInt(o.getAttribute("data-maxfiles"))||null,n=a.querySelector("button.cf-btn"),e=new Dropzone(o,((t={url:i,previewTemplate:t,maxFilesize:e,uploadMultiple:1!=r,maxFiles:r,acceptedFiles:o.getAttribute("data-acceptedfiles"),autoProcessQueue:!0,parallelUploads:1,filesizeBase:1e3,createImageThumbnails:!1,timeout:0,dictFallbackMessage:ConvertForms.Helper.text("COM_CONVERTFORMS_UPLOAD_FALLBACK_MESSAGE"),dictInvalidFileType:ConvertForms.Helper.text("COM_CONVERTFORMS_UPLOAD_INVALID_FILE")}).dictFallbackMessage=ConvertForms.Helper.text("COM_CONVERTFORMS_UPLOAD_FALLBACK_MESSAGE"),t.dictFileTooBig=ConvertForms.Helper.text("COM_CONVERTFORMS_UPLOAD_FILETOOBIG"),t.dictResponseError=ConvertForms.Helper.text("COM_CONVERTFORMS_UPLOAD_RESPONSE_ERROR"),t.dictCancelUpload=ConvertForms.Helper.text("COM_CONVERTFORMS_UPLOAD_CANCEL_UPLOAD"),t.dictCancelUploadConfirmation=ConvertForms.Helper.text("COM_CONVERTFORMS_UPLOAD_CANCEL_UPLOAD_CONFIRMATION"),t.dictRemoveFile=ConvertForms.Helper.text("COM_CONVERTFORMS_UPLOAD_REMOVE_FILE"),t.dictMaxFilesExceeded=ConvertForms.Helper.text("COM_CONVERTFORMS_UPLOAD_MAX_FILES_EXCEEDED"),t));n&&(e.on("queuecomplete",function(){n.classList.remove("cf-disabled")}),e.on("processing",function(){n.classList.add("cf-disabled")})),e.on("sending",function(e,t,r){r.append("form_id",o.closest("form").querySelector("input[name='cf[form_id]']").value),r.append("field_key",o.getAttribute("data-key")),t.setRequestHeader("X-CSRF-Token",s),r.append(s,1)}),e.on("success",function(e){var t=e.xhr.response;try{t=JSON.parse(t)}catch(e){var r=t.match(/{([^}]*)}/i);null!==r?t=JSON.parse(r[0]):alert("Error! "+e+"<br>"+t)}r=document.createElement("input");r.setAttribute("type","hidden"),r.setAttribute("name",o.dataset.name),r.setAttribute("value",t.file),e.previewTemplate.appendChild(r)}),l.push(e)}),a.addEventListener("beforeSubmit",function(e){var r;e.defaultPrevented||(r=0,l.forEach(function(e){var t=e.getQueuedFiles().length,e=e.getUploadingFiles().length;r=r+t+e}),0<r&&(e.preventDefault(),e.detail.error=e.detail.instance.text("ERROR_WAIT_FILE_UPLOADS")))}),a.addEventListener("success",function(){l.forEach(function(e){e.removeAllFiles()})})}))});

