photomix/public/javascripts/plupload/js/plupload.html5.min.js

1 line
13 KiB
JavaScript
Raw Normal View History

2011-04-11 06:43:27 +02:00
(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,