forked from AVapps/FileReader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.FileReader.min.js
1 lines (1 loc) · 4.74 KB
/
jquery.FileReader.min.js
1
(function(a){var b,c=a.Callbacks("once unique memory"),d=0,e=null;a.fn.fileReader=function(d){var e;return d=a.extend({id:"fileReaderSWFObject",multiple:null,accept:null,label:null,extensions:null,filereader:"files/filereader.swf",expressInstall:null,debugMode:!1,callback:!1},d),e=this,c.add(function(){return b(e,d)}),a.isFunction(d.callback)&&c.add(d.callback),FileAPIProxy.ready||FileAPIProxy.init(d),this},b=function(b,c){return b.each(function(b,f){f=a(f);var g=f.attr("id");g||(g="flashFileInput"+d,f.attr("id",g),d++),c.multiple=c.multiple===null?!!f.attr("multiple"):!!c.multiple,c.accept=c.accept===null?f.attr("accept"):c.multiple,FileAPIProxy.inputs[g]=f,FileAPIProxy.swfObject.add(g,c.multiple,c.accept,c.label,c.extensions),f.css("z-index",0).mouseover(function(a){g!==e&&(a=a||window.event,e=g,FileAPIProxy.swfObject.mouseover(g),FileAPIProxy.container.height(f.outerHeight()).width(f.outerWidth()).position({of:f}))}).click(function(a){return a.preventDefault(),a.stopPropagation(),a.stopImmediatePropagation(),!1})})},window.FileAPIProxy={ready:!1,init:function(b){var d=this;this.debugMode=b.debugMode,this.container=a("<div>").attr("id",b.id).wrap("<div>").parent().css({width:"1px",height:"1px",display:"inline-block",background:"transparent","z-index":99999}).on("mouseover mouseout mousedown mouseup",function(b){e&&a("#"+e).trigger(b.type)}).appendTo("body"),swfobject.embedSWF(b.filereader,b.id,"100%","100%","10",b.expressInstall,{debugMode:b.debugMode?!0:""},{wmode:"transparent",allowScriptAccess:"sameDomain"},{},function(b){d.swfObject=b.ref,a(d.swfObject).css({display:"block",outline:0}).attr("tabindex",0),d.ready&&c.fire(),d.ready=b.success})},swfObject:null,container:null,inputs:{},readers:{},onFileInputEvent:function(a){var b;this.debugMode&&console.info("FileInput Event ",a.type,a),a.target in this.inputs&&(b=this.inputs[a.target],a.target=b[0],a.type==="change"&&(a.files=new FileList(a.files),a.target={files:a.files}),b.trigger(a)),window.focus()},onFileReaderEvent:function(a){var b;this.debugMode&&console.info("FileReader Event ",a.type,a,a.target in this.readers),a.target in this.readers&&(b=this.readers[a.target],a.target=b,b._handleFlashEvent.call(b,a))},onFileReaderError:function(a){this.debugMode&&console.log(a)},onSWFReady:function(){return this.ready&&c.fire(),this.ready=!0,!0}},window.FileReader=function(){this.EMPTY=0,this.LOADING=1,this.DONE=2,this.readyState=0,this.result=null,this.error=null,this.onloadstart=null,this.onprogress=null,this.onload=null,this.onabort=null,this.onerror=null,this.onloadend=null,this._callbacks={loadstart:a.Callbacks("unique"),progress:a.Callbacks("unique"),abort:a.Callbacks("unique"),error:a.Callbacks("unique"),load:a.Callbacks("unique"),loadend:a.Callbacks("unique")},this._id=null},window.FileReader.prototype={readAsBinaryString:function(a){this._start(a),FileAPIProxy.swfObject.read(a.input,a.name,"readAsBinaryString")},readAsText:function(a){this._start(a),FileAPIProxy.swfObject.read(a.input,a.name,"readAsText")},readAsDataURL:function(a){this._start(a),FileAPIProxy.swfObject.read(a.input,a.name,"readAsDataURL")},readAsArrayBuffer:function(){throw"Whoops FileReader.readAsArrayBuffer is unimplemented"},abort:function(){this.result=null;if(this.readyState===this.EMPTY||this.readyState===this.DONE)return;FileAPIProxy.swfObject.abort(this._id)},addEventListener:function(a,b){a in this._callbacks&&this._callbacks[a].add(b)},removeEventListener:function(a,b){a in this._callbacks&&this._callbacks[a].remove(b)},dispatchEvent:function(b){var c;return b.target=this,b.type in this._callbacks&&(c=this["on"+b.type],a.isFunction(c)&&c(b),this._callbacks[b.type].fire(b)),!0},_register:function(a){this._id=a.input+"."+a.name,FileAPIProxy.readers[this._id]=this},_start:function(a){this._register(a);if(this.readyState===this.LOADING)throw{type:"InvalidStateError",code:11,message:"The object is in an invalid state."}},_handleFlashEvent:function(a){switch(a.type){case"loadstart":this.readyState=this.LOADING;break;case"loadend":this.readyState=this.DONE;break;case"load":this.readyState=this.DONE,this.result=FileAPIProxy.swfObject.result(this._id);break;case"error":this.result=null,this.error={name:"NotReadableError",message:"The File cannot be read!"}}this.dispatchEvent(new FileReaderEvent(a))}},FileReaderEvent=function(a){this.initEvent(a)},FileReaderEvent.prototype={initEvent:function(b){a.extend(this,{type:null,target:null,currentTarget:null,eventPhase:2,bubbles:!1,cancelable:!1,defaultPrevented:!1,isTrusted:!1,timeStamp:(new Date).getTime()},b)},stopPropagation:function(){},stopImmediatePropagation:function(){},preventDefault:function(){}},FileList=function(a){var b;if(a){for(b=0;b<a.length;b++)this[b]=a[b];this.length=a.length}else this.length=0},FileList.prototype={item:function(a){return a in this?this[a]:null}}})(jQuery);