var FPF_MediaUploader=function(){function e(){this.initEvents()}var t=e.prototype;return t.initEvents=function(){document.addEventListener("click",function(e){this.initAddButton(e),this.initRemoveButton(e)}.bind(this))},t.initAddButton=function(e){var r=e.target.closest(".fpf-media-uploader-add");if(r){var a=r.closest(".fpf-media-uploader-wrapper"),d=a.getAttribute("data-media"),t="image";"url"==d&&(t="audio");var l=wp.media({title:"Insert media file",library:{type:t},button:{text:"Use this media file"},multiple:!1}).on("select",function(){var e=l.state().get("selection").first().toJSON();r.classList.add("added-item");var t=a.querySelector('input[type="hidden"]');t.value=e.url;var i=new Event("input",{bubbles:!0,cancelable:!0});t.dispatchEvent(i),a.querySelector(".fpf-media-uploader-remove").classList.add("is-visible"),d&&("image"==d?a.querySelector(".fpf-media-uploader-preview img").setAttribute("src",e.url):"url"==d&&(a.querySelector(".preview-url").innerHTML=e.url),a.querySelector(".fpf-media-uploader-preview").classList.add("is-visible"))}).open();e.preventDefault()}},t.initRemoveButton=function(e){var t=e.target.closest(".fpf-media-uploader-remove");if(t){var i=t.closest(".fpf-media-uploader-wrapper"),r=i.getAttribute("data-media");i.querySelector(".fpf-media-uploader-add").classList.remove("added-item"),i.querySelector('input[type="hidden"]').value="",i.querySelector(".fpf-media-uploader-remove").classList.remove("is-visible"),r&&("image"==r?i.querySelector(".fpf-media-uploader-preview img").setAttribute("src",""):"url"==r&&(i.querySelector(".preview-url").innerHTML=""),i.querySelector(".fpf-media-uploader-preview").classList.remove("is-visible")),e.preventDefault()}},e}();document.addEventListener("DOMContentLoaded",function(e){new FPF_MediaUploader});

