forked from mailru/FileAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileAPI.min.js
62 lines (62 loc) · 27.5 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
/**!
* 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 m=f;if(f=m)if(f=a.Uint8Array)try{f=100===(new Blob([new Uint8Array(100)])).size}catch(g){f=!1}var c=f,e=a.BlobBuilder||a.WebKitBlobBuilder||a.MozBlobBuilder||a.MSBlobBuilder,p=(m||e)&&a.atob&&a.ArrayBuffer&&a.Uint8Array&&function(a){var h,f,v,g;h=0<=a.split(",")[0].indexOf("base64")?atob(a.split(",")[1]):decodeURIComponent(a.split(",")[1]);f=new ArrayBuffer(h.length);v=new Uint8Array(f);
for(g=0;g<h.length;g+=1)v[g]=h.charCodeAt(g);a=a.split(",")[0].split(":")[1].split(";")[0];if(m)return new Blob([c?v:f],{type:a});v=new e;v.append(f);return v.getBlob(a)};a.HTMLCanvasElement&&!j.toBlob&&(j.mozGetAsFile?j.toBlob=function(a,c){a(this.mozGetAsFile("blob",c))}:j.toDataURL&&p&&(j.toBlob=function(a,c){a(p(this.toDataURL(c)))}));"function"===typeof define&&define.amd?define(function(){return p}):a.dataURLtoBlob=p})(this);
(function(a,j){function f(b,q,d){if(b)if(h(b))for(var a=0,c=b.length;a<c;a++)a in b&&q.call(d,b[a],a,b);else for(a in b)b.hasOwnProperty(a)&&q.call(d,b[a],a,b)}function n(b,q,d){if(b){var a=k.uid(b);x[a]||(x[a]={});f(q.split(/\s+/),function(q){s?s.event.add(b,q,d):(x[a][q]||(x[a][q]=[]),x[a][q].push(d),b.addEventListener?b.addEventListener(q,d,!1):b.attachEvent?b.attachEvent("on"+q,d):b["on"+q]=d)})}}function m(b,q,d){if(b){var a=k.uid(b),c=x[a]||{};f(q.split(/\s+/),function(q){if(s)s.event.remove(b,
q,d);else{for(var a=c[q]||[],z=a.length;z--;)if(a[z]===d){a.splice(z,1);break}b.addEventListener?b.removeEventListener(q,d,!1):b.detachEvent?b.detachEvent("on"+q,d):b["on"+q]=null}})}}function g(b,q,d){n(b,q,function K(a){m(b,q,K);d(a)})}function c(b,q,d,a,c){b={type:d.type||d,target:b,result:a};k.extend(b,c);q(b)}function e(b,q,d,a){if(k.isFile(b)&&t&&t.prototype["readAs"+d]){var i=new t;n(i,G,function L(d){var a=d.type;"progress"==a?c(b,q,d,d.target.result,{loaded:d.loaded,total:d.total}):"loadend"==
a?(m(i,G,L),i=null):c(b,q,d,d.target.result)});try{if(a)i["readAs"+d](a,b);else i["readAs"+d](b)}catch(h){c(b,q,"error",j,{error:h.toString()})}}else c(b,q,"error",j,{error:"filreader_not_support_"+d})}function p(b){var d;b.getAsEntry?d=b.getAsEntry():b.webkitGetAsEntry&&(d=b.webkitGetAsEntry());return d}function u(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){u(c,function(c,
z){c||(a=a.concat(z));b?b():d(!1,a)})})},function(){d("directory_reader")})}else u(p(b),d);else d("empty_entry")}function h(b){return"object"==typeof b&&b&&"length"in b}function A(b){b.target||(b.target=a.event&&a.event.srcElement||i);3===b.target.nodeType&&(b.target=event.target.parentNode);return b}var v=1,E=function(){},w=navigator.userAgent,y=a.createObjectURL&&a||a.URL&&URL.revokeObjectURL&&URL||a.webkitURL&&webkitURL,r=a.File,t=a.FileReader,l=a.FormData,s=a.jQuery,d=!(!r||!(t&&a.Uint8Array||
l))&&!(/safari\//.test(w)&&/windows/i.test(w)),w=d&&"withCredentials"in new XMLHttpRequest,i=a.document,C=a.dataURLtoBlob,I={},D=/img/i,M=/canvas/i,N=/img|canvas/,F=/input/i,O=/^data:[^,]+,/,l=Math.pow,x={},J=[],G="abort progress error load loadend",P="status statusText readyState response responseXML responseText responseBody".split(" "),k={build:4,cors:!1,debug:!1,pingUrl:!1,staticPath:"./",KB:1024,MB:l(1024,2),GB:l(1024,3),TB:l(1024,4),expando:"fileapi"+ +new Date,uid:function(b){return b?b[k.expando]=
b[k.expando]||k.uid():k.expando+ ++v},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:h,support:{dnd:w&&"ondrop"in i.createElement("div"),cors:w,html5:d,dataURI:!0},event:{on:n,off:m,one:g,fix:A},throttle:function(b,d){var c,z;return function(){z=
arguments;c||(b.apply(a,z),c=setTimeout(function(){c=0;b.apply(a,z)},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(i,h){c.resolve=E;a=i||!1;for(d=h;h=b.shift();)h(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,i=!1,h={inc:function(){a++},
next:function(){d++;setTimeout(h.check,0)},check:function(){d>=a&&!c&&h.end()},isFail:function(){return c},fail:function(){!c&&b(c=!0)},end:function(){i||(i=!0,b())}};return h},each:f,afor:function(b,d){var a=0,c=b.length;h(b)&&c--?function B(){d(c!=a&&B,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 r},isCanvas:function(b){return b&&M.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){t&&t.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(O,""))},readAsImage:function(b,d,a){if(k.isFile(b))if(y){var i=y.createObjectURL(b);i===j?c(b,d,"error"):k.readAsImage(i,d,a)}else k.readAsDataURL(b,function(i){"load"==i.type?k.readAsImage(i.result,d,a):(a||"error"==i.type)&&c(b,d,i,null,{loaded:i.loaded,total:i.total})});else k.isCanvas(b)?c(b,
d,"load",b):D.test(b.nodeName)?b.complete?c(b,d,"load",b):g(b,"error abort load",function B(a){"load"==a.type&&y&&y.revokeObjectURL(b.src);m(b,"error abort load",B);c(b,d,a,b)}):b.iframe?c(b,d,{type:"error"}):(i=new Image,i.src=b.dataURL||b,k.readAsImage(i,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(I,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||{},i=h(c.items)&&c.items[0]&&p(c.items[0]),e=k.queue(function(){d(a)});f((i?c.items:c.files)||[],function(b){e.inc();if(i)u(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(t)try{var c=new t;g(c,G,function(b){b="error"!=b.type;d(b);b&&c.abort()});c.readAsDataURL(b)}catch(q){d(!1)}else d(null);else d(!0)}});e.check()},getFiles:function(b,a,c){var i=[];if(c)return k.filterFiles(k.getFiles(b),
a,c),null;b.jquery&&(b.each(function(){i=i.concat(k.getFiles(this))}),b=i,i=[]);"string"==typeof a&&(a=k.getFilesFilter(a));b.originalEvent?b=A(b.originalEvent):b.srcElement&&(b=A(b));b.dataTransfer?b=b.dataTransfer:b.target&&(b=b.target);b.files?i=b.files:!d&&F.test(b&&b.tagName)?k.trim(b.value)&&(i=[k.checkFileObj(b.value)],i[0].blob=b,i[0].iframe=!0):h(b)&&(i=b);!a&&F.test(b&&b.tagName)&&(a=k.getFilesFilter(b));return k.filter(i,function(b){return!a||a.test(b.name)})},getInfo:function(b,d){var a=
{},c=J.concat();k.isFile(b)?function B(){var i=c.shift();i?i.test(b.type)?i(b,function(b,c){b?d(b):(k.extend(a,c),B())}):B():d(!1,a)}():d("not_support",a)},addInfoReader:function(b,d){d.test=function(d){return b.test(d)};J.push(d)},addMime:function(b,d){I[b]=RegExp("("+d.replace(/,/g,"|")+")$","i")},filter:function(b,d){for(var a=[],c=0,i=b.length,h;c<i;c++)c in b&&(h=b[c],d.call(h,h,c,b)&&a.push(h));return a},filterFiles:function(b,d,a){if(b.length){var c=b.concat(),i,h=[],u=[];(function H(){c.length?
(i=c.shift(),k.getInfo(i,function(b,a){(d(i,b?!1:a)?h:u).push(i);H()})):a(h,u)})()}else a([],b)},upload:function(b){b=k.extend({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,i=0,h=0,u=1;f(a,function(b){c+=b.size});d.files=[].concat(a);d.total=c;d.loaded=0;b.beforeupload(d,b);(function H(){var e=a.shift(),
g=this,v=!1;d.currentFile=e;"abort"!=d.statusText&&e?this._getFormData(b,e,function(a){i||b.upload(d,b);var C=e.file,l=new k.XHR(k.extend({},b,{upload:function(){b.fileupload(C,l,b)},progress:function(a){!v&&a.lengthComputable&&(h=i+=~~(c*u*(a.loaded/a.total)-h+0.5),e.total=a.total,e.loaded=a.loaded,b.fileprogress(a,C,l,b),b.progress({type:a.type,total:c,loaded:d.loaded=i,lengthComputable:!0},C,l,b))},complete:function(a){f(P,function(b){d[b]=l[b]});v=!0;e.loaded=e.total;d.loaded=i+=i-h+~~(c*u+0.5);
b.filecomplete(a,l,C,b);H.call(g)}}));u=e.size/c;d.abort=function(){l.abort()};l.send(a)}):b.complete(200==d.status?!1:d.statusText||"error",d,b)}).call(this);return d},_getFilesDataArray:function(b){var d=[],a={};if(F.test(b&&b.tagName)){var c=k.getFiles(b);a[b.name||"file"]=null!==b.getAttribute("multiple")?c:c[0]}else h(b)&&F.test(b[0]&&b[0].tagName)?f(b,function(b){a[b.name||"file"]=k.getFiles(b)}):a=b;f(a,function B(b,a){h(b)?f(b,function(b,d){B(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,i=d.name,h=c.name,u=c.type,d=k.support.transform&&b.imageTransform,e=new k.Form,g=k.queue(function(){a(e)}),v=d&&(0<parseInt(d.maxWidth||d.minWidth||d.width,10)||d.rotate);d&&(/image/.test(c.type)||N.test(c.nodeType))?(g.inc(),v&&(d=[d]),k.Image.transform(c,d,b.imageAutoOrientation,function(d,a){v&&!d?(!C&&!k.flashEngine&&(a[0]=k.toBinaryString(a[0]),e.multipart=!0),e.append(i,a[0],h,u)):(d||(f(a,function(b,
d){!C&&!k.flashEngine&&(b=k.toBinaryString(b),e.multipart=!0);e.append(i+"["+d+"]",b,h,u)}),i+="[original]"),(d||b.imageOriginal)&&e.append(i,c,h,u));g.next()})):e.append(i,c,h);f(b.data,function Q(b,d){"object"==typeof b?f(b,function(b,a){Q(b,d+"["+a+"]")}):e.append(d,b)});g.check()},reset:function(b){var d,a;s?(a=s(b).clone(!0).insertBefore(b).val("")[0],s(b).remove()):(d=b.parentNode,a=d.insertBefore(b.cloneNode(!0),b),a.value="",d.removeChild(b),f(x[k.uid(b)],function(d,c){f(d,function(d){m(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,i=b.charCodeAt(a++)&255,h=b.charCodeAt(a++)&255,u=c>>2,c=(c&3)<<4|i>>4;isNaN(i)?i=h=64:(i=(i&15)<<2|h>>6,h=isNaN(h)?64:h&63);d+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(u)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(c)+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(i)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(h)}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,i;a||(a=d,d=k.F);t?(n(b,"dragenter dragleave dragover",function(b){for(var a=((b.originalEvent||b||"").dataTransfer||{}).types,h=a&&a.length;h--;)~a[h].indexOf("File")&&(b.preventDefault(),i!==b.type&&(i=b.type,
"dragleave"!=i&&d.call(b.currentTarget,!0,b),clearTimeout(c),c=setTimeout(function(){d.call(b.currentTarget,"dragleave"!=i,b)},50)))}),n(b,"drop",function(b){b.preventDefault();i=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")};s&&!s.fn.dnd&&(s.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 m=Math.min,g=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(p){}n.prototype={constructor:n,set:function(c){a.extend(this.matrix,c);return this},crop:function(a,c,e,g){e===f&&(e=a,g=c,a=c=0);return this.set({sx:a,sy:c,sw:e,sh:g||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,h){var e=this;a.readAsImage(c,function(a){h.call(e,"load"!=a.type,a.result)})},_apply:function(a,c){var e=j.createElement("canvas"),g=this.getMatrix(a),f=e.getContext("2d"),m=g.deg,p=g.dw,r=g.dh,t=a.width,l=a.height,s,d=a;if(this.better)for(;2<Math.min(t/p,l/r);)t=~~(t/2+0.5),l=~~(l/2+0.5),s=
j.createElement("canvas"),s.width=t,s.height=l,d!==a?(s.getContext("2d").drawImage(d,0,0,d.width,d.height,0,0,t,l),d=s):(d=s,d.getContext("2d").drawImage(a,g.sx,g.sy,g.sw,g.sh,0,0,t,l),g.sx=g.sy=g.sw=g.sh=0);e.width=!(m%180)?p:r;e.height=m%180?p:r;f.rotate(m*Math.PI/180);f.drawImage(d,g.sx,g.sy,g.sw||d.width,g.sh||d.height,180==m||270==m?-p:0,90==m||180==m?-r:0,p,r);c.call(this,!1,e)},getMatrix:function(c){var h=a.extend({},this.matrix),e=h.sw=h.sw||c.width,c=h.sh=h.sh||c.height,f=h.dw=h.dw||h.sw,
p=h.dh=h.dh||h.sh,j=e/c,n=f/p,r=h.resize;if("preview"==r){if(f!=e||p!=c)if(n>=j?(j=e,r=j/n):(r=c,j=r*n),j!=e||r!=c)h.sx=~~((e-j)/2),h.sy=~~((c-r)/2),e=j,c=r}else r&&("min"==r?(f=g(j<n?m(e,f):p*j),p=g(j<n?f/j:m(c,p))):(f=g(j>=n?m(e,f):p*j),p=g(j>=n?f/j:m(c,p))));h.sw=e;h.sh=c;h.dw=f;h.dh=p;return h},_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 h=this;"auto"==h.matrix.deg?a.getInfo(this.file,function(a,g){h.matrix.deg=e[g&&
g.exif&&g.exif.Orientation]||0;h._trans(c)}):h._trans(c)}else c("not_support")},toData:function(a){this.get(a)}};n.transform=function(c,e,g,j){a.getInfo(c,function(p,m){var y={},r=a.queue(function(a){j(a,y)});p?r.fail():a.each(e,function(a,e){if(!r.isFail()){var h=n(m.nodeType?m:c);if("function"==typeof a)a(m,h);else if(a.width)h[a.preview?"preview":"resize"](a.width,a.height,a.type);else a.maxWidth&&(m.width>a.maxWidth||m.height>a.maxHeight)&&h.resize(a.maxWidth,a.maxHeight,"max");a.rotate===f&&
g&&(a.rotate="auto");h.rotate(a.rotate);r.inc();h.toData(function(a,c){a?r.fail():(y[e]=c,r.next())})}})})};a.support.canvas=a.support.transform=c;a.Image=n})(FileAPI,document);
(function(a,j,f){var n=j.encodeURIComponent,m=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(g){a.support.html5?this.multipart?(a.log("FileAPI.Form.toMultipartData"),this.toMultipartData(g)):(a.log("FileAPI.Form.toFormData"),this.toFormData(g)):(a.log("tFileAPI.Form.toHtmlData"),this.toHtmlData(g))},
_to:function(g,c,e,f){var j=a.queue(function(){c(g)});this.each(function(a){e(a,g,j,f)});j.check()},toHtmlData:function(g){this._to(f.createDocumentFragment(),g,function(c,e){var g=c.blob,j;c.file?(a.reset(g),g.name=c.name,e.appendChild(g)):(j=f.createElement("input"),j.name=c.name,j.type="hidden",j.value=g,e.appendChild(j))})},toFormData:function(a){this._to(new m,a,function(a,e,g){a.file&&e.append("_"+a.name,a.file);a.blob.toBlob?(g.inc(),a.blob.toBlob(function(f){e.append(a.name,f,a.file);g.next()},
"image/png")):a.file?e.append(a.name,a.blob,a.file):e.append(a.name,a.blob)})},toMultipartData:function(g){this._to([],g,function(a,e,g,f){e.push("--_"+f+('\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(m,g){var c=this,e=c.options;c.end=c.abort=f;c.status=m;g&&(c.statusText=g);j.log("xhr.end:",m,g);e.complete(200==m?!1:c.statusText||"unknown",c);c.xhr&&c.xhr.node&&
setTimeout(function(){var e=c.xhr.node;try{e.parentNode.removeChild(e)}catch(g){}try{delete a[c.uid]}catch(h){}a[c.uid]=c.xhr.node=null},9)},abort:function(){this.end(0,"abort");this.xhr&&this.xhr.abort()},send:function(a){var g=this,c=this.options;a.toData(function(a){c.upload(c,g);g._send.call(g,c,a)})},_send:function(f,g){var c=this,e,p=c.uid;j.log("XHR._send:",g);if(g.nodeName){f.upload(f,c);e=document.createElement("div");e.innerHTML='<form target="'+p+'" action="'+f.url+'" method="POST" enctype="multipart/form-data" style="position: absolute; top: -1000px; overflow: hidden; width: 1px; height: 1px;"><iframe name="'+
p+'" src="javascript:false;"></iframe><input value="'+p+'" 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};var n=e.getElementsByTagName("form")[0];n.appendChild(g);j.log(n.parentNode.innerHTML);document.body.appendChild(e);c.xhr.node=e;a[p]=function(a,f,g){c.readyState=4;c.responseText=g;c.end(a,f);e=null};c.readyState=
2;n.submit();n=null}else e=c.xhr=j.getXHR(),e.open("POST",f.url,!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(g)?(e.setRequestHeader("Content-Type","multipart/form-data; boundary=_"+j.expando),g=g.join("")+"--_"+j.expando+"--",e.sendAsBinary?e.sendAsBinary(g):(p=Array.prototype.map.call(g,function(a){return a.charCodeAt(0)&255}),e.send((new Uint8Array(p)).buffer))):e.send(g)}};j.XHR=n})(window,FileAPI);
(function(a,j,f){var n=a.support,m=j.navigator,g=m.mimeTypes,c=!1;if(m.plugins&&"object"==typeof m.plugins["Shockwave Flash"])c=m.plugins["Shockwave Flash"].description&&!(g&&g["application/x-shockwave-flash"]&&!g["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 p=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]})},u=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){}}}},h=function(d,c){a.each(c,function(a,c){var i=d[c];d[c]=function(){this.parent=i;return a.apply(this,arguments)}})},A=function(d){var c=d.wid=a.uid();l._fn[c]=d;return"FileAPI.Flash._fn."+c},v=function(a){try{l._fn[a.wid]=
null,delete l._fn[a.wid]}catch(c){}},E=function(a){if(!t.test(a)){if(/^\.\//.test(a)||"/"!=a.charAt(0))var c=location.pathname,c=c.substr(0,c.lastIndexOf("/")),a=c+"/"+a.substr("./"==RegExp.$1?2:0);"//"!=a.substr(0,2)&&(a=location.hostname+"/"+a);t.test(a)||(a=location.protocol+"//"+a)}return a},w=a.uid(),y=0,r={},t=/^https?:/i,l={_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");u(c,{top:1,right:1,width:5,
height:5,position:"absolute"});d.parentNode.insertBefore(c,d);l.publish(c,w);return}while(d=d.nextSibling)}10>y&&setTimeout(l.init,50*++y)},publish:function(d,c){d.innerHTML=p({id:c,src:E(a.staticPath+"FileAPI.flash.swf?r="+a.build),wmode:"transparent",flashvars:"callback=FileAPI.Flash.event&flashId="+c+"&storeKey="+navigator.userAgent.match(/\d/ig).join("")+"_"+a.build+(l.isReady||(a.pingUrl?"&ping="+a.pingUrl:""))})},ready:function(){l.ready=a.F;l.isReady=!0;l.patch();a.event.on(f,"mouseover",l.mouseover);
a.event.on(f,"click",function(a){l.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(w);if("i"==c||"r"==c)return!1;if("p"!=c){d.setAttribute(w,"i");var c=f.createElement("div"),e=l.getWrapper(d);if(!e){a.log("flash.mouseover.error: js-fileapi-wrapper not found");
return}u(c,{top:0,left:0,width:d.offsetWidth+100,height:d.offsetHeight+100,zIndex:"1000000",position:"absolute"});e.appendChild(c);l.publish(c,a.uid());d.setAttribute(w,"p")}return!0}},event:function(d){var c=d.type;if("ready"==c){try{l.getInput(d.flashId).setAttribute(w,"r")}catch(e){}l.ready();setTimeout(function(){l.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 l&&setTimeout(function(){a.log("Flash.event."+
d.type+":",d);l[c](d)},1)},mouseenter:function(a){var c=l.getInput(a.flashId);c&&(l.cmd(a,"multiple",null!==c.getAttribute("multiple")),l.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=l.getWrapper(l.get(a));if(c)return c.getElementsByTagName("input")[0]}catch(e){}},select:function(d){var c=l.getInput(d.flashId),e=a.uid(c),d=d.target.files;a.each(d,function(d){a.checkFileObj(d)});r[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),l.get(d.flashId||d).cmd(c,e)}catch(g){a.log("(js -> flash).onError:",g),f||setTimeout(function(){l.cmd(d,c,e,!0)},50)}},patch:function(){a.flashEngine=a.support.transform=!0;h(a,{getFiles:function(d,c,e){if(e)return a.filterFiles(a.getFiles(d),c,e),null;var f=a.isArray(d)?d:r[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();l.cmd(a,"getFileInfo",{id:a.id,callback:A(function D(c,i){v(D);e.resolve(c,a.info=i)})})}a.__info.then(c)}}});a.support.transform=!0;h(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);l.cmd(d,"imageTransform",{id:d.id,matrix:e,callback:A(function D(g,h){a.log("FileAPI.Image._apply.callback:",g);v(D);if(g)c(g);else if(!a.support.dataURI||3E4<h.length){var j={width:!(e.deg%180)?e.dw:e.dh,
height:e.deg%180?e.dw:e.dh,scale:e.scaleMode},m=c,n=function(){try{l.get(s).setImage(h)}catch(a){}},r,s=a.uid(),t=f.createElement("div");for(r in j)t.setAttribute("data-img-"+r,j[r]);u(t,j);a.log("flash.image.publish");t.innerHTML=p(ajs.extend({id:s,src:a.staticPath+"FileAPI.flash.image.swf?r="+a.uid(),wmode:"opaque",flashvars:"scale="+j.scale+"&callback="+A(function q(){v(q);setTimeout(n,99);return!0})},j));m(!1,t);t=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,"+h}})})}},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)})}});h(a.Form.prototype,{toData:function(c){for(var e=this.items,f=e.length;f--;)if(e[f].file&&e[f].blob&&!e[f].blob.flashId)return this.parent.apply(this,arguments);a.log("flash.Form.toData");c(e)}});h(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={},h=this,j,m;a.each(e,function(a){a.file?(g[a.name]=a=a.blob,m=a.id,j=a.flashId):f[a.name]=a.blob});a.log("flash.XHR._send:",j,m,g);h.xhr={headers:{},abort:function(){l.cmd(j,"abort",m)},getResponseHeader:function(a){return this.headers[a]},getAllResponseHeaders:function(){return this.headers}};var n=a.queue(function(){l.cmd(j,"upload",{url:E(c.url),data:f,files:g,headers:c.headers,
callback:A(function x(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)v(x),"string"==typeof g&&(h.responseText=g.replace(/%22/g,'"').replace(/%5c/g,"\\").replace(/%26/g,"&").replace(/%25/g,"%")),h.end(e.status||200);else if("abort"==f||"error"==f)h.end(0,e.message),v(x)})})});a.each(g,function(c){n.inc();a.getInfo(c,n.next)});n.check()}})}};a.Flash=l;var s=new Image;a.event.one(s,
"error load",function(){a.support.dataURI=!(1!=s.width||1!=s.height);s=null;l.init()});s.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||{}});