Wordpress/wp-includes/js/plupload/plupload.html5.js

2 lines
15 KiB
JavaScript
Raw Normal View History

(function(g,j,h,d){var f;if(g.Uint8Array&&g.ArrayBuffer&&!XMLHttpRequest.prototype.sendAsBinary){XMLHttpRequest.prototype.sendAsBinary=function(o){var m=new Uint8Array(o.length);for(var n=0;n<o.length;n++){m[n]=(o.charCodeAt(n)&255)}this.send(m.buffer)}}function l(n,o){var m;if("FileReader" in g){m=new FileReader();m.readAsDataURL(n);m.onload=function(){o(m.result)}}else{return o(n.getAsDataURL())}}function k(n,o){var m;if("FileReader" in g){m=new FileReader();m.readAsBinaryString(n);m.onload=function(){o(m.result)}}else{return o(n.getAsBinary())}}function c(q,o,r,t){var n,p,m,s;l(q,function(u){n=j.createElement("canvas");n.style.display="none";j.body.appendChild(n);p=n.getContext("2d");m=new Image();m.onerror=m.onabort=function(){t({success:false})};m.onload=function(){var z,v,x,w,y;if(!o.width){o.width=m.width}if(!o.height){o.height=m.height}s=Math.min(o.width/m.width,o.height/m.height);if(s<1||(s===1&&r==="image/jpeg")){z=Math.round(m.width*s);v=Math.round(m.height*s);n.width=z;n.height=v;p.drawImage(m,0,0,z,v);if(r==="image/jpeg"){w=new e(atob(u.substring(u.indexOf("base64,")+7)));if(w.headers&&w.headers.length){y=new a();if(y.init(w.get("exif")[0])){y.setExif("PixelXDimension",z);y.setExif("PixelYDimension",v);w.set("exif",y.getBinary())}}if(o.quality){try{u=n.toDataURL(r,o.quality/100)}catch(A){u=n.toDataURL(r)}}}else{u=n.toDataURL(r)}u=u.substring(u.indexOf("base64,")+7);u=atob(u);if(w.headers&&w.headers.length){u=w.restore(u);w.purge()}n.parentNode.removeChild(n);t({success:true,data:u})}else{t({success:false})}};m.src=u})}h.runtimes.Html5=h.addRuntime("html5",{getFeatures:function(){var r,n,q,o,m,p=g;n=q=o=m=false;if(p.XMLHttpRequest){r=new XMLHttpRequest();q=!!r.upload;n=!!(r.sendAsBinary||r.upload)}if(n){o=!!(File&&(File.prototype.getAsDataURL||p.FileReader)&&r.sendAsBinary);m=!!(File&&File.prototype.slice)}f=navigator.userAgent.indexOf("Safari")>0&&navigator.vendor.indexOf("Apple")!==-1;return{html5:n,dragdrop:p.mozInnerScreenX!==d||m||f,jpgresize:o,pngresize:o,multipart:o||!!p.FileReader||!!p.FormData,progress:q,chunks:m||o,canOpenDialog:navigator.userAgent.indexOf("WebKit")!==-1}},init:function(p,q){var m={},n;function o(v){var t,s,u=[],w,r={};for(s=0;s<v.length;s++){t=v[s];if(r[t.name]){continue}r[t.name]=true;w=h.guid();m[w]=t;u.push(new h.File(w,t.fileName,t.fileSize||t.size))}if(u.length){p.trigger("FilesAdded",u)}}n=this.getFeatures();if(!n.html5){q({success:false});return}p.bind("Init",function(v){var F,E,B=[],u,C,s=v.settings.filters,t,A,r=j.body,D;F=j.createElement("div");F.id=v.id+"_html5_container";h.extend(F.style,{position:"absolute",background:p.settings.shim_bgcolor||"transparent",width:"100px",height:"100px",overflow:"hidden",zIndex:99999,opacity:p.settings.shim_bgcolor?"":0});F.className="plupload html5";if(p.settings.container){r=j.getElementById(p.settings.container);if(h.getStyle(r,"position")==="static"){r.style.position="relative"}}r.appendChild(F);no_type_restriction:for(u=0;u<s.length;u++){t=s[u].extensions.split(/,/);for(C=0;C<t.length;C++){if(t[C]==="*"){B=[];break no_type_restriction}A=h.mimeTypes[t[C]];if(A){B.push(A)}}}F.innerHTML='<input id="'+p.id+'_html5" style="width:100%;height:100%;font-size:99px" type="file" accept="'+B.join(",")+'" '+(p.settings.multi_selection?'multiple="multiple"':"")+" />";D=j.getElementById(p.id+"_html5");D.onchange=function(){o(this.files);this.value=""};E=j.getElementById(v.settings.browse_button);if(E){var x=v.settings.browse_button_hover,z=v.settings.browse_button_active,w=v.features.canOpenDialog?E:F;if(x){h.addEvent(w,"mouseover",function(){h.addClass(E,x)},v.id);h.addEvent(w,"mouseout",function(){h.removeClass(E,x)},v.id)}if(z){h.addEvent(w,"mousedown",function(){h.addClass(E,z)},v.id);h.addEvent(j.body,"mouseup",function(){h.removeClass(E,z)},v.id)}if(v.features.canOpenDialog){h.addEvent(E,"click",function(y){j.getElementById(v.id+"_html5").click();y.preventDefault()},v.id)}}});p.bind("PostInit",function(){var r=j.getElementById(p.settings.drop_element);if(r){if(f){h.addEvent(r,"dragenter",function(v){var u,s,t;u=j.getElementById(p.id+"_drop"