From 562dc54aa4ab99154a81c53200840a9a9765a568 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Mon, 11 Feb 2013 19:21:58 +0400 Subject: [PATCH] * js rebuild --- FileAPI.min.js | 120 ++++++++++++++++++++++---------------------- README.md | 20 +++++--- lib/FileAPI.Form.js | 2 +- lib/FileAPI.core.js | 4 +- 4 files changed, 76 insertions(+), 70 deletions(-) diff --git a/FileAPI.min.js b/FileAPI.min.js index 83a3b047..8df5389d 100644 --- a/FileAPI.min.js +++ b/FileAPI.min.js @@ -4,64 +4,64 @@ * @author RubaXa * @build lib/canvas-to-blob lib/FileAPI.core lib/FileAPI.Image lib/FileAPI.Form lib/FileAPI.XHR lib/FileAPI.Flash */ -(function(a){var k=a.HTMLCanvasElement&&a.HTMLCanvasElement.prototype,h;if(h=a.Blob)try{h=Boolean(new Blob)}catch(r){h=!1}var l=h;if(h=l)if(h=a.Uint8Array)try{h=100===(new Blob([new Uint8Array(100)])).size}catch(f){h=!1}var c=h,e=a.BlobBuilder||a.WebKitBlobBuilder||a.MozBlobBuilder||a.MSBlobBuilder,m=(l||e)&&a.atob&&a.ArrayBuffer&&a.Uint8Array&&function(a){var g,f,h,k;g=0<=a.split(",")[0].indexOf("base64")?atob(a.split(",")[1]):decodeURIComponent(a.split(",")[1]);f=new ArrayBuffer(g.length);h=new Uint8Array(f); -for(k=0;k=a&&!c&&n.end()},isFail:function(){return c},fail:function(){!c&&b(c=!0)},end:function(){g||(g=!0,b())}};return n},each:h,afor:function(b,d){var a=0,c=b.length; -g(b)&&c--?function B(){d(c!=a&&B,b[a],a++)}():d(!1)},extend:function(b){h(arguments,function(d){h(d,function(d,a){b[a]=d})});return b},isFile:function(b){return d&&b&&b instanceof s},isCanvas:function(b){return b&&U.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){j.isCanvas(b)?c(b,d,"load",j.toDataURL(b)):e(b,d,"DataURL")},readAsBinaryString:function(b, -d){u&&u.prototype.readAsBinaryString?e(b,d,"BinaryString"):e(b,function(b){if("load"==b.type)try{b.result=j.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(j.toDataURL(b).replace(W,""))},readAsImage:function(b, -d,a){if(j.isFile(b))if(D){var g=D.createObjectURL(b);g===k?c(b,d,"error"):j.readAsImage(g,d,a)}else j.readAsDataURL(b,function(g){"load"==g.type?j.readAsImage(g.result,d,a):(a||"error"==g.type)&&c(b,d,g,null,{loaded:g.loaded,total:g.total})});else j.isCanvas(b)?c(b,d,"load",b):G.test(b.nodeName)?b.complete?c(b,d,"load",b):f(b,"error abort load",function B(a){"load"==a.type&&D&&D.revokeObjectURL(b.src);l(b,"error abort load",B);c(b,d,a,b)}):b.iframe?c(b,d,{type:"error"}):(g=new Image,g.src=b.dataURL|| -b,j.readAsImage(g,d,a))},checkFileObj:function(b){var d={};"object"==typeof b?d=b:d.name=(b+"").split(/(\\|\/)/g).pop();d.type===k&&(d.type=d.name.split(".").pop());h(P,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||{},n=g(c.items)&&c.items[0]&&m(c.items[0]),e=j.queue(function(){d(a)});h((n?c.items:c.files)||[],function(b){e.inc();if(n)q(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(u)try{var c=new u;f(c,L,function(b){b="error"!=b.type;d(b);b&&c.abort()});c.readAsDataURL(b)}catch(g){d(!1)}else d(null);else d(!0)}});e.check()},getFiles:function(b,a,c){var n=[];if(c)return j.filterFiles(j.getFiles(b),a,c),null;b.jquery&&(b.each(function(){n=n.concat(j.getFiles(this))}),b=n,n=[]);"string"==typeof a&&(a=j.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?n=b.files:!d&&I.test(b&&b.tagName)?j.trim(b.value)&&(n=[j.checkFileObj(b.value)],n[0].blob=b,n[0].iframe=!0):g(b)&&(n=b);!a&&I.test(b&&b.tagName)&&(a=j.getFilesFilter(b));return j.filter(n,function(b){return!a||a.test(b.name)})},getInfo:function(b,d){var a={},c=R.concat();j.isFile(b)?function B(){var g=c.shift();g?g.test(b.type)?g(b,function(b,c){b?d(b):(j.extend(a,c),B())}):B():d(!1,a)}():d("not_support",a)},addInfoReader:function(b,d){d.test=function(d){return b.test(d)}; -R.push(d)},addMime:function(b,d){P[b]=RegExp("("+d.replace(/,/g,"|")+")$","i")},filter:function(b,d){for(var a=[],c=0,g=b.length,n;c>2,c=(c&3)<<4|g>>4;isNaN(g)?g=n=64:(g=(g&15)<<2|n>>6,n=isNaN(n)?64:n&63);d+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(e)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(c)+ -"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(g)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(n)}return d}};h({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){j.addMime(d,b)});j.addInfoReader(/^image/,function(b,d){if(!b.__dimensions){var a=b.__dimensions=j.defer();j.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)});j.event.dnd=function(b,d,a){var c,g;a||(a=d,d=j.F);u?(r(b,"dragenter dragleave dragover",function(b){for(var a=((b.originalEvent||b||"").dataTransfer||{}).types,n=a&&a.length;n--;)~a[n].indexOf("File")&&(b.preventDefault(),g!==b.type&&(g=b.type, -"dragleave"!=g&&d.call(b.currentTarget,!0,b),clearTimeout(c),c=setTimeout(function(){d.call(b.currentTarget,"dragleave"!=g,b)},50)))}),r(b,"drop",function(b){b.preventDefault();g=0;d.call(b.currentTarget,!1,b);j.getDropFiles(b,function(d){a.call(b.currentTarget,d,b)})})):j.log("Drag'n'Drop -- not supported")};t&&!t.fn.dnd&&(t.fn.dnd=function(b,d){return this.each(function(){j.event.dnd(this,b,d)})});a.FileAPI=j.extend(j,a.FileAPI);j.flashUrl||(j.flashUrl=j.staticPath+"FileAPI.flash.swf");j.flashImageUrl|| -(j.flashImageUrl=j.staticPath+"FileAPI.flash.image.swf")})(window); -(function(a,k,h){function r(a,c){if(!(this instanceof r))return new r(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 l=Math.min,f=Math.round,c=!1,e={8:270,3:180,6:90};try{c=-1=m?(m=e,s=m/r):(s=c,m=s*r),m!=e||s!=c)g.sx=~~((e-m)/2),g.sy=~~((c-s)/2),e=m,c=s}else s&&("min"==s?(h=f(m=r?l(e,h):k*m),k=f(m>=r?h/m:l(c,k))));g.sw=e;g.sh=c;g.dw=h;g.dh=k;return g},_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 g=this;"auto"==g.matrix.deg?a.getInfo(this.file,function(a,f){g.matrix.deg= -e[f&&f.exif&&f.exif.Orientation]||0;g._trans(c)}):g._trans(c)}else c("not_support")},toData:function(a){this.get(a)}};r.transform=function(c,g,e,f){a.getInfo(c,function(l,m){var k={},s=a.queue(function(a){f(a,k)});l?s.fail():a.each(g,function(a,g){if(!s.isFail()){var f=r(m.nodeType?m:c);if("function"==typeof a)a(m,f);else if(a.width)f[a.preview?"preview":"resize"](a.width,a.height,a.type);else a.maxWidth&&(m.width>a.maxWidth||m.height>a.maxHeight)&&f.resize(a.maxWidth,a.maxHeight,"max");a.rotate=== -h&&e&&(a.rotate="auto");f.rotate(a.rotate);s.inc();f.toData(function(a,c){a?s.fail():(k[g]=c,s.next())})}})})};a.support.canvas=a.support.transform=c;a.Image=r})(FileAPI,document); -(function(a,k,h){var r=k.encodeURIComponent,l=k.FormData;k=function(){this.items=[]};k.prototype={append:function(a,c,e,h){this.items.push({name:a,blob:c&&c.blob||c,file:e||c.name,type:h||c.type})},each:function(a){for(var c=0,e=this.items.length;c',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},q=e.getElementsByTagName("form")[0],q.appendChild(f), -k.log(q.parentNode.innerHTML),document.body.appendChild(e),c.xhr.node=e,a[m]=function(a,f,h){c.readyState=4;c.responseText=h;c.end(a,f);e=null},c.readyState=2,q.submit(),q=null):(e=c.xhr=k.getXHR(),e.open("POST",q,!0),e.withCredential="true",(!h.headers||!h.headers["X-Requested-With"])&&e.setRequestHeader("X-Requested-With","XMLHttpRequest"),k.each(h.headers,function(a,c){e.setRequestHeader(c,a)}),k.support.chunked&&0=a&&!c&&j.end()},isFail:function(){return c},fail:function(){!c&&b(c=!0)},end:function(){d||(d=!0,b())}};return j},each:g,afor:function(b,e){var a=0,c=b.length; +j(b)&&c--?function B(){e(c!=a&&B,b[a],a++)}():e(!1)},extend:function(b){g(arguments,function(e){g(e,function(e,a){b[a]=e})});return b},isFile:function(b){return e&&b&&b instanceof r},isCanvas:function(b){return b&&U.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,e){h.isCanvas(b)?c(b,e,"load",h.toDataURL(b)):d(b,e,"DataURL")},readAsBinaryString:function(b, +e){u&&u.prototype.readAsBinaryString?d(b,e,"BinaryString"):d(b,function(b){if("load"==b.type)try{b.result=h.toBinaryString(b.result)}catch(a){b.type="error",b.message=a.toString()}e(b)},"DataURL")},readAsArrayBuffer:function(b,e){d(b,e,"ArrayBuffer")},readAsText:function(b,e,a){a||(a=e,e="utf-8");d(b,a,"Text",e)},toDataURL:function(b){if("string"==typeof b)return b;if(b.toDataURL)return b.toDataURL("image/png")},toBinaryString:function(b){return a.atob(h.toDataURL(b).replace(W,""))},readAsImage:function(b, +e,a){if(h.isFile(b))if(x){var d=x.createObjectURL(b);d===k?c(b,e,"error"):h.readAsImage(d,e,a)}else h.readAsDataURL(b,function(d){"load"==d.type?h.readAsImage(d.result,e,a):(a||"error"==d.type)&&c(b,e,d,null,{loaded:d.loaded,total:d.total})});else h.isCanvas(b)?c(b,e,"load",b):F.test(b.nodeName)?b.complete?c(b,e,"load",b):f(b,"error abort load",function B(a){"load"==a.type&&x&&x.revokeObjectURL(b.src);l(b,"error abort load",B);c(b,e,a,b)}):b.iframe?c(b,e,{type:"error"}):(d=new Image,d.src=b.dataURL|| +b,h.readAsImage(d,e,a))},checkFileObj:function(b){var e={};"object"==typeof b?e=b:e.name=(b+"").split(/(\\|\/)/g).pop();e.type===k&&(e.type=e.name.split(".").pop());g(P,function(b,a){b.test(e.type)&&(e.type=a+"/"+e.type)});return e},getDropFiles:function(b,e){var a=[],c=(b.originalEvent||b||"").dataTransfer||{},d=j(c.items)&&c.items[0]&&m(c.items[0]),w=h.queue(function(){e(a)});g((d?c.items:c.files)||[],function(b){w.inc();if(d)p(b,function(b,e){!b&&a.push.apply(a,e);w.next()});else{var e=function(e){e&& +a.push(b);w.next()};if(!b.type&&0==b.size%4096&&102400>=b.size)if(u)try{var c=new u;f(c,L,function(b){b="error"!=b.type;e(b);b&&c.abort()});c.readAsDataURL(b)}catch(j){e(!1)}else e(null);else e(!0)}});w.check()},getFiles:function(b,a,c){var d=[];if(c)return h.filterFiles(h.getFiles(b),a,c),null;b.jquery&&(b.each(function(){d=d.concat(h.getFiles(this))}),b=d,d=[]);"string"==typeof a&&(a=h.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?d=b.files:!e&&H.test(b&&b.tagName)?h.trim(b.value)&&(d=[h.checkFileObj(b.value)],d[0].blob=b,d[0].iframe=!0):j(b)&&(d=b);!a&&H.test(b&&b.tagName)&&(a=h.getFilesFilter(b));return h.filter(d,function(b){return!a||a.test(b.name)})},getInfo:function(b,e){var a={},c=R.concat();h.isFile(b)?function B(){var d=c.shift();d?d.test(b.type)?d(b,function(b,c){b?e(b):(h.extend(a,c),B())}):B():e(!1,a)}():e("not_support",a)},addInfoReader:function(b,e){e.test=function(e){return b.test(e)}; +R.push(e)},addMime:function(b,e){P[b]=RegExp("("+e.replace(/,/g,"|")+")$","i")},filter:function(b,e){for(var a=[],c=0,d=b.length,j;c>2,c=(c&3)<<4|d>>4;isNaN(d)?d=j=64:(d=(d&15)<<2|j>>6,j=isNaN(j)?64:j&63);e+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(p)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(c)+ +"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(d)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(j)}return e}};g({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,e){h.addMime(e,b)});h.addInfoReader(/^image/,function(b,e){if(!b.__dimensions){var a=b.__dimensions=h.defer();h.readAsImage(b,function(b){var e=b.target;a.resolve("load"==b.type?!1:"error",{width:e.width,height:e.height})})}b.__dimensions.then(e)});h.event.dnd=function(b,e,a){var c,d;a||(a=e,e=h.F);u?(q(b,"dragenter dragleave dragover",function(b){for(var a=((b.originalEvent||b||"").dataTransfer||{}).types,j=a&&a.length;j--;)~a[j].indexOf("File")&&(b.preventDefault(),d!==b.type&&(d=b.type, +"dragleave"!=d&&e.call(b.currentTarget,!0,b),clearTimeout(c),c=setTimeout(function(){e.call(b.currentTarget,"dragleave"!=d,b)},50)))}),q(b,"drop",function(b){b.preventDefault();d=0;e.call(b.currentTarget,!1,b);h.getDropFiles(b,function(e){a.call(b.currentTarget,e,b)})})):h.log("Drag'n'Drop -- not supported")};t&&!t.fn.dnd&&(t.fn.dnd=function(b,e){return this.each(function(){h.event.dnd(this,b,e)})});a.FileAPI=h.extend(h,a.FileAPI);h.flashUrl||(h.flashUrl=h.staticPath+"FileAPI.flash.swf");h.flashImageUrl|| +(h.flashImageUrl=h.staticPath+"FileAPI.flash.image.swf")})(window); +(function(a,k,g){function q(a,c){if(!(this instanceof q))return new q(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 l=Math.min,f=Math.round,c=!1,d={8:270,3:180,6:90};try{c=-1=s?(s=g,r=s/q):(r=c,s=r*q),s!=g||r!=c)d.sx=~~((g-s)/2),d.sy=~~((c-r)/2),g=s,c=r}else r&&("min"==r?(m=f(s=q?l(g,m):k*s),k=f(s>=q?m/s:l(c,k))));d.sw=g;d.sh=c;d.dw=m;d.dh=k;return d},_trans:function(a){this._load(this.file,function(c,d){c?a(c):this._apply(d,a)})},get:function(c){if(a.support.transform){var f=this;"auto"==f.matrix.deg?a.getInfo(this.file,function(a,g){f.matrix.deg= +d[g&&g.exif&&g.exif.Orientation]||0;f._trans(c)}):f._trans(c)}else c("not_support")},toData:function(a){this.get(a)}};q.transform=function(c,d,f,m){a.getInfo(c,function(l,k){var x={},r=a.queue(function(a){m(a,x)});l?r.fail():a.each(d,function(a,d){if(!r.isFail()){var j=q(k.nodeType?k:c);if("function"==typeof a)a(k,j);else if(a.width)j[a.preview?"preview":"resize"](a.width,a.height,a.type);else a.maxWidth&&(k.width>a.maxWidth||k.height>a.maxHeight)&&j.resize(a.maxWidth,a.maxHeight,"max");a.rotate=== +g&&f&&(a.rotate="auto");j.rotate(a.rotate);r.inc();j.toData(function(a,c){a?r.fail():(x[d]=c,r.next())})}})})};a.support.canvas=a.support.transform=c;a.Image=q})(FileAPI,document); +(function(a,k,g){var q=k.encodeURIComponent,l=k.FormData;k=function(){this.items=[]};k.prototype={append:function(a,c,d,g){this.items.push({name:a,blob:c&&c.blob||c,file:d||c.name,type:g||c.type})},each:function(a){for(var c=0,d=this.items.length;c',c.xhr.abort=function(){var a=d.getElementsByName("iframe")[0];if(a)try{a.stop?a.stop():a.contentWindow.stop?a.contentWindow.stop():a.contentWindow.document.execCommand("Stop")}catch(c){}d=null},p=d.getElementsByTagName("form")[0],p.appendChild(f), +k.log(p.parentNode.innerHTML),document.body.appendChild(d),c.xhr.node=d,a[m]=function(a,f,g){c.readyState=4;c.responseText=g;c.end(a,f);d=null},c.readyState=2,p.submit(),p=null):(d=c.xhr=k.getXHR(),f.params&&(p+=(0>p.indexOf("?")?"?":"&")+f.params.join("&")),d.open("POST",p,!0),d.withCredential="true",(!g.headers||!g.headers["X-Requested-With"])&&d.setRequestHeader("X-Requested-With","XMLHttpRequest"),k.each(g.headers,function(a,c){d.setRequestHeader(c,a)}),g._chunked?(d.upload&&d.upload.addEventListener("progress", +k.throttle(function(a){a=k.extend({},a,{loaded:f.start+a.loaded,totalSize:f.size,total:f.size});g.progress(a,c,g)},100),!1),d.onreadystatechange=function(){c.status=d.status;c.statusText=d.statusText;c.readyState=d.readyState;if(4==d.readyState){for(var a in{"":1,XML:1,Text:1,Body:1})c["response"+a]=d["response"+a];d.onreadystatechange=null;0').replace(/#(\w+)#/ig,function(c,e){return a[e]})},q=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){}}}},g=function(d,c){a.each(c,function(a,c){var e=d[c];d[c]=function(){this.parent=e;return a.apply(this,arguments)}})},A=function(d){var c=d.wid=a.uid();p._fn[c]=d;return"FileAPI.Flash._fn."+c},v=function(a){try{p._fn[a.wid]= -null,delete p._fn[a.wid]}catch(c){}},F=function(a,c){if(!u.test(a)){if(/^\.\//.test(a)||"/"!=a.charAt(0)){var e=location.pathname,e=e.substr(0,e.lastIndexOf("/"));a=(e+"/"+a).replace("/./","/")}"//"!=a.substr(0,2)&&(a="//"+location.host+a);u.test(a)||(a=location.protocol+a)}c&&(a+=(/\?/.test(a)?"&":"?")+c);return a},w=a.uid(),D=0,s={},u=/^https?:/i,p={_fn:{},init:function(){var d=h.body&&h.body.firstChild;if(d){do if(1==d.nodeType){a.log("FlashAPI.Flash.init...");var c=h.createElement("div");q(c, -{top:1,right:1,width:5,height:5,position:"absolute"});d.parentNode.insertBefore(c,d);p.publish(c,w);return}while(d=d.nextSibling)}10>D&&setTimeout(p.init,50*++D)},publish:function(d,c){d.innerHTML=m({id:c,src:F(a.flashUrl,"r="+a.version),wmode:"transparent",flashvars:"callback=FileAPI.Flash.event&flashId="+c+"&storeKey="+navigator.userAgent.match(/\d/ig).join("")+"_"+a.version+(p.isReady||(a.pingUrl?"&ping="+a.pingUrl:""))})},ready:function(){p.ready=a.F;p.isReady=!0;p.patch();a.event.on(h,"mouseover", -p.mouseover);a.event.on(h,"click",function(a){p.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!==h.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=h.createElement("div"),e=p.getWrapper(d);if(!e){a.log("flash.mouseover.error: js-fileapi-wrapper not found"); -return}q(c,{top:0,left:0,width:d.offsetWidth+100,height:d.offsetHeight+100,zIndex:"1000000",position:"absolute"});e.appendChild(c);p.publish(c,a.uid());d.setAttribute(w,"p")}return!0}},event:function(d){var c=d.type;if("ready"==c){try{p.getInput(d.flashId).setAttribute(w,"r")}catch(e){}p.ready();setTimeout(function(){p.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 p&&setTimeout(function(){a.log("Flash.event."+ -d.type+":",d);p[c](d)},1)},mouseenter:function(a){var c=p.getInput(a.flashId);c&&(p.cmd(a,"multiple",null!==c.getAttribute("multiple")),p.cmd(a,"accept",(c.getAttribute("accept")||"*").replace(/\./g,"")))},get:function(a){return h[a]||k[a]||h.embeds[a]},getInput:function(a){try{var c=p.getWrapper(p.get(a));if(c)return c.getElementsByTagName("input")[0]}catch(e){}},select:function(d){var c=p.getInput(d.flashId),e=a.uid(c);d=d.target.files;a.each(d,function(d){a.checkFileObj(d)});s[e]=d;h.createEvent? -(e=h.createEvent("Event"),e.initEvent("change",!0,!1),c.dispatchEvent(e)):h.createEventObject&&(e=h.createEventObject(),c.fireEvent("onchange",e))},cmd:function(d,c,e,f){try{return a.log("(js -> flash)."+c+":",e),p.get(d.flashId||d).cmd(c,e)}catch(g){a.log("(js -> flash).onError:",g),f||setTimeout(function(){p.cmd(d,c,e,!0)},50)}},patch:function(){a.flashEngine=a.support.transform=!0;g(a,{getFiles:function(d,c,e){if(e)return a.filterFiles(a.getFiles(d),c,e),null;var f=a.isArray(d)?d:s[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();p.cmd(a,"getFileInfo",{id:a.id,callback:A(function G(c,f){v(G);e.resolve(c,a.info=f)})})}a.__info.then(c)}}});a.support.transform=!0;g(FileAPI.Image.prototype,{get:function(a,c){this.set({scaleMode:c||"noScale"});this.parent(a)}, -_load:function(c,e){a.log("FileAPI.Image._load:",c);if(c&&!c.flashId)this.parent.apply(this,arguments);else{var f=this;a.getInfo(c,function(a){e.call(f,a,c)})}},_apply:function(c,e){a.log("FileAPI.Image._apply:",c);if(c&&!c.flashId)this.parent.apply(this,arguments);else{var f=this.getMatrix(c.info);p.cmd(c,"imageTransform",{id:c.id,matrix:f,callback:A(function G(g,k){a.log("FileAPI.Image._apply.callback:",g);v(G);if(g)e(g);else if(!a.support.dataURI||3E4').replace(/#(\w+)#/ig,function(c,d){return a[d]})},p=function(a,c){if(a&&a.style){var d,f;for(d in c){f=c[d];"number"==typeof f&&(f+="px");try{a.style[d]=f}catch(g){}}}},j=function(e,c){a.each(c,function(a,c){var d=e[c];e[c]=function(){this.parent=d;return a.apply(this,arguments)}})},A=function(e){var c=e.wid=a.uid();n._fn[c]=e;return"FileAPI.Flash._fn."+c},v=function(a){try{n._fn[a.wid]= +null,delete n._fn[a.wid]}catch(c){}},E=function(a,c){if(!u.test(a)){if(/^\.\//.test(a)||"/"!=a.charAt(0)){var d=location.pathname,d=d.substr(0,d.lastIndexOf("/"));a=(d+"/"+a).replace("/./","/")}"//"!=a.substr(0,2)&&(a="//"+location.host+a);u.test(a)||(a=location.protocol+a)}c&&(a+=(/\?/.test(a)?"&":"?")+c);return a},s=a.uid(),x=0,r={},u=/^https?:/i,n={_fn:{},init:function(){var e=g.body&&g.body.firstChild;if(e){do if(1==e.nodeType){a.log("FlashAPI.Flash.init...");var c=g.createElement("div");p(c, +{top:1,right:1,width:5,height:5,position:"absolute"});e.parentNode.insertBefore(c,e);n.publish(c,s);return}while(e=e.nextSibling)}10>x&&setTimeout(n.init,50*++x)},publish:function(e,c){e.innerHTML=m({id:c,src:E(a.flashUrl,"r="+a.version),wmode:"transparent",flashvars:"callback=FileAPI.Flash.event&flashId="+c+"&storeKey="+navigator.userAgent.match(/\d/ig).join("")+"_"+a.version+(n.isReady||(a.pingUrl?"&ping="+a.pingUrl:""))})},ready:function(){n.ready=a.F;n.isReady=!0;n.patch();a.event.on(g,"mouseover", +n.mouseover);a.event.on(g,"click",function(a){n.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!==g.body)},mouseover:function(e){e=a.event.fix(e).target;if(/input/i.test(e.nodeName)&&"file"==e.type){var c=e.getAttribute(s);if("i"==c||"r"==c)return!1;if("p"!=c){e.setAttribute(s,"i");var c=g.createElement("div"),d=n.getWrapper(e);if(!d){a.log("flash.mouseover.error: js-fileapi-wrapper not found"); +return}p(c,{top:0,left:0,width:e.offsetWidth+100,height:e.offsetHeight+100,zIndex:"1000000",position:"absolute"});d.appendChild(c);n.publish(c,a.uid());e.setAttribute(s,"p")}return!0}},event:function(e){var c=e.type;if("ready"==c){try{n.getInput(e.flashId).setAttribute(s,"r")}catch(d){}n.ready();setTimeout(function(){n.mouseenter(e)},50);return!0}"ping"===c?a.log("(flash -> js).ping:",[e.status,e.savedStatus],e.error):"log"===c?a.log("(flash -> js).log:",e.target):c in n&&setTimeout(function(){a.log("Flash.event."+ +e.type+":",e);n[c](e)},1)},mouseenter:function(a){var c=n.getInput(a.flashId);c&&(n.cmd(a,"multiple",null!==c.getAttribute("multiple")),n.cmd(a,"accept",(c.getAttribute("accept")||"*").replace(/\./g,"")))},get:function(a){return g[a]||k[a]||g.embeds[a]},getInput:function(a){try{var c=n.getWrapper(n.get(a));if(c)return c.getElementsByTagName("input")[0]}catch(d){}},select:function(e){var c=n.getInput(e.flashId),d=a.uid(c);e=e.target.files;a.each(e,function(e){a.checkFileObj(e)});r[d]=e;g.createEvent? +(d=g.createEvent("Event"),d.initEvent("change",!0,!1),c.dispatchEvent(d)):g.createEventObject&&(d=g.createEventObject(),c.fireEvent("onchange",d))},cmd:function(e,c,d,f){try{return a.log("(js -> flash)."+c+":",d),n.get(e.flashId||e).cmd(c,d)}catch(g){a.log("(js -> flash).onError:",g),f||setTimeout(function(){n.cmd(e,c,d,!0)},50)}},patch:function(){a.flashEngine=a.support.transform=!0;j(a,{getFiles:function(e,c,d){if(d)return a.filterFiles(a.getFiles(e),c,d),null;var f=a.isArray(e)?e:r[a.uid(e.target|| +e.srcElement||e)];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 d=a.__info=FileAPI.defer();n.cmd(a,"getFileInfo",{id:a.id,callback:A(function F(c,f){v(F);d.resolve(c,a.info=f)})})}a.__info.then(c)}}});a.support.transform=!0;j(FileAPI.Image.prototype,{get:function(a,c){this.set({scaleMode:c||"noScale"});this.parent(a)}, +_load:function(c,d){a.log("FileAPI.Image._load:",c);if(c&&!c.flashId)this.parent.apply(this,arguments);else{var f=this;a.getInfo(c,function(a){d.call(f,a,c)})}},_apply:function(c,d){a.log("FileAPI.Image._apply:",c);if(c&&!c.flashId)this.parent.apply(this,arguments);else{var f=this.getMatrix(c.info);n.cmd(c,"imageTransform",{id:c.id,matrix:f,callback:A(function F(j,k){a.log("FileAPI.Image._apply.callback:",j);v(F);if(j)d(j);else if(!a.support.dataURI||3E4-\/\ * [Content-Disposition](http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.5.1): attachment; filename=\ -Other titles are not used. Tracking name's uniqueness of delegating file is not executed. It is left on developer's consideration. - -In response to delegating chunk server can reply following codes: -* 200, 201 — chunk is successfully saved -* 416, 500 — repairable error, you can continue upload. +Any other headers are set by a target browser and are not used by client. +Library does not provide any facilities to track a file uniqueness across requests, it's left on developer's consideration. -All the other codes — fatal error, user's involvement is recommend. +Client recognizes the following response codes: +* 200, 201 - chunk is successfully saved +* 416, 500 - recoverable error, library tries to resend chunk 'chunkUploadRetry' times then fails +All the other codes - fatal error, user's involvement is recommend. ----- @@ -668,6 +670,10 @@ All the other codes — fatal error, user's involvement is recommend. ## Changelog +### 1.2.1 + * [#64](https://github.com/mailru/FileAPI/issues/64): Bufixed for [#63](https://github.com/mailru/FileAPI/issues/63) + + ### 1.2.0 * [#57](https://github.com/mailru/FileAPI/issues/57): Chunked file upload diff --git a/lib/FileAPI.Form.js b/lib/FileAPI.Form.js index 923e9e74..6489a6f3 100644 --- a/lib/FileAPI.Form.js +++ b/lib/FileAPI.Form.js @@ -122,7 +122,7 @@ data.append('_'+file.name, file.file); } - if( file.blob.toBlob ){ + if( file.blob && file.blob.toBlob ){ queue.inc(); file.blob.toBlob(function (blob){ data.append(file.name, blob, file.file); diff --git a/lib/FileAPI.core.js b/lib/FileAPI.core.js index d1eb9321..d7d44195 100644 --- a/lib/FileAPI.core.js +++ b/lib/FileAPI.core.js @@ -58,7 +58,7 @@ preventDefault = 'preventDefault', api = { - version: '1.2.0', + version: '1.2.1', cors: false, debug: false, @@ -1073,7 +1073,7 @@ } // api ; - + function _each(obj, fn, ctx){ if( obj ){ if( isArray(obj) ){