/*
 * Title                   : DOT Framework
 * File                    : framework/assets/js/min/file.js
 * Author                  : Dot on Paper
 * Copyright               : © 2021 Dot on Paper
 * Website                 : https://dotonpaper.net
 * Description             : Minified -> DOT File jQuery plugin.
 */

(function($){$.fn.DOTFile=function(options){"use strict";let Data={textChoose:"Choose a file",textChooseMultiple:"Choose some files",textDisabled:"The field is disabled.",textDrag:"or drag it here.",textDragMultiple:"or drag them here.",textFormats:"Formats accepted",textFormatsVal:"All",textNo:"Maximum number of files at once",textNoVal:"10",textSize:"Maximum file size",textSizeVal:"8MB"},Wrapper=this,ID="",id="",name="",accept="",classes="",onChange="",isDisabled=!1,isMultiple=!1,textChoose=Data.textChoose,textChooseMultiple=Data.textChooseMultiple,textDisabled=Data.textDisabled,textDrag=Data.textDrag,textDragMultiple=Data.textDragMultiple,textFormats=Data.textFormats,textFormatsVal=Data.textFormatsVal,textNo=Data.textNo,textNoVal=Data.textNoVal,textSize=Data.textSize,textSizeVal=Data.textSizeVal,methods={init:function(){return this.each(function(){options&&$.extend(Data,options),methods.parse()})},parse:function(){const t=$(Wrapper);id=void 0!==t.attr("id")?t.attr("id"):"",name=void 0!==t.attr("name")?t.attr("name"):"",accept=void 0!==t.attr("accept")?t.attr("accept"):"",classes=void 0!==t.attr("class")?t.attr("class"):"",onChange=void 0!==t.attr("onchange")?t.attr("onchange"):"",isDisabled=void 0!==t.attr("disabled"),isMultiple=void 0!==t.attr("multiple"),ID=""!==id?id:name,textChoose=Data.textChoose,textChooseMultiple=Data.textChooseMultiple,textDisabled=Data.textDisabled,textDrag=Data.textDrag,textDragMultiple=Data.textDragMultiple,textFormats=Data.textFormats,textFormatsVal=Data.textFormatsVal,textNo=Data.textNo,textNoVal=Data.textNoVal,textSize=Data.textSize,textSizeVal=Data.textSizeVal,methods.display(),methods.events()},display:function(){const t=$(Wrapper);let e=[];e.push('<div id="dot-file-'+ID+'" class="dot-file'+(isDisabled?" dot-file-disabled":"")+'">'),e.push(' <span class="dot-file-icon dot-icon-interface-files"></span>'),e.push(' <input type="file"'),e.push(' id="'+ID+'"'),e.push(' name="'+name+'"'),e.push(' class="dot-file-input'+(""!==classes?" "+classes:"")+'"'),e.push(""!==accept?' accept="'+accept+'"':""),e.push(isDisabled?' disabled="disabled"':""),e.push(isMultiple?' multiple="multiple"':""),e.push(" />"),e.push(' <label class="dot-file-label" for="'+ID+'">'),isDisabled?e.push(textDisabled):(e.push('<span class="dot-file-label-choose">'+(isMultiple?textChooseMultiple:textChoose)+"</span>&nbsp;"),e.push('<span class="dot-file-label-drag">'+(isMultiple?textDragMultiple:textDrag)+"</span>"),e.push('<br /><br /><span class="dot-file-label-info">'+textFormats+": <strong>"+textFormatsVal+"</strong><br />"+textNo+": <strong>"+textNoVal+"</strong><br />"+textSize+": <strong>"+textSizeVal+"</strong></span>")),e.push(" </label>"),e.push(' <span id="dot-file-list-'+ID+'" class="dot-file-list"></span>'),e.push("</div>"),t.replaceWith(e.join(""))},events:function(){const $body=$("body"),$file=$("#dot-file-"+ID),$ID=$("#"+ID);let files=!1;if($body.off("dragend dragover dragleave drop"),$body.on("dragend dragover dragleave drop",function(t){t.preventDefault(),t.stopPropagation()}),$file.off("drag dragstart dragend dragover dragenter dragleave drop"),$file.on("drag dragstart dragend dragover dragenter dragleave drop",function(t){t.preventDefault(),t.stopPropagation()}),isDisabled)return!1;$file.off("drop"),$file.on("drop",function(t){if(t.preventDefault(),t.stopPropagation(),files=t.originalEvent.dataTransfer.files,!isMultiple&&files.length>1)return!1;$ID.prop("files",files),$ID.trigger("change")}),$ID.off("change"),$ID.on("change",function(){const $this=$(this);methods.list($this.prop("files")),""!==onChange&&eval(onChange)})},list:function(t){const e=$("#dot-file-list-"+ID);let a=[];$.each(t,function(t,e){a.push("<br />"+e.name)}),e.html(a.join(""))}};return methods.init.apply(this)}})(jQuery);