snappymail/vendors/jua/jua.min.js

22 lines
9.2 KiB
JavaScript
Raw Normal View History

2013-12-09 06:14:55 +08:00
(function(){function a(a){function l(){if(g&&d<a){var b=g,c=b[0],f=Array.prototype.slice.call(b,1),m=b.index;g===h?g=h=null:g=g.next,++d,f.push(function(a,b){--d;if(i)return;a?e&&k(i=a,e=j=g=h=null):(j[m]=b,--e?l():k(null,j))}),c.apply(null,f)}}var c={},d=0,e=0,f=-1,g,h,i=null,j=[],k=b;return arguments.length<1&&(a=Infinity),c.defer=function(){if(!i){var a=arguments;a.index=++f,h?(h.next=a,h=h.next):g=h=a,++e,l()}return c},c.await=function(a){return k=a,e||k(i,j),c},c}function b(){}typeof module=="undefined"?self.queue=a:module.exports=a,a.version="0.0.2"})();var e=!0,f=null,h=!1,j,k=jQuery,l=window,m=queue;function q(a){return"undefined"===typeof a}function r(a){0<a&&clearTimeout(a)}function u(a){a=a&&(a.originalEvent?a.originalEvent:a)||l.event;return a.dataTransfer?a:f}function v(a,b,c){return!a||!b||q(a[b])?c:a[b]}function w(){for(var a=16,b="",a=q(a)?32:parseInt(a||0,10);b.length<a;)b+="0123456789abcdefghijklmnopqrstuvwxyz".substr(Math.round(36*Math.random()),1);return"jua-uid-"+b+"-"+(new Date).getTime().toString()}
function z(a,b){return{FileName:q(a.fileName)?q(a.name)?f:a.name:a.fileName,Size:q(a.fileSize)?q(a.size)?f:a.size:a.fileSize,Type:q(a.type)?f:a.type,Folder:q(b)?"":b,File:a}}
function A(a,b,c,g,d,i){function n(a,b,s,c){if(a&&!q(a.name))if(b=b||"",a.isFile)a.file(function(a){!x||0<=--d?s(z(a,b)):x&&!y&&(0>d&&i)&&(y=e,i(t))});else if(g&&a.isDirectory&&a.createReader){var p=a.createReader(),o=0,C=0;p&&p.readEntries&&p.readEntries(function(d){if(d&&d&&d.length&&0<d.length){o=0;for(C=d.length;o<C;o++)n(d[o],b+a.name+"/",s,c)}})}}var t=0,s=0,p=0,o=f,o=f,x=h,y=h,g=q(g)?e:!!g,c=q(c)?h:!!c,t=d=q(d)?B.o:parseInt(d||0,10),x=0<d;if(a=a&&0<a.length?a:f){p=0;for(s=a.length;p<s;p++)if(o=
a[p])c?"file"===o.kind&&o.webkitGetAsEntry&&(o=o.webkitGetAsEntry())&&n(o,"",b,i):!x||0<=--d?b(z(o)):x&&!y&&(0>d&&i)&&(y=e,i(t))}}function D(a,b,c,g){var d=a&&a.files&&0<a.files.length?a.files:f;d?A(d,b,h,h,c,g):b({FileName:a.value.split("\\").pop().split("/").pop(),Size:f,Type:f,Folder:"",File:f})}
function E(a){var b=h;if(a&&a.dataTransfer&&a.dataTransfer.types&&a.dataTransfer.types.length)for(var c=0,g=a.dataTransfer.types.length;c<g;c++)if("files"===a.dataTransfer.types[c].toLowerCase()){b=e;break}return b}function F(){return k('<label style="position: absolute; background-color:#fff; right: 0px; top: 0px; left: 0px; bottom: 0px; margin: 0px; padding: 0px; cursor: pointer;"></label>').css({opacity:0})}
function G(a,b){var a=q(a)?"":a.toString(),c=k('<input type="file" tabindex="-1" hidefocus="hidefocus" style="position: absolute; left: -9999px;" />');0<a.length&&c.attr("name",a);(q(b)||b)&&c.prop("multiple",e);return c}function H(a,b){return k.isFunction(a)?a.apply(f,k.isArray(b)?b:[]).toString():a.toString()}function I(a,b){this.i={};this.f={};this.b=a;this.a=b}function J(a,b){this.f={};this.j={};this.b=a;this.a=b}
function B(a){var a=q(a)?{}:a,b=this;b.c=e;b.m={onDialog:f,onSelect:f,onStart:f,onComplete:f,onCompleteAll:f,onProgress:f,onDragEnter:f,onDragLeave:f,onDrop:f,onBodyDragEnter:f,onBodyDragLeave:f,onLimitReached:f};var c={action:"",name:"",hidden:{},queueSize:10,clickElement:h,dragAndDropElement:h,dragAndDropBodyElement:h,disableAjaxUpload:h,disableFolderDragAndDrop:e,disableDragAndDrop:h,disableMultiple:h,disableDocumentDropPrevent:h,multipleSizeLimit:50};if(a)for(var g in a)a.hasOwnProperty(g)&&(c[g]=
a[g]);b.a=c;b.q=m(parseInt(v(b.a,"queueSize",10)||0,10));b.g("onCompleteAll")&&b.q.await(function(){b.g("onCompleteAll")});b.e=b.p()&&!v(b.a,"disableAjaxUpload",h)?new I(b,b.a):new J(b,b.a);b.l=v(b.a,"clickElement",f);b.l&&(k(b.l).css({position:"relative",overflow:"hidden"}),"inline"===k(this.l).css("display")&&k(this.l).css("display","inline-block"),this.e.n(this.l));if(this.e.k()&&v(this.a,"dragAndDropElement",h)&&!v(this.a,"disableAjaxUpload",h)){g=k(document);var d=k(v(b.a,"dragAndDropBodyElement",
h)||g),i=v(b.a,"dragAndDropElement",h),a=function(a){if(b.c&&a)if((a=u(a))&&E(a)){r(b.h);var c=a.dataTransfer.effectAllowed;a.dataTransfer.dropEffect=c==="move"||c==="linkMove"?"move":"copy";a.stopPropagation();a.preventDefault();d.trigger("dragover",a)}},c=function(a){if(b.c&&a)if((a=u(a))&&E(a)){a.preventDefault();var c,d=function(c){if(c){b.g("onDrop",[c,a]);b.s(c);r(b.h)}},g=v(b.a,"multipleSizeLimit",B.o),i=b.d("onLimitReached"),n=f;c=f;if(c=u(a))if((n=(c.dataTransfer?v(c.dataTransfer,"items",
f):f)||v(c,"items",f))&&0<n.length&&n[0]&&n[0].webkitGetAsEntry)A(n,d,e,!v(b.a,"disableFolderDragAndDrop",e),g,i);else if(E(c))(c=v(c,"files",f)||(c.dataTransfer?v(c.dataTransfer,"files",f):f))&&0<c.length&&A(c,d,h,h,g,i)}b.g("onDragLeave",[a])},n=function(a){if(b.c&&a)if((a=u(a))&&E(a)){r(b.h);a.preventDefault();b.g("onDragEnter",[i,a])}},t=function(a){if(b.c&&a)if(a=u(a)){var c=document.elementFromPoint?document.elementFromPoint(a.clientX,a.clientY):f,d;if(!(d=!c)){d=h;this&&c&&(d=this===c?e:this.contains?
this.contains(c):c.compareDocumentPosition?!!(c.compareDocumentPosition(this)&8):h);d=!d}if(d){r(b.h);b.g("onDragLeave",[i,a])}}};if(i){if(!v(b.a,"disableDocumentDropPrevent",h))g.on("dragover",function(a){if(b.c&&a)if((a=u(a))&&E(a)){a.dataTransfer.dropEffect="none";a.preventDefault()}});if(d&&d[0])d.on("dragover",function(a){b.c&&a&&r(b.h)}).on("dragenter",function(a){if(b.c&&a)if((a=u(a))&&E(a)){r(b.h);a.preventDefault();b.g("onBodyDragEnter",[a])}}).on("dragleave",function(a){if(b.c&&a)if(a=u(a)){r(b.h);
b.h=setTimeout(function(){b.g("onBodyDragLeave",[a])},200)}}).on("drop",function(a){if(b.c&&a)if(a=u(a)){var c=E(a);c&&a.preventDefault();b.g("onBodyDragLeave",[a]);return!c}return h});k(i).bind("dragenter",n).bind("dragover",a).bind("dragleave",t).bind("drop",c)}}else b.c=h;b.on=b.on;b.cancel=b.cancel;b.isDragAndDropSupported=b.k;b.isAjaxUploaderSupported=b.p;b.setDragAndDropEnabledStatus=b.v}j=I.prototype;j.i={};j.f={};j.b=f;j.a={};j.k=function(){return e};j.t=function(a){this.f[a]=e};
j.u=function(a,b,c){if(h===this.f[a]||!b||!b.File)return c(f,a),h;try{var g=this,d=new XMLHttpRequest,i=new FormData,n=v(this.a,"hidden",{}),t=this.b.d("onStart"),s=this.b.d("onComplete"),p=this.b.d("onProgress");d.open("POST",v(this.a,"action",""),e);p&&d.upload&&(d.upload.onprogress=function(b){b&&(b.lengthComputable&&!q(b.loaded)&&!q(b.total))&&p(a,b.loaded,b.total)});d.onreadystatechange=function(){if(4===d.readyState&&200===d.status){if(s){var b=h,i=f;try{i=k.parseJSON(d.responseText);b=e}catch(n){i=
f}s(a,b,i)}q(g.i[a])||(g.i[a]=f);c(f,a)}else if(4===d.readyState){s(a,h,f);c(f,a)}};t&&t(a);i.append("jua-post-type","ajax");i.append(v(this.a,"name","juaFile"),b.File);k.each(n,function(a,c){i.append(a,H(c,[b]))});d.send(i);this.i[a]=d;return e}catch(o){}c(f,a);return h};
j.n=function(a){var b=this,c=f,g=f;a&&(g=G("",!v(this.a,"disableMultiple",h)),c=F(),c.append(g),k(a).append(c),g.on("click",function(){var a=b.b.d("onDialog");a&&a()}).on("change",function(){D(this,function(d){b.b.s(d);b.n(a);setTimeout(function(){c.remove()},10)},v(b.a,"multipleSizeLimit",B.o),b.b.d("onLimitReached"))}))};j.cancel=function(a){this.f[a]=h;if(this.i[a]){try{this.i[a].abort&&this.i[a].abort()}catch(b){}this.i[a]=f}};j=J.prototype;j.f={};j.j={};j.b=f;j.a={};j.k=function(){return h};
j.t=function(a){this.f[a]=e};
j.u=function(a,b,c){if(h===this.f[a])return c(f,a),h;var g=this.j[a],d=v(this.a,"hidden",{}),i=this.b.d("onStart"),n=this.b.d("onComplete");g?(g.append(k('<input type="hidden" />').attr("name","jua-post-type").val("iframe")),k.each(d,function(a,c){g.append(k('<input type="hidden" />').attr("name",a).val(H(c,[b])))}),g.trigger("submit"),i&&i(a),g.find("iframe").on("load",function(){var b=h,d=f,i={};if(n){try{d=this.contentDocument?this.contentDocument:this.contentWindow.document,i=k.parseJSON(d.body.innerHTML),
b=e}catch(o){i={}}n(a,b,i)}c(f,a);l.setTimeout(function(){g.remove()},100)})):c(f,a);return e};
j.n=function(a){var b=this,c="",g=f,d=f,d=v(this.a,"action",""),i=f;a&&(c=w(),g=G(v(this.a,"name","juaFile"),!v(this.a,"disableMultiple",h)),i=k('<form action="'+d+'" target="iframe-'+c+'" method="POST" enctype="multipart/form-data" style="display: block; cursor: pointer;"></form>'),d=k('<iframe name="iframe-'+c+'" tabindex="-1" src="javascript:void(0);" style="position: absolute; top: -1000px; left: -1000px; cursor: pointer;" />').css({opacity:0}),i.append(F().append(g)).append(d),k(a).append(i),
this.j[c]=i,g.on("click",function(){var a=b.b.d("onDialog");a&&a()}).on("change",function(){D(this,function(d){d&&(i.css({position:"absolute",top:-1E3,left:-1E3}),b.b.r(c,d),b.n(a))},v(b.a,"multipleSizeLimit",B.o),b.b.d("onLimitReached"))}))};j.cancel=function(a){this.f[a]=h;this.j[a]&&(this.j[a].remove(),this.j[a]=h)};B.w=function(){};B.o=20;var K=B,L=document.createElement("input");L.type="file";K.p=!!("XMLHttpRequest"in l&&"multiple"in L&&"FormData"in l&&(new XMLHttpRequest).upload);j=B.prototype;
j.c=e;j.h=0;j.a={};j.m={};j.q=f;j.e=f;j.on=function(a,b){this.m[a]=b;return this};j.g=function(a,b){this.m[a]&&this.m[a].apply(f,b||[])};j.d=function(a){return this.m[a]||f};j.cancel=function(a){this.e.cancel(a)};j.p=function(){return B.p};j.v=function(a){this.c=!!a};j.k=function(){return this.e.k()};j.s=function(a){this.r(w(),a)};
j.r=function(a,b){var c=this.d("onSelect");if(b&&(!c||h!==c(a,b))){this.e.t(a);var g=this.e.u,d=this.e;this.q.defer(function(){return g.apply(q(d)?f:d,Array.prototype.slice.call(arguments))},a,b)}else this.e.cancel(a)};l.Jua=B;