var tdbFormGallery={};jQuery().ready(function(){tdbFormGallery.init()});
(function(){tdbFormGallery={items:[],item:function(){this.blockObj=this.uid="";this.smoothScroll=!0;this.fileExtensions=["jpg","jpeg","png","gif","ico"];this.maxUploadSize=0;this.uploadLimit=-1;this.uploadedCount=0;this._is_initialized=this._in_composer=!1},init:function(){tdbFormGallery.items=[];this._is_running=!1},addItem:function(a){if("undefined"===typeof a.uid)throw"item.uid is not defined";tdbFormGallery.items.push(a);tdbFormGallery._initialize_item(a)},deleteItem:function(a){for(var b=0;b<
tdbFormGallery.items.length;b++)if(tdbFormGallery.items[b].uid===a)return tdbFormGallery.items.splice(b,1),!0;return!1},resetItems:function(){tdbFormGallery.items=[]},manageNotif:function(a,b,c){c=void 0===c?"":c;a=a.blockObj.find(".tdb-s-notif");b?(b=a.find("ul"),a.is(":hidden")&&a.show(),b.append("<li>"+c+"</li>")):a.hide()},addToPreview:function(a,b){var c=a.blockObj.find(".tdb-s-form-file"),e=a.blockObj.find(".tdb-fg-inputs");c.addClass("tdb-s-content-loading");setTimeout(function(){var a=new FileReader;
a.onload=function(){c.before('<div class="tdb-fg-item"><div class="tdb-fg-item-inner"><img class="tdb-fgi-img" src="'+a.result+'" /><div class="tdb-fgi-del">X</div></div></div>');var d=jQuery('<input type="file" class="tdb-fg-input" />'),f=new DataTransfer;f.items.add(b);d.prop("files",f.files);e.append(d)};a.readAsDataURL(b);c.removeClass("tdb-s-content-loading")},600)},_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")});var c=a.blockObj.find(".tdb-s-form-file input");c.on("change",function(b){var e=b.currentTarget.files;tdbFormGallery.manageNotif(a,!1);var d=-1!==a.uploadLimit&&a.uploadedCount>=a.uploadLimit;Object.keys(e).forEach(function(b){d?-1!==a.uploadLimit&&a.uploadedCount>=a.uploadLimit&&tdbFormGallery.manageNotif(a,!0,"You have exceeded the maximum number of images that you can upload ("+a.uploadLimit+")."):(b=e[b],
-1===jQuery.inArray(b.name.split(".").pop().toLowerCase(),a.fileExtensions)?tdbFormGallery.manageNotif(a,!0,"<strong>"+b.name+"</strong>: You are not allowed to upload this file type."):b.size>a.maxUploadSize?tdbFormGallery.manageNotif(a,!0,"<strong>"+b.name+"</strong>: The image exceeds the maximum upload file size limit."):(tdbFormGallery.addToPreview(a,b),a.uploadedCount++,-1!==a.uploadLimit&&a.uploadedCount>=a.uploadLimit&&(c.closest(".tdb-s-form-file").addClass("tdb-s-form-file-disabled"),d=
!0)))})});a.blockObj.on("click",".tdb-fgi-del",function(b){b.preventDefault();jQuery(this).closest(".tdb-fg-item").remove();a.uploadedCount--; -1!==a.uploadLimit&&a.uploadedCount<a.uploadLimit&&(b=a.blockObj.find(".tdb-s-form-file"),b.hasClass("tdb-s-form-file-disabled")&&b.removeClass("tdb-s-form-file-disabled"))});a._is_initialized=!0}}}})();
