var tdbFormFileUpload={};jQuery().ready(function(){tdbFormFileUpload.init()});
(function(){tdbFormFileUpload={items:[],item:function(){this.blockObj=this.uid="";this.fileType="image";this.fileExtensions=["jpg","jpeg","png","gif","ico"];this.maxUploadSize=0;this._is_initialized=this._in_composer=!1},init:function(){tdbFormFileUpload.items=[];this._is_running=!1},_initialize_item:function(a){if(!0!==a._is_initialized){var b=a.blockObj.find(".tdb-s-form-file");b.bind("dragover",function(){jQuery(this).addClass("tdb-s-form-file-dragover")});b.bind("dragleave drop",function(){jQuery(this).removeClass("tdb-s-form-file-dragover")});
a.blockObj.find(".tdb-s-form-file input").on("change",function(b){var c=jQuery(this);b=b.currentTarget.files[0];tdbFormFileUpload.manageNotif(a,!1);-1===jQuery.inArray(c.val().split(".").pop().toLowerCase(),a.fileExtensions)?(tdbFormFileUpload.manageNotif(a,!0,"Sorry, you are not allowed to upload this "+a.fileType+" file type."),c.val("")):b.size>a.maxUploadSize?(tdbFormFileUpload.manageNotif(a,!0,"Sorry, the "+a.fileType+" exceeds the maximum upload file size limit."),c.val("")):tdbFormFileUpload.addPreview(a,
b)});a.blockObj.on("click",".tdb-s-ffp-remove",function(b){b.preventDefault();tdbFormFileUpload.removePreview(a)});a._is_initialized=!0}},addItem:function(a){if("undefined"===typeof a.uid)throw"item.uid is not defined";tdbFormFileUpload.items.push(a);tdbFormFileUpload._initialize_item(a)},manageNotif:function(a,b,c){c=void 0===c?"":c;a=a.blockObj.find(".tdb-s-notif");b?a.show().text(c):a.hide().text(c)},addPreview:function(a,b){a.blockObj.find(".tdb-s-form");var c=a.blockObj.find(".tdb-s-form-file");
c.addClass("tdb-s-content-loading");setTimeout(function(){switch(a.fileType){case "image":var d=new FileReader;d.onload=function(){c.prepend('<div class="tdb-s-form-file-preview tdb-s-form-file-preview-image"><div class="tdb-s-ffip-img" style="background-image:url('+d.result+')"></div><button class="tdb-s-btn tdb-s-btn-sm tdb-s-btn-red tdb-s-ffp-remove" title="Remove image file"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-trash-2"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line></svg></button></div>')};
d.readAsDataURL(b);break;case "document":c.prepend('<div class="tdb-s-form-file-box tdb-s-form-file-preview tdb-s-form-file-preview-document"><svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-file-text tdb-s-ffu-ico"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><line x1="16" y1="13" x2="8" y2="13"></line><line x1="16" y1="17" x2="8" y2="17"></line><polyline points="10 9 9 9 8 9"></polyline></svg><div class="tdb-s-ffu-txt">'+
b.name+'</div><button class="tdb-s-btn tdb-s-btn-sm tdb-s-btn-red tdb-s-ffp-remove" title="Remove file"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-trash-2"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line></svg></button></div>');
break;case "audio":var e=new FileReader;e.onload=function(){c.prepend('<div class="tdb-s-form-file-preview tdb-s-form-file-preview-audio"><audio controls class="tdb-s-ffu-audio"><source src="'+e.result+'" type="'+b.type+'"></audio><button class="tdb-s-btn tdb-s-btn-sm tdb-s-btn-red tdb-s-ffp-remove" title="Remove audio file"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-trash-2"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line></svg></button></div>')};
e.readAsDataURL(b);break;case "video":var f=new FileReader;f.onload=function(){c.prepend('<div class="tdb-s-form-file-preview tdb-s-form-file-preview-video"><video class="tdb-s-ffip-video" controls><source src="'+f.result+'" type="'+b.type+'"></video><button class="tdb-s-btn tdb-s-btn-sm tdb-s-btn-red tdb-s-ffp-remove" title="Remove video file"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-trash-2"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line></svg></button></div>')};
f.readAsDataURL(b)}c.addClass("tdb-s-form-file-previewing");c.removeClass("tdb-s-content-loading")},600)},removePreview:function(a){var b=a.blockObj.find(".tdb-s-form-file"),c=b.find(".tdb-s-form-file-input");b.addClass("tdb-s-content-loading");setTimeout(function(){a.blockObj.attr("data-no-save","false");b.find(".tdb-s-form-file-preview").remove();c.val("");b.removeClass("tdb-s-form-file-previewing");b.removeClass("tdb-s-content-loading")},400)},deleteItem:function(a){for(var b=0;b<tdbFormFileUpload.items.length;b++)if(tdbFormFileUpload.items[b].uid===
a)return tdbFormFileUpload.items.splice(b,1),!0;return!1},resetItems:function(){tdbFormFileUpload.items=[]}}})();
