/* RainLoop Webmail (c) RainLoop Team | MIT */ (()=>{"use strict";var e={},n={},t=jQuery;function o(e,n){this.oXhrs={},this.oUids={},this.oJua=e,this.oOptions=n}function i(t){t=n.isUndefined(t)?{}:t;var i=this,r=jQuery;i.bEnableDnD=!0,i.oEvents={onDialog:null,onSelect:null,onStart:null,onComplete:null,onCompleteAll:null,onProgress:null,onDragEnter:null,onDragLeave:null,onDrop:null,onBodyDragEnter:null,onBodyDragLeave:null,onLimitReached:null},i.oOptions=n.extend({action:"",name:"",hidden:{},queueSize:10,clickElement:!1,dragAndDropElement:!1,dragAndDropBodyElement:!1,disableDragAndDrop:!1,disableMultiple:!1,disableDocumentDropPrevent:!1,multipleSizeLimit:50},t),i.oQueue=function(e){function n(){if(t&&r{};return arguments.length<1&&(e=1/0),i.defer=function(){if(!u){var e=arguments;e.index=++l,o?(o.next=e,o=o.next):t=o=e,++a,n()}return i},i.await=function(e){return p=e,a||p(u,s),i},i}(n.pInt(n.getValue(i.oOptions,"queueSize",10))),i.runEvent("onCompleteAll")&&i.oQueue.await(function(){i.runEvent("onCompleteAll")}),i.oDriver=new o(i,i.oOptions),i.oClickElement=n.getValue(i.oOptions,"clickElement",null),i.oClickElement&&(r(i.oClickElement).css({position:"relative",overflow:"hidden"}),"inline"===r(this.oClickElement).css("display")&&r(this.oClickElement).css("display","inline-block"),this.oDriver.generateNewInput(this.oClickElement)),this.oDriver.isDragAndDropSupported()&&n.getValue(this.oOptions,"dragAndDropElement",!1)?function(t){var o=r(window.document),i=r(n.getValue(t.oOptions,"dragAndDropBodyElement",!1)||o),a=n.getValue(t.oOptions,"dragAndDropElement",!1);a&&(n.getValue(t.oOptions,"disableDocumentDropPrevent",!1)||o.on("dragover",function(e){if(t.bEnableDnD&&e&&(e=n.getEvent(e))&&e.dataTransfer&&n.eventContainsFiles(e))try{e.dataTransfer.dropEffect="none",e.preventDefault()}catch(e){}}),i&&i[0]&&i.on("dragover",function(e){t.bEnableDnD&&e&&n.mainClearTimeout(t.iDocTimer)}).on("dragenter",function(e){t.bEnableDnD&&e&&(e=n.getEvent(e))&&n.eventContainsFiles(e)&&(n.mainClearTimeout(t.iDocTimer),e.preventDefault(),t.runEvent("onBodyDragEnter",[e]))}).on("dragleave",function(e){t.bEnableDnD&&e&&(e=n.getEvent(e))&&(n.mainClearTimeout(t.iDocTimer),t.iDocTimer=setTimeout(function(){t.runEvent("onBodyDragLeave",[e])},200))}).on("drop",function(e){if(t.bEnableDnD&&e&&(e=n.getEvent(e))){var o=n.eventContainsFiles(e);return o&&e.preventDefault(),t.runEvent("onBodyDragLeave",[e]),!o}return!1}),r(a).bind("dragenter",function(e){t.bEnableDnD&&e&&(e=n.getEvent(e))&&n.eventContainsFiles(e)&&(n.mainClearTimeout(t.iDocTimer),e.preventDefault(),t.runEvent("onDragEnter",[a,e]))}).bind("dragover",function(e){if(t.bEnableDnD&&e&&(e=n.getEvent(e))&&e.dataTransfer&&n.eventContainsFiles(e))try{var o=e.dataTransfer.effectAllowed;n.mainClearTimeout(t.iDocTimer),e.dataTransfer.dropEffect="move"===o||"linkMove"===o?"move":"copy",e.stopPropagation(),e.preventDefault(),i.trigger("dragover",e)}catch(e){}}).bind("dragleave",function(e){if(t.bEnableDnD&&e&&(e=n.getEvent(e))){var o=window.document.elementFromPoint?window.document.elementFromPoint(e.clientX,e.clientY):null;if(o&&n.contains(this,o))return;n.mainClearTimeout(t.iDocTimer),t.runEvent("onDragLeave",[a,e])}}).bind("drop",function(o){t.bEnableDnD&&o&&(o=n.getEvent(o))&&n.eventContainsFiles(o)&&(o.preventDefault(),n.getDataFromDragEvent(o,function(e){e&&(t.runEvent("onDrop",[e,o]),t.addNewFile(e),n.mainClearTimeout(t.iDocTimer))},n.getValue(t.oOptions,"multipleSizeLimit",e.iDefLimit),t.getEvent("onLimitReached"))),t.runEvent("onDragLeave",[o])}))}(i):i.bEnableDnD=!1,n.setValue(i,"on",i.on),n.setValue(i,"cancel",i.cancel),n.setValue(i,"isDragAndDropSupported",i.isDragAndDropSupported),n.setValue(i,"setDragAndDropEnabledStatus",i.setDragAndDropEnabledStatus)}e.iDefLimit=20,n.isUndefined=function(e){return void 0===e},n.extend=function(e,n){if(n)for(var t in n)n.hasOwnProperty(t)&&(e[t]=n[t]);return e},n.contains=function(e,n){var t=!1;return e&&n&&(t=e===n||(e.contains?e.contains(n):!!n.compareDocumentPosition&&!!(8&n.compareDocumentPosition(e)))),t},n.mainClearTimeout=function(e){0i&&r&&(c=!0,r(a)))},n.getDataFromInput=function(e,t,o,i){var r=e&&e.files&&0').css({opacity:0})},n.createNextInput=function(){return t('')},n.getNewInput=function(e,t){e=n.isUndefined(e)?"":e.toString();var o=n.createNextInput();return 0!0),o.prototype.regTaskUid=function(e){this.oUids[e]=!0},o.prototype.uploadTask=function(e,o,i){if(!1===this.oUids[e]||!o||!o.File)return i(null,e),!1;try{var r=this,a=new XMLHttpRequest,l=new FormData,u=n.getValue(this.oOptions,"action",""),s=n.getValue(this.oOptions,"hidden",{}),p=this.oJua.getEvent("onStart"),d=this.oJua.getEvent("onComplete"),c=this.oJua.getEvent("onProgress");return a.open("POST",u,!0),c&&a.upload&&(a.upload.onprogress=function(t){t&&t.lengthComputable&&!n.isUndefined(t.loaded)&&!n.isUndefined(t.total)&&c(e,t.loaded,t.total)}),a.onreadystatechange=function(){if(4===a.readyState&&200===a.status){if(d){var o=!1,l=null;try{l=t.parseJSON(a.responseText),o=!0}catch(e){l=null}d(e,o,l)}n.isUndefined(r.oXhrs[e])||(r.oXhrs[e]=null),i(null,e)}else 4===a.readyState&&(d(e,!1,null),i(null,e))},p&&p(e),l.append("jua-post-type","ajax"),l.append(n.getValue(this.oOptions,"name","juaFile"),o.File),t.each(s,function(e,t){l.append(e,n.getStringOrCallFunction(t,[o]))}),a.send(l),this.oXhrs[e]=a,!0}catch(e){}return i(null,e),!1},o.prototype.generateNewInput=function(o){var i=this,r=null,a=null;o&&(a=n.getNewInput("",!n.getValue(this.oOptions,"disableMultiple",!1)),(r=n.createNextLabel()).append(a),t(o).append(r),a.on("click",function(){var e=i.oJua.getEvent("onDialog");e&&e()}).on("change",function(){n.getDataFromInput(this,function(e){i.oJua.addNewFile(e),i.generateNewInput(o),setTimeout(function(){r.remove()},10)},n.getValue(i.oOptions,"multipleSizeLimit",e.iDefLimit),i.oJua.getEvent("onLimitReached"))}))},o.prototype.cancel=function(e){if(this.oUids[e]=!1,this.oXhrs[e]){try{this.oXhrs[e].abort&&this.oXhrs[e].abort()}catch(e){}this.oXhrs[e]=null}},i.prototype.bEnableDnD=!0,i.prototype.iDocTimer=0,i.prototype.oOptions={},i.prototype.oEvents={},i.prototype.oQueue=null,i.prototype.oDriver=null,i.prototype.on=function(e,n){return this.oEvents[e]=n,this},i.prototype.runEvent=function(e,n){this.oEvents[e]&&this.oEvents[e].apply(null,n||[])},i.prototype.getEvent=function(e){return this.oEvents[e]||null},i.prototype.cancel=function(e){this.oDriver.cancel(e)},i.prototype.setDragAndDropEnabledStatus=function(e){this.bEnableDnD=!!e},i.prototype.isDragAndDropSupported=function(){return this.oDriver.isDragAndDropSupported()},i.prototype.addNewFile=function(e){this.addFile(n.getNewUid(),e)},i.prototype.addFile=function(e,t){var o=this.getEvent("onSelect");!t||o&&!1===o(e,t)?this.oDriver.cancel(e):(this.oDriver.regTaskUid(e),this.oQueue.defer(n.scopeBind(this.oDriver.uploadTask,this.oDriver),e,t))},window.Jua=i})();