photomix/public/javascripts/plupload/js/plupload.html5.min.js
2011-04-11 12:43:27 +08:00

1 line
13 KiB
JavaScript

(function(e,g,f,c){var d,a;function i(k,l){var j;if("FileReader" in e){j=new FileReader();j.readAsDataURL(k);j.onload=function(){l(j.result)}}else{return l(k.getAsDataURL())}}function h(k,l){var j;if("FileReader" in e){j=new FileReader();j.readAsBinaryString(k);j.onload=function(){l(j.result)}}else{return l(k.getAsBinary())}}function b(p,r,o,j,q){var l,k,n,m;i(p,function(s){l=g.createElement("canvas");l.style.display="none";g.body.appendChild(l);k=l.getContext("2d");n=new Image();n.onload=function(){var w,t,u,v,x;m=Math.min(r/n.width,o/n.height);if(m<1){w=Math.round(n.width*m);t=Math.round(n.height*m);l.width=w;l.height=t;k.drawImage(n,0,0,w,t);x=new a();x.init(atob(s.substring(s.indexOf("base64,")+7)));v=x.APP1({width:w,height:t});s=l.toDataURL(j);s=s.substring(s.indexOf("base64,")+7);s=atob(s);if(v){x.init(s);x.setAPP1(v);s=x.getBinary()}l.parentNode.removeChild(l);q({success:true,data:s})}else{q({success:false})}};n.src=s})}f.runtimes.Html5=f.addRuntime("html5",{getFeatures:function(){var o,k,n,l,j,m=e;k=n=l=j=false;if(m.Uint8Array&&m.ArrayBuffer&&!XMLHttpRequest.prototype.sendAsBinary){XMLHttpRequest.prototype.sendAsBinary=function(t){var s,q,u,p;s=new ArrayBuffer(t.length);q=new Uint8Array(s,0);for(var r=0;r<t.length;r++){q[r]=(t.charCodeAt(r)&255)}u=new BlobBuilder();u.append(s);p=u.getBlob();this.send(p)}}if(m.XMLHttpRequest){o=new XMLHttpRequest();n=!!o.upload;k=!!(o.sendAsBinary||o.upload)}if(k){l=!!(File&&(File.prototype.getAsDataURL||m.FileReader)&&o.sendAsBinary);j=!!(File&&File.prototype.slice)}d=navigator.userAgent.indexOf("Safari")>0&&navigator.vendor.indexOf("Apple")!==-1;return{html5:k,dragdrop:m.mozInnerScreenX!==c||j||d,jpgresize:l,pngresize:l,multipart:l||!!m.FileReader||!!m.FormData,progress:n,chunking:j||l,canOpenDialog:navigator.userAgent.indexOf("WebKit")!==-1}},init:function(m,n){var j={},k;function l(s){var q,p,r=[],t,o={};for(p=0;p<s.length;p++){q=s[p];if(o[q.name]){continue}o[q.name]=true;t=f.guid();j[t]=q;r.push(new f.File(t,q.fileName,q.fileSize||q.size))}if(r.length){m.trigger("FilesAdded",r)}}k=this.getFeatures();if(!k.html5){n({success:false});return}m.bind("Init",function(s){var C,B,x=[],r,z,p=s.settings.filters,q,w,o=g.body,A;C=g.createElement("div");C.id=s.id+"_html5_container";for(r=0;r<p.length;r++){q=p[r].extensions.split(/,/);for(z=0;z<q.length;z++){w=f.mimeTypes[q[z]];if(w){x.push(w)}}}f.extend(C.style,{position:"absolute",background:m.settings.shim_bgcolor||"transparent",width:"100px",height:"100px",overflow:"hidden",zIndex:99999,opacity:m.settings.shim_bgcolor?"":0});C.className="plupload html5";if(m.settings.container){o=g.getElementById(m.settings.container);o.style.position="relative"}o.appendChild(C);C.innerHTML='<input id="'+m.id+'_html5" style="width:100%;height:100%;" type="file" accept="'+x.join(",")+'" '+(m.settings.multi_selection?'multiple="multiple"':"")+" />";A=g.getElementById(m.id+"_html5");A.onchange=function(){l(this.files);this.value=""};B=g.getElementById(s.settings.browse_button);if(B){var u=s.settings.browse_button_hover,v=s.settings.browse_button_active,t=s.features.canOpenDialog?B:C;if(u){f.addEvent(t,"mouseover",function(){f.addClass(B,u)},s.id);f.addEvent(t,"mouseout",function(){f.removeClass(B,u)},s.id)}if(v){f.addEvent(t,"mousedown",function(){f.addClass(B,v)},s.id);f.addEvent(g.body,"mouseup",function(){f.removeClass(B,v)},s.id)}if(s.features.canOpenDialog){f.addEvent(B,"click",function(y){g.getElementById(s.id+"_html5").click();y.preventDefault()},s.id)}}});m.bind("PostInit",function(){var o=g.getElementById(m.settings.drop_element);if(o){if(d){f.addEvent(o,"dragenter",function(s){var r,p,q;r=g.getElementById(m.id+"_drop");if(!r){r=g.createElement("input");r.setAttribute("type","file");r.setAttribute("id",m.id+"_drop");r.setAttribute("multiple","multiple");f.addEvent(r,"change",function(){l(this.files);f.removeEvent(r,"change",m.id);r.parentNode.removeChild(r)},m.id);o.appendChild(r)}p=f.getPos(o,g.getElementById(m.settings.container));q=f.getSize(o);f.extend(o.style,{position:"relative"});f.extend(r.style,{position:"absolute",display:"block",top:0,left:0,width:q.w+"px",height:q.h+"px",opacity:0})},m.id);return}f.addEvent(o,"dragover",function(p){p.preventDefault()},m.id);f.addEvent(o,"drop",function(q){var p=q.dataTransfer;if(p&&p.files){l(p.files)}q.preventDefault()},m.id)}});m.bind("Refresh",function(o){var p,r,s,t,q;p=g.getElementById(m.settings.browse_button);if(p){r=f.getPos(p,g.getElementById(o.settings.container));s=f.getSize(p);t=g.getElementById(m.id+"_html5_container");f.extend(t.style,{top:r.y+"px",left:r.x+"px",width:s.w+"px",height:s.h+"px"});if(m.features.canOpenDialog){q=parseInt(p.parentNode.style.zIndex,10);if(isNaN(q)){q=0}f.extend(p.style,{position:"relative",zIndex:q});f.extend(t.style,{zIndex:q-1})}}});m.bind("UploadFile",function(o,q){var r=o.settings,t,p;function s(u){var x=0,w=0;function v(){var E=u,L,M,H,I,J=0,A="----pluploadboundary"+f.guid(),D,F,B,C="--",K="\r\n",G="",z,y=o.settings.url;if(q.status==f.DONE||q.status==f.FAILED||o.state==f.STOPPED){return}I={name:q.target_name||q.name};if(r.chunk_size&&k.chunking){D=r.chunk_size;H=Math.ceil(q.size/D);F=Math.min(D,q.size-(x*D));if(typeof(u)=="string"){E=u.substring(x*D,x*D+F)}else{E=u.slice(x*D,F)}I.chunk=x;I.chunks=H}else{F=q.size}L=new XMLHttpRequest();M=L.upload;if(M){M.onprogress=function(N){q.loaded=Math.min(q.size,w+N.loaded-J);o.trigger("UploadProgress",q)}}if(!o.settings.multipart||!k.multipart){y=f.buildUrl(o.settings.url,I)}else{I.name=q.target_name||q.name}L.open("post",y,true);L.onreadystatechange=function(){var N,P;if(L.readyState==4){try{N=L.status}catch(O){N=0}if(N>=400){o.trigger("Error",{code:f.HTTP_ERROR,message:f.translate("HTTP Error."),file:q,status:N})}else{if(H){P={chunk:x,chunks:H,response:L.responseText,status:N};o.trigger("ChunkUploaded",q,P);w+=F;if(P.cancelled){q.status=f.FAILED;return}q.loaded=Math.min(q.size,(x+1)*D)}else{q.loaded=q.size}o.trigger("UploadProgress",q);if(!H||++x>=H){q.status=f.DONE;o.trigger("FileUploaded",q,{response:L.responseText,status:N});t=u=j[q.id]=null}else{v()}}L=E=B=G=null}};f.each(o.settings.headers,function(O,N){L.setRequestHeader(N,O)});if(o.settings.multipart&&k.multipart){if(!L.sendAsBinary){B=new FormData();f.each(f.extend(I,o.settings.multipart_params),function(O,N){B.append(N,O)});B.append(o.settings.file_data_name,E);L.send(B);return}L.setRequestHeader("Content-Type","multipart/form-data; boundary="+A);f.each(f.extend(I,o.settings.multipart_params),function(O,N){G+=C+A+K+'Content-Disposition: form-data; name="'+N+'"'+K+K;G+=unescape(encodeURIComponent(O))+K});z=f.mimeTypes[q.name.replace(/^.+\.([^.]+)/,"$1")]||"application/octet-stream";G+=C+A+K+'Content-Disposition: form-data; name="'+o.settings.file_data_name+'"; filename="'+unescape(encodeURIComponent(q.name))+'"'+K+"Content-Type: "+z+K+K+E+K+C+A+C+K;J=G.length-E.length;E=G}else{L.setRequestHeader("Content-Type","application/octet-stream")}if(L.sendAsBinary){L.sendAsBinary(E)}else{L.send(E)}}v()}t=j[q.id];p=o.settings.resize;if(k.jpgresize){if(p&&/\.(png|jpg|jpeg)$/i.test(q.name)){b(t,p.width,p.height,/\.png$/i.test(q.name)?"image/png":"image/jpeg",function(u){if(u.success){q.size=u.data.length;s(u.data)}else{h(t,s)}})}else{h(t,s)}}else{s(t)}});m.bind("Destroy",function(o){var q,r,p=g.body,s={inputContainer:o.id+"_html5_container",inputFile:o.id+"_html5",browseButton:o.settings.browse_button,dropElm:o.settings.drop_element};for(q in s){r=g.getElementById(s[q]);if(r){f.removeAllEvents(r,o.id)}}f.removeAllEvents(g.body,o.id);if(o.settings.container){p=g.getElementById(o.settings.container)}p.removeChild(g.getElementById(s.inputContainer))});n({success:true})}});a=function(){var l,m,B,v,w,q,u,x,G,s,D,z,n,F,j,E,C,o,k;function r(){var K=false,I;function L(N,P){var M=K?0:-8*(P-1),Q=0,O;for(O=0;O<P;O++){Q|=(I.charCodeAt(N+O)<<Math.abs(M+O*8))}return Q}function H(M,O,N){I=I.substr(0,M)+O+I.substr((N===true?O.length:0)+M)}function J(N,O,Q){var R="",M=K?0:-8*(Q-1),P;for(P=0;P<Q;P++){R+=String.fromCharCode((O>>Math.abs(M+P*8))&255)}H(N,R,true)}return{II:function(M){if(M===j){return K}else{K=M}},init:function(M){I=M},SEGMENT:function(M,O,N){if(!arguments.length){return I}if(typeof O=="number"){return I.substr(parseInt(M,10),O)}H(M,O,N)},BYTE:function(M){return L(M,1)},SHORT:function(M){return L(M,2)},LONG:function(M,N){if(N===j){return L(M,4)}else{J(M,N,4)}},SLONG:function(M){var N=L(M,4);return(N>2147483647?N-4294967296:N)},STRING:function(M,N){var O="";for(N+=M;M<N;M++){O+=String.fromCharCode(L(M,1))}return O}}}G=new r();E={274:"Orientation",34665:"ExifIFDPointer",34853:"GPSInfoIFDPointer"};C={36864:"ExifVersion",40961:"ColorSpace",40962:"PixelXDimension",40963:"PixelYDimension",36867:"DateTimeOriginal",33434:"ExposureTime",33437:"FNumber",34855:"ISOSpeedRatings",37377:"ShutterSpeedValue",37378:"ApertureValue",37383:"MeteringMode",37384:"LightSource",37385:"Flash",41986:"ExposureMode",41987:"WhiteBalance",41990:"SceneCaptureType",41988:"DigitalZoomRatio",41992:"Contrast",41993:"Saturation",41994:"Sharpness"};o={0:"GPSVersionID",1:"GPSLatitudeRef",2:"GPSLatitude",3:"GPSLongitudeRef",4:"GPSLongitude"};k={ColorSpace:{1:"sRGB",0:"Uncalibrated"},MeteringMode:{0:"Unknown",1:"Average",2:"CenterWeightedAverage",3:"Spot",4:"MultiSpot",5:"Pattern",6:"Partial",255:"Other"},LightSource:{1:"Daylight",2:"Fliorescent",3:"Tungsten",4:"Flash",9:"Fine weather",10:"Cloudy weather",11:"Shade",12:"Daylight fluorescent (D 5700 - 7100K)",13:"Day white fluorescent (N 4600 -5400K)",14:"Cool white fluorescent (W 3900 - 4500K)",15:"White fluorescent (WW 3200 - 3700K)",17:"Standard light A",18:"Standard light B",19:"Standard light C",20:"D55",21:"D65",22:"D75",23:"D50",24:"ISO studio tungsten",255:"Other"},Flash:{0:"Flash did not fire.",1:"Flash fired.",5:"Strobe return light not detected.",7:"Strobe return light detected.",9:"Flash fired, compulsory flash mode",13:"Flash fired, compulsory flash mode, return light not detected",15:"Flash fired, compulsory flash mode, return light detected",16:"Flash did not fire, compulsory flash mode",24:"Flash did not fire, auto mode",25:"Flash fired, auto mode",29:"Flash fired, auto mode, return light not detected",31:"Flash fired, auto mode, return light detected",32:"No flash function",65:"Flash fired, red-eye reduction mode",69:"Flash fired, red-eye reduction mode, return light not detected",71:"Flash fired, red-eye reduction mode, return light detected",73:"Flash fired, compulsory flash mode, red-eye reduction mode",77:"Flash fired, compulsory flash mode, red-eye reduction mode, return light not detected",79:"Flash fired, compulsory flash mode, red-eye reduction mode, return light detected",89:"Flash fired, auto mode, red-eye reduction mode",93:"Flash fired, auto mode, return light not detected, red-eye reduction mode",95:"Flash fired, auto mode, return light detected, red-eye reduction mode"},ExposureMode:{0:"Auto exposure",1:"Manual exposure",2:"Auto bracket"},WhiteBalance:{0:"Auto white balance",1:"Manual white balance"},SceneCaptureType:{0:"Standard",1:"Landscape",2:"Portrait",3:"Night scene"},Contrast:{0:"Normal",1:"Soft",2:"Hard"},Saturation:{0:"Normal",1:"Low saturation",2:"High saturation"},Sharpness:{0:"Normal",1:"Soft",2:"Hard"},GPSLatitudeRef:{N:"North latitude",S:"South latitude"},GPSLongitudeRef:{E:"East longitude",W:"West longitude"}};function t(H,O){var J=G.SHORT(H),L,R,T,N,M,I,K,P,Q=[],S={};for(L=0;L<J;L++){K=I=H+12*L+2;T=O[G.SHORT(K)];if(T===j){continue}N=G.SHORT(K+=2);M=G.LONG(K+=2);K+=4;Q=[];switch(N){case 1:case 7:if(M>4){K=G.LONG(K)+F}for(R=0;R<M;R++){Q[R]=G.BYTE(K+R)}break;case 2:if(M>4){K=G.LONG(K)+F}S[T]=G.STRING(K,M-1);continue;case 3:if(M>2){K=G.LONG(K)+F}for(R=0;R<M;R++){Q[R]=G.SHORT(K+R*2)}break;case 4:if(M>1){K=G.LONG(K)+F}for(R=0;R<M;R++){Q[R]=G.LONG(K+R*4)}break;case 5:K=G.LONG(K)+F;for(R=0;R<M;R++){Q[R]=G.LONG(K+R*4)/G.LONG(K+R*4+4)}break;case 9:K=G.LONG(K)+F;for(R=0;R<M;R++){Q[R]=G.SLONG(K+R*4)}break;case 10:K=G.LONG(K)+F;for(R=0;R<M;R++){Q[R]=G.SLONG(K+R*4)/G.SLONG(K+R*4+4)}break;default:continue}P=(M==1?Q[0]:Q);if(k.hasOwnProperty(T)&&typeof P!="object"){S[T]=k[T][P]}else{S[T]=P}}return S}function A(){var H=x+4;F+=x;if(G.STRING(H,4).toUpperCase()!=="EXIF"||G.SHORT(H+=4)!==0){return}G.II(G.SHORT(H+=2)==18761);if(G.SHORT(H+=2)!==42){return}n=F+G.LONG(H+=2);l=t(n,E);D=("ExifIFDPointer" in l?F+l.ExifIFDPointer:j);z=("GPSInfoIFDPointer" in l?F+l.GPSInfoIFDPointer:j);return true}function p(H,M,L){var K=H.SHORT(L),J,I;for(I=0;I<K;I++){J=L+12*I+2;if(H.SHORT(J)==M){return J+8}}}function y(K,I){var J,L,M=D!=j?D-x:j,H=new r();H.init(u);H.II(G.II());if(M===j){return}J=p(H,40962,M);if(J!==j){H.LONG(J,K)}L=p(H,40963,M);if(L!==j){H.LONG(L,I)}u=H.SEGMENT()}return{init:function(H){F=10;l=m=B=v=w=q=u=x=s=j;G.init(H);if(G.SHORT(0)!==65496){return false}switch(G.SHORT(2)){case 65504:w=2;q=G.SHORT(4)+2;if(G.SHORT(q)==65505){x=q;s=G.SHORT(q+2)+2}break;case 65505:x=2;s=G.SHORT(4)+2;break;default:return false}if(s!==j){A()}},APP1:function(H){if(x===j&&s===j){return}u=u||(u=G.SEGMENT(x,s));if(H!==j&&"width" in H&&"height" in H){y(H.width,H.height)}return u},EXIF:function(){m=t(D,C);m.ExifVersion=String.fromCharCode(m.ExifVersion[0],m.ExifVersion[1],m.ExifVersion[2],m.ExifVersion[3]);return m},GPS:function(){B=t(z,o);B.GPSVersionID=B.GPSVersionID.join(".");return B},setAPP1:function(H){if(x!==j){return false}G.SEGMENT((w?w+q:2),H)},getBinary:function(){return G.SEGMENT()}}}})(window,document,plupload);