forked from mailru/FileAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileAPI.min.js
64 lines (64 loc) · 27.7 KB
/
FileAPI.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**!
* FileAPI — a set of tools for working with files
*
* @author RubaXa <[email protected]>
* @build lib/canvas-to-blob lib/FileAPI.core lib/FileAPI.Image lib/FileAPI.Form lib/FileAPI.XHR lib/FileAPI.Flash
*/
(function(a){var j=a.HTMLCanvasElement&&a.HTMLCanvasElement.prototype,f;if(f=a.Blob)try{f=Boolean(new Blob)}catch(n){f=!1}var p=f;if(f=p)if(f=a.Uint8Array)try{f=100===(new Blob([new Uint8Array(100)])).size}catch(l){f=!1}var c=f,e=a.BlobBuilder||a.WebKitBlobBuilder||a.MozBlobBuilder||a.MSBlobBuilder,r=(p||e)&&a.atob&&a.ArrayBuffer&&a.Uint8Array&&function(a){var g,f,q,l;g=0<=a.split(",")[0].indexOf("base64")?atob(a.split(",")[1]):decodeURIComponent(a.split(",")[1]);f=new ArrayBuffer(g.length);q=new Uint8Array(f);
for(l=0;l<g.length;l+=1)q[l]=g.charCodeAt(l);a=a.split(",")[0].split(":")[1].split(";")[0];if(p)return new Blob([c?q:f],{type:a});q=new e;q.append(f);return q.getBlob(a)};a.HTMLCanvasElement&&!j.toBlob&&(j.mozGetAsFile?j.toBlob=function(a,c){a(this.mozGetAsFile("blob",c))}:j.toDataURL&&r&&(j.toBlob=function(a,c){a(r(this.toDataURL(c)))}));"function"===typeof define&&define.amd?define(function(){return r}):a.dataURLtoBlob=r})(this);
(function(a,j){function f(b,s,d){if(b)if(g(b))for(var a=0,c=b.length;a<c;a++)a in b&&s.call(d,b[a],a,b);else for(a in b)b.hasOwnProperty(a)&&s.call(d,b[a],a,b)}function n(b,s,d){if(b){var a=k.uid(b);z[a]||(z[a]={});f(s.split(/\s+/),function(s){t?t.event.add(b,s,d):(z[a][s]||(z[a][s]=[]),z[a][s].push(d),b.addEventListener?b.addEventListener(s,d,!1):b.attachEvent?b.attachEvent("on"+s,d):b["on"+s]=d)})}}function p(b,s,d){if(b){var a=k.uid(b),c=z[a]||{};f(s.split(/\s+/),function(s){if(t)t.event.remove(b,
s,d);else{for(var a=c[s]||[],B=a.length;B--;)if(a[B]===d){a.splice(B,1);break}b.addEventListener?b.removeEventListener(s,d,!1):b.detachEvent?b.detachEvent("on"+s,d):b["on"+s]=null}})}}function l(b,s,d){n(b,s,function L(a){p(b,s,L);d(a)})}function c(b,s,d,a,c){b={type:d.type||d,target:b,result:a};k.extend(b,c);s(b)}function e(b,s,d,a){if(k.isFile(b)&&u&&u.prototype["readAs"+d]){var h=new u;n(h,H,function M(d){var a=d.type;"progress"==a?c(b,s,d,d.target.result,{loaded:d.loaded,total:d.total}):"loadend"==
a?(p(h,H,M),h=null):c(b,s,d,d.target.result)});try{if(a)h["readAs"+d](a,b);else h["readAs"+d](b)}catch(g){c(b,s,"error",j,{error:g.toString()})}}else c(b,s,"error",j,{error:"filreader_not_support_"+d})}function r(b){var d;b.getAsEntry?d=b.getAsEntry():b.webkitGetAsEntry&&(d=b.webkitGetAsEntry());return d}function w(b,d){if(b)if(b.isFile)b.file(function(b){d(!1,[b])},function(){d("entry_file")});else if(b.isDirectory){var a=[];b.createReader().readEntries(function(b){k.afor(b,function(b,c){w(c,function(c,
B){c||(a=a.concat(B));b?b():d(!1,a)})})},function(){d("directory_reader")})}else w(r(b),d);else d("empty_entry")}function g(b){return"object"==typeof b&&b&&"length"in b}function x(b){b.target||(b.target=a.event&&a.event.srcElement||h);3===b.target.nodeType&&(b.target=event.target.parentNode);return b}var q=1,F=function(){},y=navigator.userAgent,A=a.createObjectURL&&a||a.URL&&URL.revokeObjectURL&&URL||a.webkitURL&&webkitURL,v=a.File,u=a.FileReader,m=a.FormData,t=a.jQuery,d=!(!v||!(u&&a.Uint8Array||
m))&&!(/safari\//.test(y)&&/windows/i.test(y)),y=d&&"withCredentials"in new XMLHttpRequest,h=a.document,D=a.dataURLtoBlob,J={},E=/img/i,N=/canvas/i,O=/img|canvas/,G=/input/i,P=/^data:[^,]+,/,m=Math.pow,z={},K=[],H="abort progress error load loadend",Q="status statusText readyState response responseXML responseText responseBody".split(" "),k={version:"1.0.1",cors:!1,debug:!1,pingUrl:!1,staticPath:"./",KB:1024,MB:m(1024,2),GB:m(1024,3),TB:m(1024,4),expando:"fileapi"+(new Date).getTime(),uid:function(b){return b?
b[k.expando]=b[k.expando]||k.uid():(++q,k.expando+q)},log:function(){k.debug&&(a.console&&console.log)&&(console.log.apply?console.log.apply(console,arguments):console.log([].join.call(arguments," ")))},getXHR:function(){var b;if(a.XMLHttpRequest)b=new XMLHttpRequest;else if(a.ActiveXObject)try{b=new ActiveXObject("MSXML2.XMLHttp.3.0")}catch(d){}return b},isArray:g,support:{dnd:y&&"ondrop"in h.createElement("div"),cors:y,html5:d,dataURI:!0},event:{on:n,off:p,one:l,fix:x},throttle:function(b,d){var c,
B;return function(){B=arguments;c||(b.apply(a,B),c=setTimeout(function(){c=0;b.apply(a,B)},d))}},F:function(){},parseJSON:function(b){return a.JSON&&JSON.parse?JSON.parse(b):(new Function("return ("+b.replace(/([\r\n])/g,"\\$1")+");"))()},trim:function(b){b=String(b);return b.trim?b.trim():b.replace(/^\s+|\s+$/g,"")},defer:function(){var b=[],d,a,c={resolve:function(h,g){c.resolve=F;a=h||!1;for(d=g;g=b.shift();)g(a,d)},then:function(c){a!==j?c(a,d):b.push(c)}};return c},queue:function(b){var d=0,
a=0,c=!1,h=!1,g={inc:function(){a++},next:function(){d++;setTimeout(g.check,0)},check:function(){d>=a&&!c&&g.end()},isFail:function(){return c},fail:function(){!c&&b(c=!0)},end:function(){h||(h=!0,b())}};return g},each:f,afor:function(b,d){var a=0,c=b.length;g(b)&&c--?function C(){d(c!=a&&C,b[a],a++)}():d(!1)},extend:function(b){f(arguments,function(d){f(d,function(d,a){b[a]=d})});return b},isFile:function(b){return d&&b&&b instanceof v},isCanvas:function(b){return b&&N.test(b.nodeName)},getFilesFilter:function(b){return(b=
"string"==typeof b?b:b.getAttribute&&b.getAttribute("accept")||"")?RegExp("("+b.replace(/\./g,"\\.").replace(/,/g,"|")+")$","i"):/./},readAsDataURL:function(b,d){k.isCanvas(b)?c(b,d,"load",k.toDataURL(b)):e(b,d,"DataURL")},readAsBinaryString:function(b,d){u&&u.prototype.readAsBinaryString?e(b,d,"BinaryString"):e(b,function(b){if("load"==b.type)try{b.result=k.toBinaryString(b.result)}catch(a){b.type="error",b.message=a.toString()}d(b)},"DataURL")},readAsArrayBuffer:function(b,d){e(b,d,"ArrayBuffer")},
readAsText:function(b,d,a){a||(a=d,d="utf-8");e(b,a,"Text",d)},toDataURL:function(b){if("string"==typeof b)return b;if(b.toDataURL)return b.toDataURL("image/png")},toBinaryString:function(b){return a.atob(k.toDataURL(b).replace(P,""))},readAsImage:function(b,d,a){if(k.isFile(b))if(A){var h=A.createObjectURL(b);h===j?c(b,d,"error"):k.readAsImage(h,d,a)}else k.readAsDataURL(b,function(h){"load"==h.type?k.readAsImage(h.result,d,a):(a||"error"==h.type)&&c(b,d,h,null,{loaded:h.loaded,total:h.total})});
else k.isCanvas(b)?c(b,d,"load",b):E.test(b.nodeName)?b.complete?c(b,d,"load",b):l(b,"error abort load",function C(a){"load"==a.type&&A&&A.revokeObjectURL(b.src);p(b,"error abort load",C);c(b,d,a,b)}):b.iframe?c(b,d,{type:"error"}):(h=new Image,h.src=b.dataURL||b,k.readAsImage(h,d,a))},checkFileObj:function(b){var d={};"object"==typeof b?d=b:d.name=(b+"").split(/(\\|\/)/g).pop();d.type===j&&(d.type=d.name.split(".").pop());f(J,function(b,a){b.test(d.type)&&(d.type=a+"/"+d.type)});return d},getDropFiles:function(b,
d){var a=[],c=(b.originalEvent||b||"").dataTransfer||{},h=g(c.items)&&c.items[0]&&r(c.items[0]),e=k.queue(function(){d(a)});f((h?c.items:c.files)||[],function(b){e.inc();if(h)w(b,function(b,d){!b&&a.push.apply(a,d);e.next()});else{var d=function(d){d&&a.push(b);e.next()};if(!b.type&&0==b.size%4096&&102400>=b.size)if(u)try{var c=new u;l(c,H,function(b){b="error"!=b.type;d(b);b&&c.abort()});c.readAsDataURL(b)}catch(s){d(!1)}else d(null);else d(!0)}});e.check()},getFiles:function(b,a,c){var h=[];if(c)return k.filterFiles(k.getFiles(b),
a,c),null;b.jquery&&(b.each(function(){h=h.concat(k.getFiles(this))}),b=h,h=[]);"string"==typeof a&&(a=k.getFilesFilter(a));b.originalEvent?b=x(b.originalEvent):b.srcElement&&(b=x(b));b.dataTransfer?b=b.dataTransfer:b.target&&(b=b.target);b.files?h=b.files:!d&&G.test(b&&b.tagName)?k.trim(b.value)&&(h=[k.checkFileObj(b.value)],h[0].blob=b,h[0].iframe=!0):g(b)&&(h=b);!a&&G.test(b&&b.tagName)&&(a=k.getFilesFilter(b));return k.filter(h,function(b){return!a||a.test(b.name)})},getInfo:function(b,d){var a=
{},c=K.concat();k.isFile(b)?function C(){var h=c.shift();h?h.test(b.type)?h(b,function(b,c){b?d(b):(k.extend(a,c),C())}):C():d(!1,a)}():d("not_support",a)},addInfoReader:function(b,d){d.test=function(d){return b.test(d)};K.push(d)},addMime:function(b,d){J[b]=RegExp("("+d.replace(/,/g,"|")+")$","i")},filter:function(b,d){for(var a=[],c=0,h=b.length,g;c<h;c++)c in b&&(g=b[c],d.call(g,g,c,b)&&a.push(g));return a},filterFiles:function(b,d,a){if(b.length){var c=b.concat(),h,g=[],w=[];(function I(){c.length?
(h=c.shift(),k.getInfo(h,function(b,a){(d(h,b?!1:a)?g:w).push(h);I()})):a(g,w)})()}else a([],b)},upload:function(b){b=k.extend({prepare:k.F,beforeupload:k.F,upload:k.F,fileupload:k.F,fileprogress:k.F,filecomplete:k.F,progress:k.F,complete:k.F},b);b.imageAutoOrientation&&!b.imageTransform&&(b.imageTransform={rotate:"auto"});var d=new k.XHR(b),a=this._getFilesDataArray(b.files),c=0,h=0,g=0,w=1;f(a,function(b){c+=b.size});d.files=[];f(a,function(b){d.files.push(b.file)});d.total=c;d.loaded=0;b.beforeupload(d,
b);(function I(){var e=a.shift(),l=this,q=e&&e.file,D=!1,m={};f(b,function(b,d){b&&"object"===typeof b&&(b=k.extend({},b));m[d]=b});"abort"!=d.statusText&&e?(d.currentFile=q,b.prepare(q,m),this._getFormData(m,e,function(a){h||b.upload(d,b);var x=new k.XHR(k.extend({},m,{upload:function(){b.fileupload(q,x,m)},progress:function(a){!D&&a.lengthComputable&&(g=h+=c*w*(a.loaded/a.total)-g+0.5|0,e.total=a.total,e.loaded=a.loaded,b.fileprogress(a,q,x,m),b.progress({type:a.type,total:c,loaded:d.loaded=h,lengthComputable:!0},
q,x,m))},complete:function(a){f(Q,function(b){d[b]=x[b]});D=!0;e.loaded=e.total;d.loaded=h+=h-g+(c*w+0.5)|0;b.filecomplete(a,x,q,m);I.call(l)}}));w=e.size/c;d.abort=function(){x.abort()};x.send(a)})):b.complete(200==d.status?!1:d.statusText||"error",d,b)}).call(this);return d},_getFilesDataArray:function(b){var d=[],a={};if(G.test(b&&b.tagName)){var c=k.getFiles(b);a[b.name||"file"]=null!==b.getAttribute("multiple")?c:c[0]}else g(b)&&G.test(b[0]&&b[0].tagName)?f(b,function(b){a[b.name||"file"]=k.getFiles(b)}):
a=b;f(a,function C(b,a){g(b)?f(b,function(b,d){C(b,a+"["+d+"]")}):b&&b.name&&d.push({name:a,file:b,size:b.size,total:b.size,loaded:0})});return d},_getFormData:function(b,d,a){var c=d.file,h=d.name,g=c.name,w=c.type;d=k.support.transform&&b.imageTransform;var e=new k.Form,q=k.queue(function(){a(e)}),l=d&&(0<parseInt(d.maxWidth||d.minWidth||d.width,10)||d.rotate);d&&(/image/.test(c.type)||O.test(c.nodeType))?(q.inc(),l&&(d=[d]),k.Image.transform(c,d,b.imageAutoOrientation,function(d,a){l&&!d?(!D&&
!k.flashEngine&&(a[0]=k.toBinaryString(a[0]),e.multipart=!0),e.append(h,a[0],g,w)):(d||(f(a,function(b,d){!D&&!k.flashEngine&&(b=k.toBinaryString(b),e.multipart=!0);e.append(h+"["+d+"]",b,g,w)}),h+="[original]"),(d||b.imageOriginal)&&e.append(h,c,g,w));q.next()})):e.append(h,c,g);f(b.data,function R(b,d){"object"==typeof b?f(b,function(b,a){R(b,d+"["+a+"]")}):e.append(d,b)});q.check()},reset:function(b){var d,a;t?(a=t(b).clone(!0).insertBefore(b).val("")[0],t(b).remove()):(d=b.parentNode,a=d.insertBefore(b.cloneNode(!0),
b),a.value="",d.removeChild(b),f(z[k.uid(b)],function(d,c){f(d,function(d){p(b,c,d);n(a,c,d)})}));return a},load:function(b,d){var a=k.getXHR();a?(a.open("GET",b,!0),a.overrideMimeType&&a.overrideMimeType("text/plain; charset=x-user-defined"),n(a,"progress",function(b){b.lengthComputable&&d({type:b.type,loaded:b.loaded,total:b.total},a)}),a.onreadystatechange=function(){if(4==a.readyState)if(a.onreadystatechange=null,200==a.status){b=b.split("/");var c={name:b[b.length-1],size:a.getResponseHeader("Content-Length"),
type:a.getResponseHeader("Content-Type")};c.dataURL="data:"+c.type+";base64,"+k.encode64(a.responseBody||a.responseText);d({type:"load",result:c})}else d({type:"error"})},a.send(null)):d({type:"error"});return a},encode64:function(b){var d="",a=0;for("string"!==typeof b&&(b=String(b));a<b.length;){var c=b.charCodeAt(a++)&255,h=b.charCodeAt(a++)&255,g=b.charCodeAt(a++)&255,w=c>>2,c=(c&3)<<4|h>>4;isNaN(h)?h=g=64:(h=(h&15)<<2|g>>6,g=isNaN(g)?64:g&63);d+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(w)+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(c)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(h)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(g)}return d}};f({image:"png,jpg,jpeg,bmp,gif,ico,tif,tiff,tga,pcx,cbz,cbr",audio:"m4a,flac,aac,rm,mpa,wav,wma,ogg,mp3,mp2,m3u,mod,amf,dmf,dsm,far,gdm,imf,it,m15,med,okt,s3m,stm,sfx,ult,uni,xm,sid,ac3,dts,cue,aif,aiff,wpl,ape,mac,mpc,mpp,shn,wv,nsf,spc,gym,adplug,adx,dsp,adp,ymf,ast,afc,hps,xsp",
video:"m4v,3gp,nsv,ts,ty,strm,rm,rmvb,m3u,ifo,mov,qt,divx,xvid,bivx,vob,nrg,img,iso,pva,wmv,asf,asx,ogm,m2v,avi,bin,dat,dvr-ms,mpg,mpeg,mp4,mkv,avc,vp3,svq3,nuv,viv,dv,fli,flv,wpl"},function(b,d){k.addMime(d,b)});k.addInfoReader(/^image/,function(b,d){if(!b.__dimensions){var a=b.__dimensions=k.defer();k.readAsImage(b,function(b){var d=b.target;a.resolve("load"==b.type?!1:"error",{width:d.width,height:d.height})})}b.__dimensions.then(d)});k.event.dnd=function(b,d,a){var c,h;a||(a=d,d=k.F);u?(n(b,"dragenter dragleave dragover",
function(b){for(var a=((b.originalEvent||b||"").dataTransfer||{}).types,g=a&&a.length;g--;)~a[g].indexOf("File")&&(b.preventDefault(),h!==b.type&&(h=b.type,"dragleave"!=h&&d.call(b.currentTarget,!0,b),clearTimeout(c),c=setTimeout(function(){d.call(b.currentTarget,"dragleave"!=h,b)},50)))}),n(b,"drop",function(b){b.preventDefault();h=0;d.call(b.currentTarget,!1,b);k.getDropFiles(b,function(d){a.call(b.currentTarget,d,b)})})):k.log("Drag'n'Drop -- not supported")};t&&!t.fn.dnd&&(t.fn.dnd=function(b,
d){return this.each(function(){k.event.dnd(this,b,d)})});a.FileAPI=k.extend(k,a.FileAPI)})(window);
(function(a,j,f){function n(a,c){if(!(this instanceof n))return new n(a);this.file=a;this.better=!c;this.matrix={sx:0,sy:0,sw:0,sh:0,dx:0,dy:0,dw:0,dh:0,resize:0,deg:0}}var p=Math.min,l=Math.round,c=!1,e={8:270,3:180,6:90};try{c=-1<j.createElement("canvas").toDataURL("image/png").indexOf("data:image/png")}catch(r){}n.prototype={constructor:n,set:function(c){a.extend(this.matrix,c);return this},crop:function(a,c,e,q){e===f&&(e=a,q=c,a=c=0);return this.set({sx:a,sy:c,sw:e,sh:q||e})},resize:function(a,
c,e){"string"==typeof c&&(e=c,c=a);return this.set({dw:a,dh:c,resize:e})},preview:function(a,c){return this.set({dw:a,dh:c||a,resize:"preview"})},rotate:function(a){return this.set({deg:a})},_load:function(c,g){var e=this;a.readAsImage(c,function(a){g.call(e,"load"!=a.type,a.result)})},_apply:function(a,c){var e=j.createElement("canvas"),q=this.getMatrix(a),f=e.getContext("2d"),l=q.deg,p=q.dw,r=q.dh,u=a.width,m=a.height,t,d=a;if(this.better)for(;2<Math.min(u/p,m/r);)u=~~(u/2+0.5),m=~~(m/2+0.5),t=
j.createElement("canvas"),t.width=u,t.height=m,d!==a?(t.getContext("2d").drawImage(d,0,0,d.width,d.height,0,0,u,m),d=t):(d=t,d.getContext("2d").drawImage(a,q.sx,q.sy,q.sw,q.sh,0,0,u,m),q.sx=q.sy=q.sw=q.sh=0);e.width=!(l%180)?p:r;e.height=l%180?p:r;f.rotate(l*Math.PI/180);f.drawImage(d,q.sx,q.sy,q.sw||d.width,q.sh||d.height,180==l||270==l?-p:0,90==l||180==l?-r:0,p,r);c.call(this,!1,e)},getMatrix:function(c){var g=a.extend({},this.matrix),e=g.sw=g.sw||c.width;c=g.sh=g.sh||c.height;var f=g.dw=g.dw||
g.sw,r=g.dh=g.dh||g.sh,j=e/c,n=f/r,v=g.resize;if("preview"==v){if(f!=e||r!=c)if(n>=j?(j=e,v=j/n):(v=c,j=v*n),j!=e||v!=c)g.sx=~~((e-j)/2),g.sy=~~((c-v)/2),e=j,c=v}else v&&("min"==v?(f=l(j<n?p(e,f):r*j),r=l(j<n?f/j:p(c,r))):(f=l(j>=n?p(e,f):r*j),r=l(j>=n?f/j:p(c,r))));g.sw=e;g.sh=c;g.dw=f;g.dh=r;return g},_trans:function(a){this._load(this.file,function(c,e){c?a(c):this._apply(e,a)})},get:function(c){if(a.support.transform){var g=this;"auto"==g.matrix.deg?a.getInfo(this.file,function(a,f){g.matrix.deg=
e[f&&f.exif&&f.exif.Orientation]||0;g._trans(c)}):g._trans(c)}else c("not_support")},toData:function(a){this.get(a)}};n.transform=function(c,e,l,j){a.getInfo(c,function(r,p){var A={},v=a.queue(function(a){j(a,A)});r?v.fail():a.each(e,function(a,e){if(!v.isFail()){var g=n(p.nodeType?p:c);if("function"==typeof a)a(p,g);else if(a.width)g[a.preview?"preview":"resize"](a.width,a.height,a.type);else a.maxWidth&&(p.width>a.maxWidth||p.height>a.maxHeight)&&g.resize(a.maxWidth,a.maxHeight,"max");a.rotate===
f&&l&&(a.rotate="auto");g.rotate(a.rotate);v.inc();g.toData(function(d,a){d?v.fail():(A[e]=a,v.next())})}})})};a.support.canvas=a.support.transform=c;a.Image=n})(FileAPI,document);
(function(a,j,f){var n=j.encodeURIComponent,p=j.FormData;j=function(){this.items=[]};j.prototype={append:function(a,c,e,f){this.items.push({name:a,blob:c&&c.blob||c,file:e||c.name,type:f||c.type})},each:function(a){for(var c=0,e=this.items.length;c<e;c++)a.call(this,this.items[c])},toData:function(f){a.support.html5?this.multipart?(a.log("FileAPI.Form.toMultipartData"),this.toMultipartData(f)):(a.log("FileAPI.Form.toFormData"),this.toFormData(f)):(a.log("FileAPI.Form.toHtmlData"),this.toHtmlData(f))},
_to:function(f,c,e,j){var p=a.queue(function(){c(f)});this.each(function(a){e(a,f,p,j)});p.check()},toHtmlData:function(l){this._to(f.createDocumentFragment(),l,function(c,e){var l=c.blob,j;c.file?(a.reset(l),l.name=c.name,e.appendChild(l)):(j=f.createElement("input"),j.name=c.name,j.type="hidden",j.value=l,e.appendChild(j))})},toFormData:function(a){this._to(new p,a,function(a,e,f){a.file&&e.append("_"+a.name,a.file);a.blob.toBlob?(f.inc(),a.blob.toBlob(function(j){e.append(a.name,j,a.file);f.next()},
"image/png")):a.file?e.append(a.name,a.blob,a.file):e.append(a.name,a.blob)})},toMultipartData:function(f){this._to([],f,function(a,e,f,j){e.push("--_"+j+('\r\nContent-Disposition: form-data; name="'+a.name+'"'+(a.file?'; filename="'+n(a.file)+'"':"")+(a.file?"\r\nContent-Type: "+(a.type||"application/octet-stream"):"")+"\r\n\r\n"+(a.file?a.blob:n(a.blob))+"\r\n"))},a.expando)}};a.Form=j})(FileAPI,window,document);
(function(a,j){var f=function(){},n=function(a){this.uid=j.uid();this.xhr={abort:f,getResponseHeader:f,getAllResponseHeaders:f};this.options=a};n.prototype={status:0,statusText:"",getResponseHeader:function(a){return this.xhr.getResponseHeader(a)},getAllResponseHeaders:function(){return this.xhr.getAllResponseHeaders()||{}},end:function(p,l){var c=this,e=c.options;c.end=c.abort=f;c.status=p;l&&(c.statusText=l);j.log("xhr.end:",p,l);e.complete(200==p?!1:c.statusText||"unknown",c);c.xhr&&c.xhr.node&&
setTimeout(function(){var e=c.xhr.node;try{e.parentNode.removeChild(e)}catch(f){}try{delete a[c.uid]}catch(g){}a[c.uid]=c.xhr.node=null},9)},abort:function(){this.end(0,"abort");this.xhr&&this.xhr.abort()},send:function(a){var f=this,c=this.options;a.toData(function(a){c.upload(c,f);f._send.call(f,c,a)})},_send:function(f,l){var c=this,e,r=c.uid,n=f.url;j.log("XHR._send:",l);n+=(~n.indexOf("?")?"&":"?")+j.uid();l.nodeName?(f.upload(f,c),e=document.createElement("div"),e.innerHTML='<form target="'+
r+'" action="'+n+'" method="POST" enctype="multipart/form-data" style="position: absolute; top: -1000px; overflow: hidden; width: 1px; height: 1px;"><iframe name="'+r+'" src="javascript:false;"></iframe><input value="'+r+'" name="callback" type="hidden"/></form>',c.xhr.abort=function(){var a=e.getElementsByName("iframe")[0];if(a)try{a.stop?a.stop():a.contentWindow.stop?a.contentWindow.stop():a.contentWindow.document.execCommand("Stop")}catch(c){}e=null},n=e.getElementsByTagName("form")[0],n.appendChild(l),
j.log(n.parentNode.innerHTML),document.body.appendChild(e),c.xhr.node=e,a[r]=function(a,f,j){c.readyState=4;c.responseText=j;c.end(a,f);e=null},c.readyState=2,n.submit(),n=null):(e=c.xhr=j.getXHR(),e.open("POST",n,!0),e.withCredential="true",(!f.headers||!f.headers["X-Requested-With"])&&e.setRequestHeader("X-Requested-With","XMLHttpRequest"),j.each(f.headers,function(a,c){e.setRequestHeader(c,a)}),e.upload&&e.upload.addEventListener("progress",j.throttle(function(a){f.progress(a,c,f)},100),!1),e.onreadystatechange=
function(){c.status=e.status;c.statusText=e.statusText;c.readyState=e.readyState;if(4==e.readyState){for(var a in{"":1,XML:1,Text:1,Body:1})c["response"+a]=e["response"+a];e.onreadystatechange=null;c.end(e.status);e=null}},j.isArray(l)?(e.setRequestHeader("Content-Type","multipart/form-data; boundary=_"+j.expando),l=l.join("")+"--_"+j.expando+"--",e.sendAsBinary?e.sendAsBinary(l):(r=Array.prototype.map.call(l,function(a){return a.charCodeAt(0)&255}),e.send((new Uint8Array(r)).buffer))):e.send(l))}};
j.XHR=n})(window,FileAPI);
(function(a,j,f){var n=a.support,p=j.navigator,l=p.mimeTypes,c=!1;if(p.plugins&&"object"==typeof p.plugins["Shockwave Flash"])c=p.plugins["Shockwave Flash"].description&&!(l&&l["application/x-shockwave-flash"]&&!l["application/x-shockwave-flash"].enabledPlugin);else try{c=!(!j.ActiveXObject||!new ActiveXObject("ShockwaveFlash.ShockwaveFlash"))}catch(e){}n.flash=c;if(a.support.flash&&(!a.support.html5||a.cors&&!a.support.cors)){var r=function(a){return('<object id="#id#" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+(a.width||
"100%")+'" height="'+(a.height||"100%")+'"><param name="movie" value="#src#" /><param name="flashvars" value="#flashvars#" /><param name="swliveconnect" value="true" /><param name="allowscriptaccess" value="always" /><param name="allownetworking" value="all" /><param name="menu" value="false" /><param name="wmode" value="#wmode#" /><embed flashvars="#flashvars#" swliveconnect="true" allownetworking="all" allowscriptaccess="always" name="#id#" src="#src#" width="'+(a.width||"100%")+'" height="'+(a.height||
"100%")+'" menu="false" wmode="transparent" type="application/x-shockwave-flash"></embed></object>').replace(/#(\w+)#/ig,function(c,e){return a[e]})},w=function(a,c){if(a&&a.style){var e,f;for(e in c){f=c[e];"number"==typeof f&&(f+="px");try{a.style[e]=f}catch(g){}}}},g=function(d,c){a.each(c,function(a,c){var h=d[c];d[c]=function(){this.parent=h;return a.apply(this,arguments)}})},x=function(d){var c=d.wid=a.uid();m._fn[c]=d;return"FileAPI.Flash._fn."+c},q=function(a){try{m._fn[a.wid]=null,delete m._fn[a.wid]}catch(c){}},
F=function(a){if(!u.test(a)){if(/^\.\//.test(a)||"/"!=a.charAt(0)){var c=location.pathname,c=c.substr(0,c.lastIndexOf("/"));a=(c+"/"+a).replace("/./","/")}"//"!=a.substr(0,2)&&(a="//"+location.host+a);u.test(a)||(a=location.protocol+a)}return a},y=a.uid(),A=0,v={},u=/^https?:/i,m={_fn:{},init:function(){var d=f.body&&f.body.firstChild;if(d){do if(1==d.nodeType){a.log("FlashAPI.Flash.inited");var c=f.createElement("div");w(c,{top:1,right:1,width:5,height:5,position:"absolute"});d.parentNode.insertBefore(c,
d);m.publish(c,y);return}while(d=d.nextSibling)}10>A&&setTimeout(m.init,50*++A)},publish:function(d,c){d.innerHTML=r({id:c,src:F(a.staticPath+"FileAPI.flash.swf?r="+a.version),wmode:"transparent",flashvars:"callback=FileAPI.Flash.event&flashId="+c+"&storeKey="+navigator.userAgent.match(/\d/ig).join("")+"_"+a.version+(m.isReady||(a.pingUrl?"&ping="+a.pingUrl:""))})},ready:function(){m.ready=a.F;m.isReady=!0;m.patch();a.event.on(f,"mouseover",m.mouseover);a.event.on(f,"click",function(a){m.mouseover(a)&&
(a.preventDefault?a.preventDefault():a.returnValue=!0)})},getWrapper:function(a){do if(/js-fileapi-wrapper/.test(a.className))return a;while((a=a.parentNode)&&a!==f.body)},mouseover:function(d){d=a.event.fix(d).target;if(/input/i.test(d.nodeName)&&"file"==d.type){var c=d.getAttribute(y);if("i"==c||"r"==c)return!1;if("p"!=c){d.setAttribute(y,"i");var c=f.createElement("div"),e=m.getWrapper(d);if(!e){a.log("flash.mouseover.error: js-fileapi-wrapper not found");return}w(c,{top:0,left:0,width:d.offsetWidth+
100,height:d.offsetHeight+100,zIndex:"1000000",position:"absolute"});e.appendChild(c);m.publish(c,a.uid());d.setAttribute(y,"p")}return!0}},event:function(d){var c=d.type;if("ready"==c){try{m.getInput(d.flashId).setAttribute(y,"r")}catch(e){}m.ready();setTimeout(function(){m.mouseenter(d)},50);return!0}"ping"===c?a.log("(flash -> js).ping:",[d.status,d.savedStatus],d.error):"log"===c?a.log("(flash -> js).log:",d.target):c in m&&setTimeout(function(){a.log("Flash.event."+d.type+":",d);m[c](d)},1)},
mouseenter:function(a){var c=m.getInput(a.flashId);c&&(m.cmd(a,"multiple",null!==c.getAttribute("multiple")),m.cmd(a,"accept",(c.getAttribute("accept")||"*").replace(/\./g,"")))},get:function(a){return f[a]||j[a]||f.embeds[a]},getInput:function(a){try{var c=m.getWrapper(m.get(a));if(c)return c.getElementsByTagName("input")[0]}catch(e){}},select:function(d){var c=m.getInput(d.flashId),e=a.uid(c);d=d.target.files;a.each(d,function(d){a.checkFileObj(d)});v[e]=d;f.createEvent?(e=f.createEvent("Event"),
e.initEvent("change",!0,!1),c.dispatchEvent(e)):f.createEventObject&&(e=f.createEventObject(),c.fireEvent("onchange",e))},cmd:function(d,c,e,f){try{return a.log("(js -> flash)."+c+":",e),m.get(d.flashId||d).cmd(c,e)}catch(g){a.log("(js -> flash).onError:",g),f||setTimeout(function(){m.cmd(d,c,e,!0)},50)}},patch:function(){a.flashEngine=a.support.transform=!0;g(a,{getFiles:function(d,c,e){if(e)return a.filterFiles(a.getFiles(d),c,e),null;var f=a.isArray(d)?d:v[a.uid(d.target||d.srcElement||d)];if(!f)return this.parent.apply(this,
arguments);c&&(c=a.getFilesFilter(c),f=a.filter(f,function(a){return c.test(a.name)}));return f},getInfo:function(a,c){if(a&&!a.flashId)this.parent.apply(this,arguments);else{if(!a.__info){var e=a.__info=FileAPI.defer();m.cmd(a,"getFileInfo",{id:a.id,callback:x(function E(c,f){q(E);e.resolve(c,a.info=f)})})}a.__info.then(c)}}});a.support.transform=!0;g(FileAPI.Image.prototype,{get:function(a,c){this.set({scaleMode:c||"noScale"});this.parent(a)},_load:function(d,c){a.log("FileAPI.Image._load:",d);
if(d&&!d.flashId)this.parent.apply(this,arguments);else{var e=this;a.getInfo(d,function(a){c.call(e,a,d)})}},_apply:function(d,c){a.log("FileAPI.Image._apply:",d);if(d&&!d.flashId)this.parent.apply(this,arguments);else{var e=this.getMatrix(d.info);m.cmd(d,"imageTransform",{id:d.id,matrix:e,callback:x(function E(g,j){a.log("FileAPI.Image._apply.callback:",g);q(E);if(g)c(g);else if(!a.support.dataURI||3E4<j.length){var l={width:!(e.deg%180)?e.dw:e.dh,height:e.deg%180?e.dw:e.dh,scale:e.scaleMode},n=
c,p=function(){try{m.get(v).setImage(j)}catch(a){}},t,v=a.uid(),u=f.createElement("div");for(t in l)u.setAttribute("data-img-"+t,l[t]);w(u,l);u.innerHTML=r(a.extend({id:v,src:a.staticPath+"FileAPI.flash.image.swf?r="+a.uid(),wmode:"opaque",flashvars:"scale="+l.scale+"&callback="+x(function s(){q(s);setTimeout(p,99);return!0})},l));n(!1,u);u=null}else{var k=new Image;a.event.one(k,"error abort load",function(a){c("load"!=a.type&&a.type,k);k=null});k.src="data:"+d.type+";base64,"+j}})})}},toData:function(a){var c=
this.file;c&&!c.flashId?this.parent.apply(this,arguments):a.call(this,!c.info,{id:c.id,flashId:c.flashId,name:c.name,type:c.type,matrix:this.getMatrix(c.info)})}});g(a.Form.prototype,{toData:function(d){for(var c=this.items,e=c.length;e--;)if(c[e].file&&c[e].blob&&!c[e].blob.flashId)return this.parent.apply(this,arguments);a.log("flash.Form.toData");d(c)}});g(a.XHR.prototype,{_send:function(c,e){if(e.nodeName||e.append&&a.support.html5||a.isArray(e)&&"string"===typeof e[0])return this.parent.apply(this,
arguments);var f={},g={},j=this,l,n;a.each(e,function(a){a.file?(g[a.name]=a={id:a.blob.id,name:a.blob.name,matrix:a.blob.matrix,flashId:a.blob.flashId},n=a.id,l=a.flashId):f[a.name]=a.blob});a.log("flash.XHR._send:",l,n,g);j.xhr={headers:{},abort:function(){m.cmd(l,"abort",n)},getResponseHeader:function(a){return this.headers[a]},getAllResponseHeaders:function(){return this.headers}};var p=a.queue(function(){m.cmd(l,"upload",{url:F(c.url),data:f,files:g,headers:c.headers,callback:x(function z(e){var f=
e.type,g=e.result;a.log("flash.upload."+f+":",e);if("progress"==f)e.loaded=Math.min(e.loaded,e.total),e.lengthComputable=!0,c.progress(e);else if("complete"==f)q(z),"string"==typeof g&&(j.responseText=g.replace(/%22/g,'"').replace(/%5c/g,"\\").replace(/%26/g,"&").replace(/%25/g,"%")),j.end(e.status||200);else if("abort"==f||"error"==f)j.end(0,e.message),q(z)})})});a.each(g,function(c){p.inc();a.getInfo(c,p.next)});p.check()}})}};a.Flash=m;var t=new Image;a.event.one(t,"error load",function(){a.support.dataURI=
!(1!=t.width||1!=t.height);t=null;m.init()});t.src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=="}})(FileAPI,window,document);"undefined"!==typeof ajs&&ajs.loaded&&ajs.loaded("{fileapi}FileAPI.min");"function"===typeof define&&define.amd&&define("FileAPI",[],function(){return window.FileAPI||{}});