angular-file-upload-rails 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 657107115c990ca4ea3d9aa3458ee615f54225a6
4
+ data.tar.gz: 6b61b091df6e1e15c4ca0c595a3ce26be698565b
5
+ SHA512:
6
+ metadata.gz: 15a1912ef0cd0cb5c9fe91246cd99a274efab93c4efc221a2ac07379b3631529d4da2ba7c83e593ea56d8bd27ae5b7ba6242884a239262771b3cf83c15139e44
7
+ data.tar.gz: 43ad7a4fa3bc3714fa9b94b5d4719b6abbf0da5dde8df07ebc39fabb8dfb3d76abc63bd062d8eee70151dc65518ae064b5ddc4169cfa078fe166dcdf88b858b4
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ .ruby-gemset
3
+ .ruby-version
4
+ .DS_Store
5
+ Gemfile.lock
6
+ tmp/*
7
+ !.keep
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT LICENSE
2
+
3
+ Copyright (c) 2014 Joe DiVita <joediv31@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,5 @@
1
+ Angular-File-Upload-Rails
2
+ =========================
3
+
4
+ This gem includes [angular-file-upload](https://github.com/danialfarid/angular-file-upload) as an asset in the Rails Asset Pipeline (requires Rails 3.1 or higher).
5
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/angular-file-upload/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'angular-file-upload-rails'
6
+ gem.version = AngularFileUpload::VERSION
7
+ gem.date = '2014-07-23'
8
+ gem.authors = ['Joe DiVita']
9
+ gem.email = ['joediv31@gmail.com']
10
+ gem.description = %q{ Includes an AngularJS Directive for uploading files as an asset in the Rails Asset Pipeline }
11
+ gem.summary = %q{ Includes an AngularJS Directive for uploading files as an asset in the Rails Asset Pipeline }
12
+ gem.homepage = 'https://github.com/joedivita/angular-file-upload-rails'
13
+ gem.license = 'MIT'
14
+
15
+ gem.files = `git ls-files`.split($\)
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'railties', '>= 3.1'
21
+ gem.add_development_dependency 'bundler', '~> 1.0'
22
+ gem.add_development_dependency 'rails', '>= 3.1'
23
+ end
@@ -0,0 +1,3 @@
1
+ /*! FileAPI 2.0.4 - BSD | git://github.com/mailru/FileAPI.git */
2
+ !function(a){"use strict";var b=a.HTMLCanvasElement&&a.HTMLCanvasElement.prototype,c=a.Blob&&function(){try{return Boolean(new Blob)}catch(a){return!1}}(),d=c&&a.Uint8Array&&function(){try{return 100===new Blob([new Uint8Array(100)]).size}catch(a){return!1}}(),e=a.BlobBuilder||a.WebKitBlobBuilder||a.MozBlobBuilder||a.MSBlobBuilder,f=(c||e)&&a.atob&&a.ArrayBuffer&&a.Uint8Array&&function(a){var b,f,g,h,i,j;for(b=a.split(",")[0].indexOf("base64")>=0?atob(a.split(",")[1]):decodeURIComponent(a.split(",")[1]),f=new ArrayBuffer(b.length),g=new Uint8Array(f),h=0;h<b.length;h+=1)g[h]=b.charCodeAt(h);return i=a.split(",")[0].split(":")[1].split(";")[0],c?new Blob([d?g:f],{type:i}):(j=new e,j.append(f),j.getBlob(i))};a.HTMLCanvasElement&&!b.toBlob&&(b.mozGetAsFile?b.toBlob=function(a,c,d){a(d&&b.toDataURL&&f?f(this.toDataURL(c,d)):this.mozGetAsFile("blob",c))}:b.toDataURL&&f&&(b.toBlob=function(a,b,c){a(f(this.toDataURL(b,c)))})),a.dataURLtoBlob=f}(window),function(a,b){"use strict";function c(a,b,c,d,e){var f={type:c.type||c,target:a,result:d};R(f,e),b(f)}function d(a){return u&&!!u.prototype["readAs"+a]}function e(a,e,f,g){if(X.isBlob(a)&&d(f)){var h=new u;S(h,L,function j(b){var d=b.type;"progress"==d?c(a,e,b,b.target.result,{loaded:b.loaded,total:b.total}):"loadend"==d?(T(h,L,j),h=null):c(a,e,b,b.target.result)});try{g?h["readAs"+f](a,g):h["readAs"+f](a)}catch(i){c(a,e,"error",b,{error:i.toString()})}}else c(a,e,"error",b,{error:"filreader_not_support_"+f})}function f(a,b){if(!a.type&&a.size%4096===0&&a.size<=102400)if(u)try{var c=new u;U(c,L,function(a){var d="error"!=a.type;b(d),d&&c.abort()}),c.readAsDataURL(a)}catch(d){b(!1)}else b(null);else b(!0)}function g(a){var b;return a.getAsEntry?b=a.getAsEntry():a.webkitGetAsEntry&&(b=a.webkitGetAsEntry()),b}function h(a,b){if(a)if(a.isFile)a.file(function(c){c.fullPath=a.fullPath,b(!1,[c])},function(a){b("FileError.code: "+a.code)});else if(a.isDirectory){var c=a.createReader(),d=[];c.readEntries(function(a){X.afor(a,function(a,c){h(c,function(c,e){c?X.log(c):d=d.concat(e),a?a():b(!1,d)})})},function(a){b("directory_reader: "+a)})}else h(g(a),b);else b("invalid entry")}function i(a){var b={};return Q(a,function(a,c){a&&"object"==typeof a&&void 0===a.nodeType&&(a=R({},a)),b[c]=a}),b}function j(a){return F.test(a&&a.tagName)}function k(a){return(a.originalEvent||a||"").dataTransfer||{}}function l(a){var b;for(b in a)if(a.hasOwnProperty(b)&&!(a[b]instanceof Object||"overlay"===b||"filter"===b))return!0;return!1}var m=1,n=function(){},o=a.document,p=o.doctype||{},q=a.navigator.userAgent,r=a.createObjectURL&&a||a.URL&&URL.revokeObjectURL&&URL||a.webkitURL&&webkitURL,s=a.Blob,t=a.File,u=a.FileReader,v=a.FormData,w=a.XMLHttpRequest,x=a.jQuery,y=!(!(t&&u&&(a.Uint8Array||v||w.prototype.sendAsBinary))||/safari\//i.test(q)&&!/chrome\//i.test(q)&&/windows/i.test(q)),z=y&&"withCredentials"in new w,A=y&&!!s&&!!(s.prototype.webkitSlice||s.prototype.mozSlice||s.prototype.slice),B=a.dataURLtoBlob,C=/img/i,D=/canvas/i,E=/img|canvas/i,F=/input/i,G=/^data:[^,]+,/,H=a.Math,I=function(b){return b=new a.Number(H.pow(1024,b)),b.from=function(a){return H.round(a*this)},b},J={},K=[],L="abort progress error load loadend",M="status statusText readyState response responseXML responseText responseBody".split(" "),N="currentTarget",O="preventDefault",P=function(a){return a&&"length"in a},Q=function(a,b,c){if(a)if(P(a))for(var d=0,e=a.length;e>d;d++)d in a&&b.call(c,a[d],d,a);else for(var f in a)a.hasOwnProperty(f)&&b.call(c,a[f],f,a)},R=function(a){for(var b=arguments,c=1,d=function(b,c){a[c]=b};c<b.length;c++)Q(b[c],d);return a},S=function(a,b,c){if(a){var d=X.uid(a);J[d]||(J[d]={});var e=u&&a&&a instanceof u;Q(b.split(/\s+/),function(b){x&&!e?x.event.add(a,b,c):(J[d][b]||(J[d][b]=[]),J[d][b].push(c),a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent?a.attachEvent("on"+b,c):a["on"+b]=c)})}},T=function(a,b,c){if(a){var d=X.uid(a),e=J[d]||{},f=u&&a&&a instanceof u;Q(b.split(/\s+/),function(b){if(x&&!f)x.event.remove(a,b,c);else{for(var d=e[b]||[],g=d.length;g--;)if(d[g]===c){d.splice(g,1);break}a.addEventListener?a.removeEventListener(b,c,!1):a.detachEvent?a.detachEvent("on"+b,c):a["on"+b]=null}})}},U=function(a,b,c){S(a,b,function d(e){T(a,b,d),c(e)})},V=function(b){return b.target||(b.target=a.event&&a.event.srcElement||o),3===b.target.nodeType&&(b.target=b.target.parentNode),b},W=function(a){var b=o.createElement("input");return b.setAttribute("type","file"),a in b},X={version:"2.0.4",cors:!1,html5:!0,media:!1,formData:!0,multiPassResize:!0,debug:!1,pingUrl:!1,multiFlash:!1,flashAbortTimeout:0,withCredentials:!0,staticPath:"./dist/",flashUrl:0,flashImageUrl:0,postNameConcat:function(a,b){return a+(null!=b?"["+b+"]":"")},ext2mime:{jpg:"image/jpeg",tif:"image/tiff",txt:"text/plain"},accept:{"image/*":"art bm bmp dwg dxf cbr cbz fif fpx gif ico iefs jfif jpe jpeg jpg jps jut mcf nap nif pbm pcx pgm pict pm png pnm qif qtif ras rast rf rp svf tga tif tiff xbm xbm xpm xwd","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 xs","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"},uploadRetry:0,networkDownRetryTimeout:5e3,chunkSize:0,chunkUploadRetry:0,chunkNetworkDownRetryTimeout:2e3,KB:I(1),MB:I(2),GB:I(3),TB:I(4),EMPTY_PNG:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQIW2NkAAIAAAoAAggA9GkAAAAASUVORK5CYII=",expando:"fileapi"+(new Date).getTime(),uid:function(a){return a?a[X.expando]=a[X.expando]||X.uid():(++m,X.expando+m)},log:function(){X.debug&&a.console&&console.log&&(console.log.apply?console.log.apply(console,arguments):console.log([].join.call(arguments," ")))},newImage:function(a,b){var c=o.createElement("img");return b&&X.event.one(c,"error load",function(a){b("error"==a.type,c),c=null}),c.src=a,c},getXHR:function(){var b;if(w)b=new w;else if(a.ActiveXObject)try{b=new ActiveXObject("MSXML2.XMLHttp.3.0")}catch(c){b=new ActiveXObject("Microsoft.XMLHTTP")}return b},isArray:P,support:{dnd:z&&"ondrop"in o.createElement("div"),cors:z,html5:y,chunked:A,dataURI:!0,accept:W("accept"),multiple:W("multiple")},event:{on:S,off:T,one:U,fix:V},throttle:function(b,c){var d,e;return function(){e=arguments,d||(b.apply(a,e),d=setTimeout(function(){d=0,b.apply(a,e)},c))}},F:function(){},parseJSON:function(b){var c;return c=a.JSON&&JSON.parse?JSON.parse(b):new Function("return ("+b.replace(/([\r\n])/g,"\\$1")+");")()},trim:function(a){return a=String(a),a.trim?a.trim():a.replace(/^\s+|\s+$/g,"")},defer:function(){var a,c,d=[],e={resolve:function(b,f){for(e.resolve=n,c=b||!1,a=f;f=d.shift();)f(c,a)},then:function(e){c!==b?e(c,a):d.push(e)}};return e},queue:function(a){var b=0,c=0,d=!1,e=!1,f={inc:function(){c++},next:function(){b++,setTimeout(f.check,0)},check:function(){b>=c&&!d&&f.end()},isFail:function(){return d},fail:function(){!d&&a(d=!0)},end:function(){e||(e=!0,a())}};return f},each:Q,afor:function(a,b){var c=0,d=a.length;P(a)&&d--?!function e(){b(d!=c&&e,a[c],c++)}():b(!1)},extend:R,isFile:function(a){return y&&a&&a instanceof t},isBlob:function(a){return y&&a&&a instanceof s},isCanvas:function(a){return a&&D.test(a.nodeName)},getFilesFilter:function(a){return a="string"==typeof a?a:a.getAttribute&&a.getAttribute("accept")||"",a?new RegExp("("+a.replace(/\./g,"\\.").replace(/,/g,"|")+")$","i"):/./},readAsDataURL:function(a,b){X.isCanvas(a)?c(a,b,"load",X.toDataURL(a)):e(a,b,"DataURL")},readAsBinaryString:function(a,b){d("BinaryString")?e(a,b,"BinaryString"):e(a,function(a){if("load"==a.type)try{a.result=X.toBinaryString(a.result)}catch(c){a.type="error",a.message=c.toString()}b(a)},"DataURL")},readAsArrayBuffer:function(a,b){e(a,b,"ArrayBuffer")},readAsText:function(a,b,c){c||(c=b,b="utf-8"),e(a,c,"Text",b)},toDataURL:function(a,b){return"string"==typeof a?a:a.toDataURL?a.toDataURL(b||"image/png"):void 0},toBinaryString:function(b){return a.atob(X.toDataURL(b).replace(G,""))},readAsImage:function(a,d,e){if(X.isFile(a))if(r){var f=r.createObjectURL(a);f===b?c(a,d,"error"):X.readAsImage(f,d,e)}else X.readAsDataURL(a,function(b){"load"==b.type?X.readAsImage(b.result,d,e):(e||"error"==b.type)&&c(a,d,b,null,{loaded:b.loaded,total:b.total})});else if(X.isCanvas(a))c(a,d,"load",a);else if(C.test(a.nodeName))if(a.complete)c(a,d,"load",a);else{var g="error abort load";U(a,g,function i(b){"load"==b.type&&r&&r.revokeObjectURL(a.src),T(a,g,i),c(a,d,b,a)})}else if(a.iframe)c(a,d,{type:"error"});else{var h=X.newImage(a.dataURL||a);X.readAsImage(h,d,e)}},checkFileObj:function(a){var b={},c=X.accept;return"object"==typeof a?b=a:b.name=(a+"").split(/\\|\//g).pop(),null==b.type&&(b.type=b.name.split(".").pop()),Q(c,function(a,c){a=new RegExp(a.replace(/\s/g,"|"),"i"),(a.test(b.type)||X.ext2mime[b.type])&&(b.type=X.ext2mime[b.type]||c.split("/")[0]+"/"+b.type)}),b},getDropFiles:function(a,b){var c=[],d=k(a),e=P(d.items)&&d.items[0]&&g(d.items[0]),i=X.queue(function(){b(c)});Q((e?d.items:d.files)||[],function(a){i.inc();try{e?h(a,function(a,b){a?X.log("[err] getDropFiles:",a):c.push.apply(c,b),i.next()}):f(a,function(b){b&&c.push(a),i.next()})}catch(b){i.next(),X.log("[err] getDropFiles: ",b)}}),i.check()},getFiles:function(a,b,c){var d=[];return c?(X.filterFiles(X.getFiles(a),b,c),null):(a.jquery&&(a.each(function(){d=d.concat(X.getFiles(this))}),a=d,d=[]),"string"==typeof b&&(b=X.getFilesFilter(b)),a.originalEvent?a=V(a.originalEvent):a.srcElement&&(a=V(a)),a.dataTransfer?a=a.dataTransfer:a.target&&(a=a.target),a.files?(d=a.files,y||(d[0].blob=a,d[0].iframe=!0)):!y&&j(a)?X.trim(a.value)&&(d=[X.checkFileObj(a.value)],d[0].blob=a,d[0].iframe=!0):P(a)&&(d=a),X.filter(d,function(a){return!b||b.test(a.name)}))},getTotalSize:function(a){for(var b=0,c=a&&a.length;c--;)b+=a[c].size;return b},getInfo:function(a,b){var c={},d=K.concat();X.isFile(a)?!function e(){var f=d.shift();f?f.test(a.type)?f(a,function(a,d){a?b(a):(R(c,d),e())}):e():b(!1,c)}():b("not_support_info",c)},addInfoReader:function(a,b){b.test=function(b){return a.test(b)},K.push(b)},filter:function(a,b){for(var c,d=[],e=0,f=a.length;f>e;e++)e in a&&(c=a[e],b.call(c,c,e,a)&&d.push(c));return d},filterFiles:function(a,b,c){if(a.length){var d,e=a.concat(),f=[],g=[];!function h(){e.length?(d=e.shift(),X.getInfo(d,function(a,c){(b(d,a?!1:c)?f:g).push(d),h()})):c(f,g)}()}else c([],a)},upload:function(a){a=R({jsonp:"callback",prepare:X.F,beforeupload:X.F,upload:X.F,fileupload:X.F,fileprogress:X.F,filecomplete:X.F,progress:X.F,complete:X.F,pause:X.F,imageOriginal:!0,chunkSize:X.chunkSize,chunkUploadRetry:X.chunkUploadRetry,uploadRetry:X.uploadRetry},a),a.imageAutoOrientation&&!a.imageTransform&&(a.imageTransform={rotate:"auto"});var b,c=new X.XHR(a),d=this._getFilesDataArray(a.files),e=this,f=0,g=0,h=!1;return Q(d,function(a){f+=a.size}),c.files=[],Q(d,function(a){c.files.push(a.file)}),c.total=f,c.loaded=0,c.filesLeft=d.length,a.beforeupload(c,a),b=function(){var j=d.shift(),k=j&&j.file,l=!1,m=i(a);if(c.filesLeft=d.length,k&&k.name===X.expando&&(k=null,X.log("[warn] FileAPI.upload() — called without files")),("abort"!=c.statusText||c.current)&&j){if(h=!1,c.currentFile=k,k&&a.prepare(k,m)===!1)return void b.call(e);m.file=k,e._getFormData(m,j,function(h){g||a.upload(c,a);var i=new X.XHR(R({},m,{upload:k?function(){a.fileupload(k,i,m)}:n,progress:k?function(b){l||(l=b.loaded===b.total,a.fileprogress({type:"progress",total:j.total=b.total,loaded:j.loaded=b.loaded},k,i,m),a.progress({type:"progress",total:f,loaded:c.loaded=g+j.size*(b.loaded/b.total)|0},k,i,m))}:n,complete:function(d){Q(M,function(a){c[a]=i[a]}),k&&(j.total=j.total||j.size,j.loaded=j.total,d||(this.progress(j),l=!0,g+=j.size,c.loaded=g),a.filecomplete(d,i,k,m)),setTimeout(function(){b.call(e)},0)}}));c.abort=function(a){a||(d.length=0),this.current=a,i.abort()},i.send(h)})}else{var o=200==c.status||201==c.status||204==c.status;a.complete(o?!1:c.statusText||"error",c,a),h=!0}},setTimeout(b,0),c.append=function(a,g){a=X._getFilesDataArray([].concat(a)),Q(a,function(a){f+=a.size,c.files.push(a.file),g?d.unshift(a):d.push(a)}),c.statusText="",h&&b.call(e)},c.remove=function(a){for(var b,c=d.length;c--;)d[c].file==a&&(b=d.splice(c,1),f-=b.size);return b},c},_getFilesDataArray:function(a){var b=[],c={};if(j(a)){var d=X.getFiles(a);c[a.name||"file"]=null!==a.getAttribute("multiple")?d:d[0]}else P(a)&&j(a[0])?Q(a,function(a){c[a.name||"file"]=X.getFiles(a)}):c=a;return Q(c,function e(a,c){P(a)?Q(a,function(a){e(a,c)}):a&&(a.name||a.image)&&b.push({name:c,file:a,size:a.size,total:a.size,loaded:0})}),b.length||b.push({file:{name:X.expando}}),b},_getFormData:function(a,b,c){var d=b.file,e=b.name,f=d.name,g=d.type,h=X.support.transform&&a.imageTransform,i=new X.Form,j=X.queue(function(){c(i)}),k=h&&l(h),m=X.postNameConcat;Q(a.data,function n(a,b){"object"==typeof a?Q(a,function(a,c){n(a,m(b,c))}):i.append(b,a)}),function o(b){b.image?(j.inc(),b.toData(function(a,b){f=f||(new Date).getTime()+".png",o(b),j.next()})):X.Image&&h&&(/^image/.test(b.type)||E.test(b.nodeName))?(j.inc(),k&&(h=[h]),X.Image.transform(b,h,a.imageAutoOrientation,function(c,d){if(k&&!c)B||X.flashEngine||(i.multipart=!0),i.append(e,d[0],f,h[0].type||g);else{var l=0;c||Q(d,function(a,b){B||X.flashEngine||(i.multipart=!0),h[b].postName||(l=1),i.append(h[b].postName||m(e,b),a,f,h[b].type||g)}),(c||a.imageOriginal)&&i.append(m(e,l?"original":null),b,f,g)}j.next()})):f!==X.expando&&i.append(e,b,f)}(d),j.check()},reset:function(a,b){var c,d;return x?(d=x(a).clone(!0).insertBefore(a).val("")[0],b||x(a).remove()):(c=a.parentNode,d=c.insertBefore(a.cloneNode(!0),a),d.value="",b||c.removeChild(a),Q(J[X.uid(a)],function(b,c){Q(b,function(b){T(a,c,b),S(d,c,b)})})),d},load:function(a,b){var c=X.getXHR();return c?(c.open("GET",a,!0),c.overrideMimeType&&c.overrideMimeType("text/plain; charset=x-user-defined"),S(c,"progress",function(a){a.lengthComputable&&b({type:a.type,loaded:a.loaded,total:a.total},c)}),c.onreadystatechange=function(){if(4==c.readyState)if(c.onreadystatechange=null,200==c.status){a=a.split("/");var d={name:a[a.length-1],size:c.getResponseHeader("Content-Length"),type:c.getResponseHeader("Content-Type")};d.dataURL="data:"+d.type+";base64,"+X.encode64(c.responseBody||c.responseText),b({type:"load",result:d},c)}else b({type:"error"},c)},c.send(null)):b({type:"error"}),c},encode64:function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",c="",d=0;for("string"!=typeof a&&(a=String(a));d<a.length;){var e,f,g=255&a.charCodeAt(d++),h=255&a.charCodeAt(d++),i=255&a.charCodeAt(d++),j=g>>2,k=(3&g)<<4|h>>4;isNaN(h)?e=f=64:(e=(15&h)<<2|i>>6,f=isNaN(i)?64:63&i),c+=b.charAt(j)+b.charAt(k)+b.charAt(e)+b.charAt(f)}return c}};X.addInfoReader(/^image/,function(a,b){if(!a.__dimensions){var c=a.__dimensions=X.defer();X.readAsImage(a,function(a){var b=a.target;c.resolve("load"==a.type?!1:"error",{width:b.width,height:b.height}),b.src=X.EMPTY_PNG,b=null})}a.__dimensions.then(b)}),X.event.dnd=function(a,b,c){var d,e;c||(c=b,b=X.F),u?(S(a,"dragenter dragleave dragover",function(a){for(var c=k(a).types,f=c&&c.length,g=!1;f--;)if(~c[f].indexOf("File")){a[O](),e!==a.type&&(e=a.type,"dragleave"!=e&&b.call(a[N],!0,a),g=!0);break}g&&(clearTimeout(d),d=setTimeout(function(){b.call(a[N],"dragleave"!=e,a)},50))}),S(a,"drop",function(a){a[O](),e=0,b.call(a[N],!1,a),X.getDropFiles(a,function(b){c.call(a[N],b,a)})})):X.log("Drag'n'Drop -- not supported")},X.event.dnd.off=function(a,b,c){T(a,"dragenter dragleave dragover",b),T(a,"drop",c)},x&&!x.fn.dnd&&(x.fn.dnd=function(a,b){return this.each(function(){X.event.dnd(this,a,b)})},x.fn.offdnd=function(a,b){return this.each(function(){X.event.dnd.off(this,a,b)})}),a.FileAPI=R(X,a.FileAPI),X.log("FileAPI: "+X.version),X.log("protocol: "+a.location.protocol),X.log("doctype: ["+p.name+"] "+p.publicId+" "+p.systemId),Q(o.getElementsByTagName("meta"),function(a){/x-ua-compatible/i.test(a.getAttribute("http-equiv"))&&X.log("meta.http-equiv: "+a.getAttribute("content"))}),X.flashUrl||(X.flashUrl=X.staticPath+"FileAPI.flash.swf"),X.flashImageUrl||(X.flashImageUrl=X.staticPath+"FileAPI.flash.image.swf"),X.flashWebcamUrl||(X.flashWebcamUrl=X.staticPath+"FileAPI.flash.camera.swf")}(window,void 0),function(a,b,c){"use strict";function d(b){if(b instanceof d){var c=new d(b.file);return a.extend(c.matrix,b.matrix),c}return this instanceof d?(this.file=b,this.size=b.size||100,void(this.matrix={sx:0,sy:0,sw:0,sh:0,dx:0,dy:0,dw:0,dh:0,resize:0,deg:0,quality:1,filter:0})):new d(b)}var e=Math.min,f=Math.round,g=function(){return b.createElement("canvas")},h=!1,i={8:270,3:180,6:90,7:270,4:180,5:90};try{h=g().toDataURL("image/png").indexOf("data:image/png")>-1}catch(j){}d.prototype={image:!0,constructor:d,set:function(b){return a.extend(this.matrix,b),this},crop:function(a,b,d,e){return d===c&&(d=a,e=b,a=b=0),this.set({sx:a,sy:b,sw:d,sh:e||d})},resize:function(a,b,c){return/min|max/.test(b)&&(c=b,b=a),this.set({dw:a,dh:b||a,resize:c})},preview:function(a,b){return this.resize(a,b||a,"preview")},rotate:function(a){return this.set({deg:a})},filter:function(a){return this.set({filter:a})},overlay:function(a){return this.set({overlay:a})},clone:function(){return new d(this)},_load:function(b,c){var d=this;/img|video/i.test(b.nodeName)?c.call(d,null,b):a.readAsImage(b,function(a){c.call(d,"load"!=a.type,a.result)})},_apply:function(b,c){var f,h=g(),i=this.getMatrix(b),j=h.getContext("2d"),k=b.videoWidth||b.width,l=b.videoHeight||b.height,m=i.deg,n=i.dw,o=i.dh,p=k,q=l,r=i.filter,s=b,t=i.overlay,u=a.queue(function(){b.src=a.EMPTY_PNG,c(!1,h)}),v=a.renderImageToCanvas;for(m-=360*Math.floor(m/360),b._type=this.file.type;i.multipass&&e(p/n,q/o)>2;)p=p/2+.5|0,q=q/2+.5|0,f=g(),f.width=p,f.height=q,s!==b?(v(f,s,0,0,s.width,s.height,0,0,p,q),s=f):(s=f,v(s,b,i.sx,i.sy,i.sw,i.sh,0,0,p,q),i.sx=i.sy=i.sw=i.sh=0);h.width=m%180?o:n,h.height=m%180?n:o,h.type=i.type,h.quality=i.quality,j.rotate(m*Math.PI/180),v(j.canvas,s,i.sx,i.sy,i.sw||s.width,i.sh||s.height,180==m||270==m?-n:0,90==m||180==m?-o:0,n,o),n=h.width,o=h.height,t&&a.each([].concat(t),function(b){u.inc();var c=new window.Image,d=function(){var e=0|b.x,f=0|b.y,g=b.w||c.width,h=b.h||c.height,i=b.rel;e=1==i||4==i||7==i?(n-g+e)/2:2==i||5==i||8==i?n-(g+e):e,f=3==i||4==i||5==i?(o-h+f)/2:i>=6?o-(h+f):f,a.event.off(c,"error load abort",d);try{j.globalAlpha=b.opacity||1,j.drawImage(c,e,f,g,h)}catch(k){}u.next()};a.event.on(c,"error load abort",d),c.src=b.src,c.complete&&d()}),r&&(u.inc(),d.applyFilter(h,r,u.next)),u.check()},getMatrix:function(b){var c=a.extend({},this.matrix),d=c.sw=c.sw||b.videoWidth||b.naturalWidth||b.width,g=c.sh=c.sh||b.videoHeight||b.naturalHeight||b.height,h=c.dw=c.dw||d,i=c.dh=c.dh||g,j=d/g,k=h/i,l=c.resize;if("preview"==l){if(h!=d||i!=g){var m,n;k>=j?(m=d,n=m/k):(n=g,m=n*k),(m!=d||n!=g)&&(c.sx=~~((d-m)/2),c.sy=~~((g-n)/2),d=m,g=n)}}else l&&(d>h||g>i?"min"==l?(h=f(k>j?e(d,h):i*j),i=f(k>j?h/j:e(g,i))):(h=f(j>=k?e(d,h):i*j),i=f(j>=k?h/j:e(g,i))):(h=d,i=g));return c.sw=d,c.sh=g,c.dw=h,c.dh=i,c.multipass=a.multiPassResize,c},_trans:function(b){this._load(this.file,function(c,d){if(c)b(c);else try{this._apply(d,b)}catch(c){a.log("[err] FileAPI.Image.fn._apply:",c),b(c)}})},get:function(b){if(a.support.transform){var c=this,d=c.matrix;"auto"==d.deg?a.getInfo(c.file,function(a,e){d.deg=i[e&&e.exif&&e.exif.Orientation]||0,c._trans(b)}):c._trans(b)}else b("not_support_transform");return this},toData:function(a){return this.get(a)}},d.exifOrientation=i,d.transform=function(b,e,f,g){function h(h,i){var j={},k=a.queue(function(a){g(a,j)});h?k.fail():a.each(e,function(a,e){if(!k.isFail()){var g=new d(i.nodeType?i:b);if("function"==typeof a?a(i,g):a.width?g[a.preview?"preview":"resize"](a.width,a.height,a.strategy):a.maxWidth&&(i.width>a.maxWidth||i.height>a.maxHeight)&&g.resize(a.maxWidth,a.maxHeight,"max"),a.crop){var h=a.crop;g.crop(0|h.x,0|h.y,h.w||h.width,h.h||h.height)}a.rotate===c&&f&&(a.rotate="auto"),g.set({deg:a.rotate,type:a.type||b.type||"image/png",quality:a.quality||1,overlay:a.overlay,filter:a.filter}),k.inc(),g.toData(function(a,b){a?k.fail():(j[e]=b,k.next())})}})}b.width?h(!1,b):a.getInfo(b,h)},a.each(["TOP","CENTER","BOTTOM"],function(b,c){a.each(["LEFT","CENTER","RIGHT"],function(a,e){d[b+"_"+a]=3*c+e,d[a+"_"+b]=3*c+e})}),d.toCanvas=function(a){var c=b.createElement("canvas");return c.width=a.videoWidth||a.width,c.height=a.videoHeight||a.height,c.getContext("2d").drawImage(a,0,0),c},d.fromDataURL=function(b,c,d){var e=a.newImage(b);a.extend(e,c),d(e)},d.applyFilter=function(b,c,e){"function"==typeof c?c(b,e):window.Caman&&window.Caman("IMG"==b.tagName?d.toCanvas(b):b,function(){"string"==typeof c?this[c]():a.each(c,function(a,b){this[b](a)},this),this.render(e)})},a.renderImageToCanvas=function(b,c,d,e,f,g,h,i,j,k){try{return b.getContext("2d").drawImage(c,d,e,f,g,h,i,j,k)}catch(l){throw a.log("renderImageToCanvas failed"),l}},a.support.canvas=a.support.transform=h,a.Image=d}(FileAPI,document),function(a){"use strict";a(FileAPI)}(function(a){"use strict";if(window.navigator&&window.navigator.platform&&/iP(hone|od|ad)/.test(window.navigator.platform)){var b=a.renderImageToCanvas;a.detectSubsampling=function(a){var b,c;return a.width*a.height>1048576?(b=document.createElement("canvas"),b.width=b.height=1,c=b.getContext("2d"),c.drawImage(a,-a.width+1,0),0===c.getImageData(0,0,1,1).data[3]):!1},a.detectVerticalSquash=function(a,b){var c,d,e,f,g,h=a.naturalHeight||a.height,i=document.createElement("canvas"),j=i.getContext("2d");for(b&&(h/=2),i.width=1,i.height=h,j.drawImage(a,0,0),c=j.getImageData(0,0,1,h).data,d=0,e=h,f=h;f>d;)g=c[4*(f-1)+3],0===g?e=f:d=f,f=e+d>>1;return f/h||1},a.renderImageToCanvas=function(c,d,e,f,g,h,i,j,k,l){if("image/jpeg"===d._type){var m,n,o,p,q=c.getContext("2d"),r=document.createElement("canvas"),s=1024,t=r.getContext("2d");if(r.width=s,r.height=s,q.save(),m=a.detectSubsampling(d),m&&(e/=2,f/=2,g/=2,h/=2),n=a.detectVerticalSquash(d,m),m||1!==n){for(f*=n,k=Math.ceil(s*k/g),l=Math.ceil(s*l/h/n),j=0,p=0;h>p;){for(i=0,o=0;g>o;)t.clearRect(0,0,s,s),t.drawImage(d,e,f,g,h,-o,-p,g,h),q.drawImage(r,0,0,s,s,i,j,k,l),o+=s,i+=k;p+=s,j+=l}return q.restore(),c}}return b(c,d,e,f,g,h,i,j,k,l)}}}),function(a,b){"use strict";function c(b,c,d){var e=b.blob,f=b.file;if(f){if(!e.toDataURL)return void a.readAsBinaryString(e,function(a){"load"==a.type&&c(b,a.result)});var g={"image/jpeg":".jpe?g","image/png":".png"},h=g[b.type]?b.type:"image/png",i=g[h]||".png",j=e.quality||1;f.match(new RegExp(i+"$","i"))||(f+=i.replace("?","")),b.file=f,b.type=h,!d&&e.toBlob?e.toBlob(function(a){c(b,a)},h,j):c(b,a.toBinaryString(e.toDataURL(h,j)))}else c(b,e)}var d=b.document,e=b.FormData,f=function(){this.items=[]},g=b.encodeURIComponent;f.prototype={append:function(a,b,c,d){this.items.push({name:a,blob:b&&b.blob||(void 0==b?"":b),file:b&&(c||b.name),type:b&&(d||b.type)})},each:function(a){for(var b=0,c=this.items.length;c>b;b++)a.call(this,this.items[b])},toData:function(b,c){c._chunked=a.support.chunked&&c.chunkSize>0&&1==a.filter(this.items,function(a){return a.file}).length,a.support.html5?a.formData&&!this.multipart&&e?c._chunked?(a.log("FileAPI.Form.toPlainData"),this.toPlainData(b)):(a.log("FileAPI.Form.toFormData"),this.toFormData(b)):(a.log("FileAPI.Form.toMultipartData"),this.toMultipartData(b)):(a.log("FileAPI.Form.toHtmlData"),this.toHtmlData(b))},_to:function(b,c,d,e){var f=a.queue(function(){c(b)});this.each(function(a){d(a,b,f,e)}),f.check()},toHtmlData:function(b){this._to(d.createDocumentFragment(),b,function(b,c){var e,f=b.blob;b.file?(a.reset(f,!0),f.name=b.name,c.appendChild(f)):(e=d.createElement("input"),e.name=b.name,e.type="hidden",e.value=f,c.appendChild(e))})},toPlainData:function(a){this._to({},a,function(a,b,d){a.file&&(b.type=a.file),a.blob.toBlob?(d.inc(),c(a,function(a,c){b.name=a.name,b.file=c,b.size=c.length,b.type=a.type,d.next()})):a.file?(b.name=a.blob.name,b.file=a.blob,b.size=a.blob.size,b.type=a.type):(b.params||(b.params=[]),b.params.push(g(a.name)+"="+g(a.blob))),b.start=-1,b.end=b.file&&b.file.FileAPIReadPosition||-1,b.retry=0})},toFormData:function(a){this._to(new e,a,function(a,b,d){a.blob&&a.blob.toBlob?(d.inc(),c(a,function(a,c){b.append(a.name,c,a.file),d.next()})):a.file?b.append(a.name,a.blob,a.file):b.append(a.name,a.blob),a.file&&b.append("_"+a.name,a.file)})},toMultipartData:function(b){this._to([],b,function(a,b,d,e){d.inc(),c(a,function(a,c){b.push("--_"+e+('\r\nContent-Disposition: form-data; name="'+a.name+'"'+(a.file?'; filename="'+g(a.file)+'"':"")+(a.file?"\r\nContent-Type: "+(a.type||"application/octet-stream"):"")+"\r\n\r\n"+(a.file?c:g(c))+"\r\n")),d.next()},!0)},a.expando)}},a.Form=f}(FileAPI,window),function(a,b){"use strict";var c=function(){},d=a.document,e=function(a){this.uid=b.uid(),this.xhr={abort:c,getResponseHeader:c,getAllResponseHeaders:c},this.options=a},f={"":1,XML:1,Text:1,Body:1};e.prototype={status:0,statusText:"",constructor:e,getResponseHeader:function(a){return this.xhr.getResponseHeader(a)},getAllResponseHeaders:function(){return this.xhr.getAllResponseHeaders()||{}},end:function(d,e){var f=this,g=f.options;f.end=f.abort=c,f.status=d,e&&(f.statusText=e),b.log("xhr.end:",d,e),g.complete(200==d||201==d?!1:f.statusText||"unknown",f),f.xhr&&f.xhr.node&&setTimeout(function(){var b=f.xhr.node;try{b.parentNode.removeChild(b)}catch(c){}try{delete a[f.uid]}catch(c){}a[f.uid]=f.xhr.node=null},9)},abort:function(){this.end(0,"abort"),this.xhr&&(this.xhr.aborted=!0,this.xhr.abort())},send:function(a){var b=this,c=this.options;a.toData(function(a){c.upload(c,b),b._send.call(b,c,a)},c)},_send:function(c,e){var g,h=this,i=h.uid,j=c.url;if(b.log("XHR._send:",e),c.cache||(j+=(~j.indexOf("?")?"&":"?")+b.uid()),e.nodeName){var k=c.jsonp;j=j.replace(/([a-z]+)=(\?)/i,"$1="+i),c.upload(c,h),g=d.createElement("div"),g.innerHTML='<form target="'+i+'" action="'+j+'" method="POST" enctype="multipart/form-data" style="position: absolute; top: -1000px; overflow: hidden; width: 1px; height: 1px;"><iframe name="'+i+'" src="javascript:false;"></iframe>'+(k&&c.url.indexOf("=?")<0?'<input value="'+i+'" name="'+k+'" type="hidden"/>':"")+"</form>";var l=g.getElementsByTagName("form")[0],m=g.getElementsByTagName("iframe")[0];l.appendChild(e),b.log(l.parentNode.innerHTML),d.body.appendChild(g),h.xhr.node=g;var n=function(a){if(~j.indexOf(a.origin))try{var c=b.parseJSON(a.data);c.id==i&&o(c.status,c.statusText,c.response)}catch(d){o(0,d.message)}},o=a[i]=function(c,d,e){h.readyState=4,h.responseText=e,h.end(c,d),b.event.off(a,"message",n),a[i]=g=m=m.onload=null};h.xhr.abort=function(){try{m.stop?m.stop():m.contentWindow.stop?m.contentWindow.stop():m.contentWindow.document.execCommand("Stop")}catch(a){}o(0,"abort")},b.event.on(a,"message",n),m.onload=function(){try{var a=m.contentWindow,c=a.document,d=a.result||b.parseJSON(c.body.innerHTML);o(d.status,d.statusText,d.response)}catch(e){b.log("[transport.onload]",e)}},h.readyState=2,l.submit(),l=null}else{if(j=j.replace(/([a-z]+)=(\?)&?/i,""),this.xhr&&this.xhr.aborted)return void b.log("Error: already aborted");if(g=h.xhr=b.getXHR(),e.params&&(j+=(j.indexOf("?")<0?"?":"&")+e.params.join("&")),g.open("POST",j,!0),b.withCredentials&&(g.withCredentials="true"),c.headers&&c.headers["X-Requested-With"]||g.setRequestHeader("X-Requested-With","XMLHttpRequest"),b.each(c.headers,function(a,b){g.setRequestHeader(b,a)}),c._chunked){g.upload&&g.upload.addEventListener("progress",b.throttle(function(a){e.retry||c.progress({type:a.type,total:e.size,loaded:e.start+a.loaded,totalSize:e.size},h,c)},100),!1),g.onreadystatechange=function(){var a=parseInt(g.getResponseHeader("X-Last-Known-Byte"),10);if(h.status=g.status,h.statusText=g.statusText,h.readyState=g.readyState,4==g.readyState){for(var d in f)h["response"+d]=g["response"+d];if(g.onreadystatechange=null,!g.status||g.status-201>0)if(b.log("Error: "+g.status),(!g.status&&!g.aborted||500==g.status||416==g.status)&&++e.retry<=c.chunkUploadRetry){var i=g.status?0:b.chunkNetworkDownRetryTimeout;c.pause(e.file,c),b.log("X-Last-Known-Byte: "+a),a?e.end=a:(e.end=e.start-1,416==g.status&&(e.end=e.end-c.chunkSize)),setTimeout(function(){h._send(c,e)},i)}else h.end(g.status);else e.retry=0,e.end==e.size-1?h.end(g.status):(b.log("X-Last-Known-Byte: "+a),a&&(e.end=a),e.file.FileAPIReadPosition=e.end,setTimeout(function(){h._send(c,e)},0));g=null}},e.start=e.end+1,e.end=Math.max(Math.min(e.start+c.chunkSize,e.size)-1,e.start);var p=e.file,q=(p.slice||p.mozSlice||p.webkitSlice).call(p,e.start,e.end+1);e.size&&!q.size?setTimeout(function(){h.end(-1)}):(g.setRequestHeader("Content-Range","bytes "+e.start+"-"+e.end+"/"+e.size),g.setRequestHeader("Content-Disposition","attachment; filename="+encodeURIComponent(e.name)),g.setRequestHeader("Content-Type",e.type||"application/octet-stream"),g.send(q)),p=q=null}else if(g.upload&&g.upload.addEventListener("progress",b.throttle(function(a){c.progress(a,h,c)},100),!1),g.onreadystatechange=function(){if(h.status=g.status,h.statusText=g.statusText,h.readyState=g.readyState,4==g.readyState){for(var a in f)h["response"+a]=g["response"+a];if(g.onreadystatechange=null,!g.status||g.status>201)if(b.log("Error: "+g.status),(!g.status&&!g.aborted||500==g.status)&&(c.retry||0)<c.uploadRetry){c.retry=(c.retry||0)+1;var d=b.networkDownRetryTimeout;c.pause(c.file,c),setTimeout(function(){h._send(c,e)},d)}else h.end(g.status);else h.end(g.status);g=null}},b.isArray(e)){g.setRequestHeader("Content-Type","multipart/form-data; boundary=_"+b.expando);var r=e.join("")+"--_"+b.expando+"--";if(g.sendAsBinary)g.sendAsBinary(r);else{var s=Array.prototype.map.call(r,function(a){return 255&a.charCodeAt(0)});g.send(new Uint8Array(s).buffer)}}else g.send(e)}}},b.XHR=e}(window,FileAPI),function(a,b){"use strict";function c(a){return a>=0?a+"px":a}function d(a){var b,c=f.createElement("canvas"),d=!1;try{b=c.getContext("2d"),b.drawImage(a,0,0,1,1),d=255!=b.getImageData(0,0,1,1).data[4]}catch(e){}return d}var e=a.URL||a.webkitURL,f=a.document,g=a.navigator,h=g.getUserMedia||g.webkitGetUserMedia||g.mozGetUserMedia||g.msGetUserMedia,i=!!h;b.support.media=i;var j=function(a){this.video=a};j.prototype={isActive:function(){return!!this._active},start:function(a){var b,c,f=this,i=f.video,j=function(d){f._active=!d,clearTimeout(c),clearTimeout(b),a&&a(d,f)};h.call(g,{video:!0},function(a){f.stream=a,i.src=e.createObjectURL(a),b=setInterval(function(){d(i)&&j(null)},1e3),c=setTimeout(function(){j("timeout")},5e3),i.play()},j)},stop:function(){try{this._active=!1,this.video.pause(),this.stream.stop()}catch(a){}},shot:function(){return new k(this.video)}},j.get=function(a){return new j(a.firstChild)},j.publish=function(d,e,g){"function"==typeof e&&(g=e,e={}),e=b.extend({},{width:"100%",height:"100%",start:!0},e),d.jquery&&(d=d[0]);var h=function(a){if(a)g(a);else{var b=j.get(d);e.start?b.start(g):g(null,b)}};if(d.style.width=c(e.width),d.style.height=c(e.height),b.html5&&i){var k=f.createElement("video");k.style.width=c(e.width),k.style.height=c(e.height),a.jQuery?jQuery(d).empty():d.innerHTML="",d.appendChild(k),h()}else j.fallback(d,e,h)},j.fallback=function(a,b,c){c("not_support_camera")};var k=function(a){var c=a.nodeName?b.Image.toCanvas(a):a,d=b.Image(c);return d.type="image/png",d.width=c.width,d.height=c.height,d.size=c.width*c.height*4,d};j.Shot=k,b.Camera=j}(window,FileAPI),function(a,b,c){"use strict";var d=a.document,e=a.location,f=a.navigator,g=c.each;c.support.flash=function(){var b=f.mimeTypes,d=!1;if(f.plugins&&"object"==typeof f.plugins["Shockwave Flash"])d=f.plugins["Shockwave Flash"].description&&!(b&&b["application/x-shockwave-flash"]&&!b["application/x-shockwave-flash"].enabledPlugin);else try{d=!(!a.ActiveXObject||!new ActiveXObject("ShockwaveFlash.ShockwaveFlash"))}catch(g){c.log("Flash -- does not supported.")
3
+ }return d&&/^file:/i.test(e)&&c.log("[warn] Flash does not work on `file:` protocol."),d}(),c.support.flash&&(0||!c.html5||!c.support.html5||c.cors&&!c.support.cors||c.media&&!c.support.media)&&function(){function h(a){return('<object id="#id#" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+(a.width||"100%")+'" height="'+(a.height||"100%")+'"><param name="movie" value="#src#" /><param name="flashvars" value="#flashvars#" /><param name="swliveconnect" value="true" /><param name="allowscriptaccess" value="always" /><param name="allownetworking" value="all" /><param name="menu" value="false" /><param name="wmode" value="#wmode#" /><embed flashvars="#flashvars#" swliveconnect="true" allownetworking="all" allowscriptaccess="always" name="#id#" src="#src#" width="'+(a.width||"100%")+'" height="'+(a.height||"100%")+'" menu="false" wmode="transparent" type="application/x-shockwave-flash"></embed></object>').replace(/#(\w+)#/gi,function(b,c){return a[c]})}function i(a,b){if(a&&a.style){var c,d;for(c in b){d=b[c],"number"==typeof d&&(d+="px");try{a.style[c]=d}catch(e){}}}}function j(a,b){g(b,function(b,c){var d=a[c];a[c]=function(){return this.parent=d,b.apply(this,arguments)}})}function k(a){return a&&!a.flashId}function l(a){var b=a.wid=c.uid();return v._fn[b]=a,"FileAPI.Flash._fn."+b}function m(a){try{v._fn[a.wid]=null,delete v._fn[a.wid]}catch(b){}}function n(a,b){if(!u.test(a)){if(/^\.\//.test(a)||"/"!=a.charAt(0)){var c=e.pathname;c=c.substr(0,c.lastIndexOf("/")),a=(c+"/"+a).replace("/./","/")}"//"!=a.substr(0,2)&&(a="//"+e.host+a),u.test(a)||(a=e.protocol+a)}return b&&(a+=(/\?/.test(a)?"&":"?")+b),a}function o(a,b,e){function f(){try{var a=v.get(j);a.setImage(b)}catch(d){c.log('[err] FlashAPI.Preview.setImage -- can not set "base64":',d)}}var g,j=c.uid(),k=d.createElement("div"),o=10;for(g in a)k.setAttribute(g,a[g]),k[g]=a[g];i(k,a),a.width="100%",a.height="100%",k.innerHTML=h(c.extend({id:j,src:n(c.flashImageUrl,"r="+c.uid()),wmode:"opaque",flashvars:"scale="+a.scale+"&callback="+l(function p(){return m(p),--o>0&&f(),!0})},a)),e(!1,k),k=null}function p(a){return{id:a.id,name:a.name,matrix:a.matrix,flashId:a.flashId}}function q(b){var c=b.getBoundingClientRect(),e=d.body,f=(b&&b.ownerDocument).documentElement;return{top:c.top+(a.pageYOffset||f.scrollTop)-(f.clientTop||e.clientTop||0),left:c.left+(a.pageXOffset||f.scrollLeft)-(f.clientLeft||e.clientLeft||0),width:c.right-c.left,height:c.bottom-c.top}}var r=c.uid(),s=0,t={},u=/^https?:/i,v={_fn:{},init:function(){var a=d.body&&d.body.firstChild;if(a)do if(1==a.nodeType){c.log("FlashAPI.state: awaiting");var b=d.createElement("div");return b.id="_"+r,i(b,{top:1,right:1,width:5,height:5,position:"absolute",zIndex:1e6+""}),a.parentNode.insertBefore(b,a),void v.publish(b,r)}while(a=a.nextSibling);10>s&&setTimeout(v.init,50*++s)},publish:function(a,b,d){d=d||{},a.innerHTML=h({id:b,src:n(c.flashUrl,"r="+c.version),wmode:d.camera?"":"transparent",flashvars:"callback="+(d.onEvent||"FileAPI.Flash.onEvent")+"&flashId="+b+"&storeKey="+f.userAgent.match(/\d/gi).join("")+"_"+c.version+(v.isReady||(c.pingUrl?"&ping="+c.pingUrl:""))+"&timeout="+c.flashAbortTimeout+(d.camera?"&useCamera="+n(c.flashWebcamUrl):"")+"&debug="+(c.debug?"1":"")},d)},ready:function(){c.log("FlashAPI.state: ready"),v.ready=c.F,v.isReady=!0,v.patch(),v.patchCamera&&v.patchCamera(),c.event.on(d,"mouseover",v.mouseover),c.event.on(d,"click",function(a){v.mouseover(a)&&(a.preventDefault?a.preventDefault():a.returnValue=!0)})},getEl:function(){return d.getElementById("_"+r)},getWrapper:function(a){do if(/js-fileapi-wrapper/.test(a.className))return a;while((a=a.parentNode)&&a!==d.body)},mouseover:function(a){var b=c.event.fix(a).target;if(/input/i.test(b.nodeName)&&"file"==b.type){var e=b.getAttribute(r),f=v.getWrapper(b);if(c.multiFlash){if("i"==e||"r"==e)return!1;if("p"!=e){b.setAttribute(r,"i");var g=d.createElement("div");if(!f)return void c.log("[err] FlashAPI.mouseover: js-fileapi-wrapper not found");i(g,{top:0,left:0,width:b.offsetWidth+100,height:b.offsetHeight+100,zIndex:1e6+"",position:"absolute"}),f.appendChild(g),v.publish(g,c.uid()),b.setAttribute(r,"p")}return!0}if(f){var h=q(f);i(v.getEl(),h),v.curInp=b}}else/object|embed/i.test(b.nodeName)||i(v.getEl(),{top:1,left:1,width:5,height:5})},onEvent:function(a){var b=a.type;if("ready"==b){try{v.getInput(a.flashId).setAttribute(r,"r")}catch(d){}return v.ready(),setTimeout(function(){v.mouseenter(a)},50),!0}"ping"===b?c.log("(flash -> js).ping:",[a.status,a.savedStatus],a.error):"log"===b?c.log("(flash -> js).log:",a.target):b in v&&setTimeout(function(){c.log("FlashAPI.event."+a.type+":",a),v[b](a)},1)},mouseenter:function(a){var b=v.getInput(a.flashId);if(b){v.cmd(a,"multiple",null!=b.getAttribute("multiple"));var d=[],e={};g((b.getAttribute("accept")||"").split(/,\s*/),function(a){c.accept[a]&&g(c.accept[a].split(" "),function(a){e[a]=1})}),g(e,function(a,b){d.push(b)}),v.cmd(a,"accept",d.length?d.join(",")+","+d.join(",").toUpperCase():"*")}},get:function(b){return d[b]||a[b]||d.embeds[b]},getInput:function(a){if(!c.multiFlash)return v.curInp;try{var b=v.getWrapper(v.get(a));if(b)return b.getElementsByTagName("input")[0]}catch(d){c.log('[err] Can not find "input" by flashId:',a,d)}},select:function(a){var e,f=v.getInput(a.flashId),h=c.uid(f),i=a.target.files;g(i,function(a){c.checkFileObj(a)}),t[h]=i,d.createEvent?(e=d.createEvent("Event"),e.files=i,e.initEvent("change",!0,!0),f.dispatchEvent(e)):b?b(f).trigger({type:"change",files:i}):(e=d.createEventObject(),e.files=i,f.fireEvent("onchange",e))},cmd:function(a,b,d,e){try{return c.log("(js -> flash)."+b+":",d),v.get(a.flashId||a).cmd(b,d)}catch(f){c.log("(js -> flash).onError:",f),e||setTimeout(function(){v.cmd(a,b,d,!0)},50)}},patch:function(){c.flashEngine=!0,j(c,{getFiles:function(a,b,d){if(d)return c.filterFiles(c.getFiles(a),b,d),null;var e=c.isArray(a)?a:t[c.uid(a.target||a.srcElement||a)];return e?(b&&(b=c.getFilesFilter(b),e=c.filter(e,function(a){return b.test(a.name)})),e):this.parent.apply(this,arguments)},getInfo:function(a,b){if(k(a))this.parent.apply(this,arguments);else if(a.isShot)b(null,a.info={width:a.width,height:a.height});else{if(!a.__info){var d=a.__info=c.defer();v.cmd(a,"getFileInfo",{id:a.id,callback:l(function e(b,c){m(e),d.resolve(b,a.info=c)})})}a.__info.then(b)}}}),c.support.transform=!0,c.Image&&j(c.Image.prototype,{get:function(a,b){return this.set({scaleMode:b||"noScale"}),this.parent(a)},_load:function(a,b){if(c.log("FlashAPI.Image._load:",a),k(a))this.parent.apply(this,arguments);else{var d=this;c.getInfo(a,function(c){b.call(d,c,a)})}},_apply:function(a,b){if(c.log("FlashAPI.Image._apply:",a),k(a))this.parent.apply(this,arguments);else{var d=this.getMatrix(a.info),e=b;v.cmd(a,"imageTransform",{id:a.id,matrix:d,callback:l(function f(g,h){c.log("FlashAPI.Image._apply.callback:",g),m(f),g?e(g):c.support.html5||c.support.dataURI&&!(h.length>3e4)?(d.filter&&(e=function(a,e){a?b(a):c.Image.applyFilter(e,d.filter,function(){b(a,this.canvas)})}),c.newImage("data:"+a.type+";base64,"+h,e)):o({width:d.deg%180?d.dh:d.dw,height:d.deg%180?d.dw:d.dh,scale:d.scaleMode},h,e)})})}},toData:function(a){var b=this.file,d=b.info,e=this.getMatrix(d);c.log("FlashAPI.Image.toData"),k(b)?this.parent.apply(this,arguments):("auto"==e.deg&&(e.deg=c.Image.exifOrientation[d&&d.exif&&d.exif.Orientation]||0),a.call(this,!b.info,{id:b.id,flashId:b.flashId,name:b.name,type:b.type,matrix:e}))}}),c.Image&&j(c.Image,{fromDataURL:function(a,b,d){!c.support.dataURI||a.length>3e4?o(c.extend({scale:"exactFit"},b),a.replace(/^data:[^,]+,/,""),function(a,b){d(b)}):this.parent(a,b,d)}}),j(c.Form.prototype,{toData:function(a){for(var b=this.items,d=b.length;d--;)if(b[d].file&&k(b[d].blob))return this.parent.apply(this,arguments);c.log("FlashAPI.Form.toData"),a(b)}}),j(c.XHR.prototype,{_send:function(a,b){if(b.nodeName||b.append&&c.support.html5||c.isArray(b)&&"string"==typeof b[0])return this.parent.apply(this,arguments);var d,e,f={},h={},i=this;if(g(b,function(a){a.file?(h[a.name]=a=p(a.blob),e=a.id,d=a.flashId):f[a.name]=a.blob}),e||(d=r),!d)return c.log("[err] FlashAPI._send: flashId -- undefined"),this.parent.apply(this,arguments);c.log("FlashAPI.XHR._send: "+d+" -> "+e),i.xhr={headers:{},abort:function(){v.cmd(d,"abort",{id:e})},getResponseHeader:function(a){return this.headers[a]},getAllResponseHeaders:function(){return this.headers}};var j=c.queue(function(){v.cmd(d,"upload",{url:n(a.url.replace(/([a-z]+)=(\?)&?/i,"")),data:f,files:e?h:null,headers:a.headers||{},callback:l(function b(d){var e=d.type,f=d.result;c.log("FlashAPI.upload."+e),"progress"==e?(d.loaded=Math.min(d.loaded,d.total),d.lengthComputable=!0,a.progress(d)):"complete"==e?(m(b),"string"==typeof f&&(i.responseText=f.replace(/%22/g,'"').replace(/%5c/g,"\\").replace(/%26/g,"&").replace(/%25/g,"%")),i.end(d.status||200)):("abort"==e||"error"==e)&&(i.end(d.status||0,d.message),m(b))})})});g(h,function(a){j.inc(),c.getInfo(a,j.next)}),j.check()}})}};c.Flash=v,c.newImage("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==",function(a,b){c.support.dataURI=!(1!=b.width||1!=b.height),v.init()})}()}(window,window.jQuery,FileAPI),function(a,b,c){"use strict";var d=c.each,e=[];c.support.flash&&c.media&&!c.support.media&&!function(){function a(a){var b=a.wid=c.uid();return c.Flash._fn[b]=a,"FileAPI.Flash._fn."+b}function b(a){try{c.Flash._fn[a.wid]=null,delete c.Flash._fn[a.wid]}catch(b){}}var f=c.Flash;c.extend(c.Flash,{patchCamera:function(){c.Camera.fallback=function(d,e,g){var h=c.uid();c.log("FlashAPI.Camera.publish: "+h),f.publish(d,h,c.extend(e,{camera:!0,onEvent:a(function i(a){"camera"===a.type&&(b(i),a.error?(c.log("FlashAPI.Camera.publish.error: "+a.error),g(a.error)):(c.log("FlashAPI.Camera.publish.success: "+h),g(null)))})}))},d(e,function(a){c.Camera.fallback.apply(c.Camera,a)}),e=[],c.extend(c.Camera.prototype,{_id:function(){return this.video.id},start:function(d){var e=this;f.cmd(this._id(),"camera.on",{callback:a(function g(a){b(g),a.error?(c.log("FlashAPI.camera.on.error: "+a.error),d(a.error,e)):(c.log("FlashAPI.camera.on.success: "+e._id()),e._active=!0,d(null,e))})})},stop:function(){this._active=!1,f.cmd(this._id(),"camera.off")},shot:function(){c.log("FlashAPI.Camera.shot:",this._id());var a=c.Flash.cmd(this._id(),"shot",{});return a.type="image/png",a.flashId=this._id(),a.isShot=!0,new c.Camera.Shot(a)}})}}),c.Camera.fallback=function(){e.push(arguments)}}()}(window,window.jQuery,FileAPI),"function"==typeof define&&define.amd&&define("FileAPI",[],function(){return FileAPI});
@@ -0,0 +1,30 @@
1
+ /**!
2
+ * AngularJS file upload shim for angular XHR HTML5 browsers
3
+ * @author Danial <danial.farid@gmail.com>
4
+ * @version 1.6.1
5
+ */
6
+ if (window.XMLHttpRequest) {
7
+ if (window.FormData) {
8
+ // allow access to Angular XHR private field: https://github.com/angular/angular.js/issues/1934
9
+ XMLHttpRequest = (function(origXHR) {
10
+ return function() {
11
+ var xhr = new origXHR();
12
+ xhr.setRequestHeader = (function(orig) {
13
+ return function(header, value) {
14
+ if (header === '__setXHR_') {
15
+ var val = value(xhr);
16
+ // fix for angular < 1.2.0
17
+ if (val instanceof Function) {
18
+ val(xhr);
19
+ }
20
+ } else {
21
+ orig.apply(xhr, arguments);
22
+ }
23
+ }
24
+ })(xhr.setRequestHeader);
25
+ return xhr;
26
+ }
27
+ })(XMLHttpRequest);
28
+ window.XMLHttpRequest.__isShim = true;
29
+ }
30
+ }
@@ -0,0 +1,338 @@
1
+ /**!
2
+ * AngularJS file upload shim for HTML5 FormData
3
+ * @author Danial <danial.farid@gmail.com>
4
+ * @version 1.6.1
5
+ */
6
+ (function() {
7
+
8
+ var hasFlash = function() {
9
+ try {
10
+ var fo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
11
+ if (fo) return true;
12
+ } catch(e) {
13
+ if (navigator.mimeTypes["application/x-shockwave-flash"] != undefined) return true;
14
+ }
15
+ return false;
16
+ }
17
+
18
+ var patchXHR = function(fnName, newFn) {
19
+ window.XMLHttpRequest.prototype[fnName] = newFn(window.XMLHttpRequest.prototype[fnName]);
20
+ };
21
+
22
+ if (window.XMLHttpRequest) {
23
+ if (window.FormData && (!window.FileAPI || !FileAPI.forceLoad)) {
24
+ // allow access to Angular XHR private field: https://github.com/angular/angular.js/issues/1934
25
+ patchXHR("setRequestHeader", function(orig) {
26
+ return function(header, value) {
27
+ if (header === '__setXHR_') {
28
+ var val = value(this);
29
+ // fix for angular < 1.2.0
30
+ if (val instanceof Function) {
31
+ val(this);
32
+ }
33
+ } else {
34
+ orig.apply(this, arguments);
35
+ }
36
+ }
37
+ });
38
+ } else {
39
+ function initializeUploadListener(xhr) {
40
+ if (!xhr.__listeners) {
41
+ if (!xhr.upload) xhr.upload = {};
42
+ xhr.__listeners = [];
43
+ var origAddEventListener = xhr.upload.addEventListener;
44
+ xhr.upload.addEventListener = function(t, fn, b) {
45
+ xhr.__listeners[t] = fn;
46
+ origAddEventListener && origAddEventListener.apply(this, arguments);
47
+ };
48
+ }
49
+ }
50
+
51
+ patchXHR("open", function(orig) {
52
+ return function(m, url, b) {
53
+ initializeUploadListener(this);
54
+ this.__url = url;
55
+ try {
56
+ orig.apply(this, [m, url, b]);
57
+ } catch (e) {
58
+ if (e.message.indexOf('Access is denied') > -1) {
59
+ orig.apply(this, [m, '_fix_for_ie_crossdomain__', b]);
60
+ }
61
+ }
62
+ }
63
+ });
64
+
65
+ patchXHR("getResponseHeader", function(orig) {
66
+ return function(h) {
67
+ return this.__fileApiXHR ? this.__fileApiXHR.getResponseHeader(h) : orig.apply(this, [h]);
68
+ };
69
+ });
70
+
71
+ patchXHR("getAllResponseHeaders", function(orig) {
72
+ return function() {
73
+ return this.__fileApiXHR ? this.__fileApiXHR.abort() : (orig == null ? null : orig.apply(this));
74
+ }
75
+ });
76
+
77
+ patchXHR("abort", function(orig) {
78
+ return function() {
79
+ return this.__fileApiXHR ? this.__fileApiXHR.abort() : (orig == null ? null : orig.apply(this));
80
+ }
81
+ });
82
+
83
+ patchXHR("setRequestHeader", function(orig) {
84
+ return function(header, value) {
85
+ if (header === '__setXHR_') {
86
+ initializeUploadListener(this);
87
+ var val = value(this);
88
+ // fix for angular < 1.2.0
89
+ if (val instanceof Function) {
90
+ val(this);
91
+ }
92
+ } else {
93
+ this.__requestHeaders = this.__requestHeaders || {};
94
+ this.__requestHeaders[header] = value;
95
+ orig.apply(this, arguments);
96
+ }
97
+ }
98
+ });
99
+
100
+ patchXHR("send", function(orig) {
101
+ return function() {
102
+ var xhr = this;
103
+ if (arguments[0] && arguments[0].__isShim) {
104
+ var formData = arguments[0];
105
+ var config = {
106
+ url: xhr.__url,
107
+ complete: function(err, fileApiXHR) {
108
+ if (!err && xhr.__listeners['load'])
109
+ xhr.__listeners['load']({type: 'load', loaded: xhr.__loaded, total: xhr.__total, target: xhr, lengthComputable: true});
110
+ if (!err && xhr.__listeners['loadend'])
111
+ xhr.__listeners['loadend']({type: 'loadend', loaded: xhr.__loaded, total: xhr.__total, target: xhr, lengthComputable: true});
112
+ if (err === 'abort' && xhr.__listeners['abort'])
113
+ xhr.__listeners['abort']({type: 'abort', loaded: xhr.__loaded, total: xhr.__total, target: xhr, lengthComputable: true});
114
+ if (fileApiXHR.status !== undefined) Object.defineProperty(xhr, 'status', {get: function() {return fileApiXHR.status}});
115
+ if (fileApiXHR.statusText !== undefined) Object.defineProperty(xhr, 'statusText', {get: function() {return fileApiXHR.statusText}});
116
+ Object.defineProperty(xhr, 'readyState', {get: function() {return 4}});
117
+ if (fileApiXHR.response !== undefined) Object.defineProperty(xhr, 'response', {get: function() {return fileApiXHR.response}});
118
+ Object.defineProperty(xhr, 'responseText', {get: function() {return fileApiXHR.responseText}});
119
+ Object.defineProperty(xhr, 'response', {get: function() {return fileApiXHR.responseText}});
120
+ xhr.__fileApiXHR = fileApiXHR;
121
+ xhr.onreadystatechange();
122
+ },
123
+ fileprogress: function(e) {
124
+ e.target = xhr;
125
+ xhr.__listeners['progress'] && xhr.__listeners['progress'](e);
126
+ xhr.__total = e.total;
127
+ xhr.__loaded = e.loaded;
128
+ },
129
+ headers: xhr.__requestHeaders
130
+ }
131
+ config.data = {};
132
+ config.files = {}
133
+ for (var i = 0; i < formData.data.length; i++) {
134
+ var item = formData.data[i];
135
+ if (item.val != null && item.val.name != null && item.val.size != null && item.val.type != null) {
136
+ config.files[item.key] = item.val;
137
+ } else {
138
+ config.data[item.key] = item.val;
139
+ }
140
+ }
141
+
142
+ setTimeout(function() {
143
+ if (!hasFlash()) {
144
+ throw 'Adode Flash Player need to be installed. To check ahead use "FileAPI.hasFlash"';
145
+ }
146
+ xhr.__fileApiXHR = FileAPI.upload(config);
147
+ }, 1);
148
+ } else {
149
+ orig.apply(xhr, arguments);
150
+ }
151
+ }
152
+ });
153
+ }
154
+ window.XMLHttpRequest.__isShim = true;
155
+ }
156
+
157
+ if (!window.FormData || (window.FileAPI && FileAPI.forceLoad)) {
158
+ var addFlash = function(elem) {
159
+ if (!hasFlash()) {
160
+ throw 'Adode Flash Player need to be installed. To check ahead use "FileAPI.hasFlash"';
161
+ }
162
+ var el = angular.element(elem);
163
+ if (!el.hasClass('js-fileapi-wrapper') && (elem.getAttribute('ng-file-select') != null || elem.getAttribute('data-ng-file-select') != null)) {
164
+ // var wrap = document.createElement('div');
165
+ // wrap.innerHTML = '<div class="js-fileapi-wrapper" style="position:relative; overflow:hidden"></div>';
166
+ // wrap = wrap.firstChild;
167
+ // var parent = elem.parentNode;
168
+ // parent.insertBefore(wrap, elem);
169
+ // parent.removeChild(elem);
170
+ // wrap.appendChild(elem);
171
+ el.addClass('js-fileapi-wrapper');
172
+ }
173
+ };
174
+ var changeFnWrapper = function(fn) {
175
+ return function(evt) {
176
+ var files = FileAPI.getFiles(evt);
177
+ //just a double check for #233
178
+ for (var i = 0; i < files.length; i++) {
179
+ if (files[i].size === undefined) files[i].size = 0;
180
+ if (files[i].name === undefined) files[i].name = 'file';
181
+ if (files[i].type === undefined) files[i].type = 'undefined';
182
+ }
183
+ if (!evt.target) {
184
+ evt.target = {};
185
+ }
186
+ evt.target.files = files;
187
+ // if evt.target.files is not writable use helper field
188
+ if (evt.target.files != files) {
189
+ evt.__files_ = files;
190
+ }
191
+ (evt.__files_ || evt.target.files).item = function(i) {
192
+ return (evt.__files_ || evt.target.files)[i] || null;
193
+ }
194
+ fn(evt);
195
+ };
196
+ };
197
+ var isFileChange = function(elem, e) {
198
+ return (e.toLowerCase() === 'change' || e.toLowerCase() === 'onchange') && elem.getAttribute('type') == 'file';
199
+ }
200
+ if (HTMLInputElement.prototype.addEventListener) {
201
+ HTMLInputElement.prototype.addEventListener = (function(origAddEventListener) {
202
+ return function(e, fn, b, d) {
203
+ if (isFileChange(this, e)) {
204
+ addFlash(this);
205
+ origAddEventListener.apply(this, [e, changeFnWrapper(fn), b, d]);
206
+ } else {
207
+ origAddEventListener.apply(this, [e, fn, b, d]);
208
+ }
209
+ }
210
+ })(HTMLInputElement.prototype.addEventListener);
211
+ }
212
+ if (HTMLInputElement.prototype.attachEvent) {
213
+ HTMLInputElement.prototype.attachEvent = (function(origAttachEvent) {
214
+ return function(e, fn) {
215
+ if (isFileChange(this, e)) {
216
+ addFlash(this);
217
+ origAttachEvent.apply(this, [e, changeFnWrapper(fn)]);
218
+ } else {
219
+ origAttachEvent.apply(this, [e, fn]);
220
+ }
221
+ }
222
+ })(HTMLInputElement.prototype.attachEvent);
223
+ }
224
+
225
+ window.FormData = FormData = function() {
226
+ return {
227
+ append: function(key, val, name) {
228
+ this.data.push({
229
+ key: key,
230
+ val: val,
231
+ name: name
232
+ });
233
+ },
234
+ data: [],
235
+ __isShim: true
236
+ };
237
+ };
238
+
239
+ (function () {
240
+ //load FileAPI
241
+ if (!window.FileAPI) {
242
+ window.FileAPI = {};
243
+ }
244
+ if (FileAPI.forceLoad) {
245
+ FileAPI.html5 = false;
246
+ }
247
+
248
+ if (!FileAPI.upload) {
249
+ var jsUrl, basePath, script = document.createElement('script'), allScripts = document.getElementsByTagName('script'), i, index, src;
250
+ if (window.FileAPI.jsUrl) {
251
+ jsUrl = window.FileAPI.jsUrl;
252
+ } else if (window.FileAPI.jsPath) {
253
+ basePath = window.FileAPI.jsPath;
254
+ } else {
255
+ for (i = 0; i < allScripts.length; i++) {
256
+ src = allScripts[i].src;
257
+ index = src.indexOf('angular-file-upload-shim.js')
258
+ if (index == -1) {
259
+ index = src.indexOf('angular-file-upload-shim.min.js');
260
+ }
261
+ if (index > -1) {
262
+ basePath = src.substring(0, index);
263
+ break;
264
+ }
265
+ }
266
+ }
267
+
268
+ if (FileAPI.staticPath == null) FileAPI.staticPath = basePath;
269
+ script.setAttribute('src', jsUrl || basePath + "FileAPI.min.js");
270
+ document.getElementsByTagName('head')[0].appendChild(script);
271
+ FileAPI.hasFlash = hasFlash();
272
+ }
273
+ })();
274
+ }
275
+
276
+
277
+ if (!window.FileReader) {
278
+ window.FileReader = function() {
279
+ var _this = this, loadStarted = false;
280
+ this.listeners = {};
281
+ this.addEventListener = function(type, fn) {
282
+ _this.listeners[type] = _this.listeners[type] || [];
283
+ _this.listeners[type].push(fn);
284
+ };
285
+ this.removeEventListener = function(type, fn) {
286
+ _this.listeners[type] && _this.listeners[type].splice(_this.listeners[type].indexOf(fn), 1);
287
+ };
288
+ this.dispatchEvent = function(evt) {
289
+ var list = _this.listeners[evt.type];
290
+ if (list) {
291
+ for (var i = 0; i < list.length; i++) {
292
+ list[i].call(_this, evt);
293
+ }
294
+ }
295
+ };
296
+ this.onabort = this.onerror = this.onload = this.onloadstart = this.onloadend = this.onprogress = null;
297
+
298
+ function constructEvent(type, evt) {
299
+ var e = {type: type, target: _this, loaded: evt.loaded, total: evt.total, error: evt.error};
300
+ if (evt.result != null) e.target.result = evt.result;
301
+ return e;
302
+ };
303
+ var listener = function(evt) {
304
+ if (!loadStarted) {
305
+ loadStarted = true;
306
+ _this.onloadstart && this.onloadstart(constructEvent('loadstart', evt));
307
+ }
308
+ if (evt.type === 'load') {
309
+ _this.onloadend && _this.onloadend(constructEvent('loadend', evt));
310
+ var e = constructEvent('load', evt);
311
+ _this.onload && _this.onload(e);
312
+ _this.dispatchEvent(e);
313
+ } else if (evt.type === 'progress') {
314
+ var e = constructEvent('progress', evt);
315
+ _this.onprogress && _this.onprogress(e);
316
+ _this.dispatchEvent(e);
317
+ } else {
318
+ var e = constructEvent('error', evt);
319
+ _this.onerror && _this.onerror(e);
320
+ _this.dispatchEvent(e);
321
+ }
322
+ };
323
+ this.readAsArrayBuffer = function(file) {
324
+ FileAPI.readAsBinaryString(file, listener);
325
+ }
326
+ this.readAsBinaryString = function(file) {
327
+ FileAPI.readAsBinaryString(file, listener);
328
+ }
329
+ this.readAsDataURL = function(file) {
330
+ FileAPI.readAsDataURL(file, listener);
331
+ }
332
+ this.readAsText = function(file) {
333
+ FileAPI.readAsText(file, listener);
334
+ }
335
+ }
336
+ }
337
+
338
+ })();
@@ -0,0 +1,311 @@
1
+ /**!
2
+ * AngularJS file upload/drop directive with http post and progress
3
+ * @author Danial <danial.farid@gmail.com>
4
+ * @version 1.6.1
5
+ */
6
+ (function() {
7
+
8
+ var angularFileUpload = angular.module('angularFileUpload', []);
9
+
10
+ angularFileUpload.service('$upload', ['$http', '$q', '$timeout', function($http, $q, $timeout) {
11
+ function sendHttp(config) {
12
+ config.method = config.method || 'POST';
13
+ config.headers = config.headers || {};
14
+ config.transformRequest = config.transformRequest || function(data, headersGetter) {
15
+ if (window.ArrayBuffer && data instanceof window.ArrayBuffer) {
16
+ return data;
17
+ }
18
+ return $http.defaults.transformRequest[0](data, headersGetter);
19
+ };
20
+ var deferred = $q.defer();
21
+
22
+ if (window.XMLHttpRequest.__isShim) {
23
+ config.headers['__setXHR_'] = function() {
24
+ return function(xhr) {
25
+ if (!xhr) return;
26
+ config.__XHR = xhr;
27
+ config.xhrFn && config.xhrFn(xhr);
28
+ xhr.upload.addEventListener('progress', function(e) {
29
+ deferred.notify(e);
30
+ }, false);
31
+ //fix for firefox not firing upload progress end, also IE8-9
32
+ xhr.upload.addEventListener('load', function(e) {
33
+ if (e.lengthComputable) {
34
+ deferred.notify(e);
35
+ }
36
+ }, false);
37
+ };
38
+ };
39
+ }
40
+
41
+ $http(config).then(function(r){deferred.resolve(r)}, function(e){deferred.reject(e)}, function(n){deferred.notify(n)});
42
+
43
+ var promise = deferred.promise;
44
+ promise.success = function(fn) {
45
+ promise.then(function(response) {
46
+ fn(response.data, response.status, response.headers, config);
47
+ });
48
+ return promise;
49
+ };
50
+
51
+ promise.error = function(fn) {
52
+ promise.then(null, function(response) {
53
+ fn(response.data, response.status, response.headers, config);
54
+ });
55
+ return promise;
56
+ };
57
+
58
+ promise.progress = function(fn) {
59
+ promise.then(null, null, function(update) {
60
+ fn(update);
61
+ });
62
+ return promise;
63
+ };
64
+ promise.abort = function() {
65
+ if (config.__XHR) {
66
+ $timeout(function() {
67
+ config.__XHR.abort();
68
+ });
69
+ }
70
+ return promise;
71
+ };
72
+ promise.xhr = function(fn) {
73
+ config.xhrFn = (function(origXhrFn) {
74
+ return function() {
75
+ origXhrFn && origXhrFn.apply(promise, arguments);
76
+ fn.apply(promise, arguments);
77
+ }
78
+ })(config.xhrFn);
79
+ return promise;
80
+ };
81
+
82
+ return promise;
83
+ }
84
+
85
+ this.upload = function(config) {
86
+ config.headers = config.headers || {};
87
+ config.headers['Content-Type'] = undefined;
88
+ config.transformRequest = config.transformRequest || $http.defaults.transformRequest;
89
+ var formData = new FormData();
90
+ var origTransformRequest = config.transformRequest;
91
+ var origData = config.data;
92
+ config.transformRequest = function(formData, headerGetter) {
93
+ if (origData) {
94
+ if (config.formDataAppender) {
95
+ for (var key in origData) {
96
+ var val = origData[key];
97
+ config.formDataAppender(formData, key, val);
98
+ }
99
+ } else {
100
+ for (var key in origData) {
101
+ var val = origData[key];
102
+ if (typeof origTransformRequest == 'function') {
103
+ val = origTransformRequest(val, headerGetter);
104
+ } else {
105
+ for (var i = 0; i < origTransformRequest.length; i++) {
106
+ var transformFn = origTransformRequest[i];
107
+ if (typeof transformFn == 'function') {
108
+ val = transformFn(val, headerGetter);
109
+ }
110
+ }
111
+ }
112
+ formData.append(key, val);
113
+ }
114
+ }
115
+ }
116
+
117
+ if (config.file != null) {
118
+ var fileFormName = config.fileFormDataName || 'file';
119
+
120
+ if (Object.prototype.toString.call(config.file) === '[object Array]') {
121
+ var isFileFormNameString = Object.prototype.toString.call(fileFormName) === '[object String]';
122
+ for (var i = 0; i < config.file.length; i++) {
123
+ formData.append(isFileFormNameString ? fileFormName : fileFormName[i], config.file[i],
124
+ (config.fileName && config.fileName[i]) || config.file[i].name);
125
+ }
126
+ } else {
127
+ formData.append(fileFormName, config.file, config.fileName || config.file.name);
128
+ }
129
+ }
130
+ return formData;
131
+ };
132
+
133
+ config.data = formData;
134
+
135
+ return sendHttp(config);
136
+ };
137
+
138
+ this.http = function(config) {
139
+ return sendHttp(config);
140
+ }
141
+ }]);
142
+
143
+ angularFileUpload.directive('ngFileSelect', [ '$parse', '$timeout', function($parse, $timeout) {
144
+ return function(scope, elem, attr) {
145
+ var fn = $parse(attr['ngFileSelect']);
146
+ if (elem[0].tagName.toLowerCase() !== 'input' || (elem.attr('type') && elem.attr('type').toLowerCase()) !== 'file') {
147
+ var fileElem = angular.element('<input type="file">')
148
+ for (var i = 0; i < elem[0].attributes.length; i++) {
149
+ fileElem.attr(elem[0].attributes[i].name, elem[0].attributes[i].value);
150
+ }
151
+ if (elem.attr("data-multiple")) fileElem.attr("multiple", "true");
152
+ fileElem.css("top", 0).css("bottom", 0).css("left", 0).css("right", 0).css("width", "100%").
153
+ css("opacity", 0).css("position", "absolute").css('filter', 'alpha(opacity=0)');
154
+ elem.append(fileElem);
155
+ if (elem.css("position") === '' || elem.css("position") === 'static') {
156
+ elem.css("position", "relative");
157
+ }
158
+ elem = fileElem;
159
+ }
160
+ elem.bind('change', function(evt) {
161
+ var files = [], fileList, i;
162
+ fileList = evt.__files_ || evt.target.files;
163
+ if (fileList != null) {
164
+ for (i = 0; i < fileList.length; i++) {
165
+ files.push(fileList.item(i));
166
+ }
167
+ }
168
+ $timeout(function() {
169
+ fn(scope, {
170
+ $files : files,
171
+ $event : evt
172
+ });
173
+ });
174
+ });
175
+ // removed this since it was confusing if the user click on browse and then cancel #181
176
+ // elem.bind('click', function(){
177
+ // this.value = null;
178
+ // });
179
+
180
+ // removed because of #253 bug
181
+ // touch screens
182
+ // if (('ontouchstart' in window) ||
183
+ // (navigator.maxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0)) {
184
+ // elem.bind('touchend', function(e) {
185
+ // e.preventDefault();
186
+ // e.target.click();
187
+ // });
188
+ // }
189
+ };
190
+ } ]);
191
+
192
+ angularFileUpload.directive('ngFileDropAvailable', [ '$parse', '$timeout', function($parse, $timeout) {
193
+ return function(scope, elem, attr) {
194
+ if ('draggable' in document.createElement('span')) {
195
+ var fn = $parse(attr['ngFileDropAvailable']);
196
+ $timeout(function() {
197
+ fn(scope);
198
+ });
199
+ }
200
+ };
201
+ } ]);
202
+
203
+ angularFileUpload.directive('ngFileDrop', [ '$parse', '$timeout', '$location', function($parse, $timeout, $location) {
204
+ return function(scope, elem, attr) {
205
+ if ('draggable' in document.createElement('span')) {
206
+ var leaveTimeout = null;
207
+ elem[0].addEventListener("dragover", function(evt) {
208
+ evt.stopPropagation();
209
+ evt.preventDefault();
210
+ $timeout.cancel(leaveTimeout);
211
+ if (!elem[0].__drag_over_class_) {
212
+ var dragOverClassFn = $parse(attr['ngFileDragOverClass']);
213
+ if (dragOverClassFn instanceof Function) {
214
+ var dragOverClass = dragOverClassFn(scope, {
215
+ $event : evt
216
+ });
217
+ elem[0].__drag_over_class_ = dragOverClass;
218
+ } else {
219
+ elem[0].__drag_over_class_ = attr['ngFileDragOverClass'] || "dragover";
220
+ }
221
+ }
222
+ elem.addClass(elem[0].__drag_over_class_);
223
+ }, false);
224
+ elem[0].addEventListener("dragenter", function(evt) {
225
+ evt.stopPropagation();
226
+ evt.preventDefault();
227
+ }, false);
228
+ elem[0].addEventListener("dragleave", function(evt) {
229
+ leaveTimeout = $timeout(function() {
230
+ elem.removeClass(elem[0].__drag_over_class_);
231
+ elem[0].__drag_over_class_ = null;
232
+ });
233
+ }, false);
234
+ var fn = $parse(attr['ngFileDrop']);
235
+ elem[0].addEventListener("drop", function(evt) {
236
+ evt.stopPropagation();
237
+ evt.preventDefault();
238
+ elem.removeClass(elem[0].__drag_over_class_);
239
+ elem[0].__drag_over_class_ = null;
240
+ extractFiles(evt, function(files) {
241
+ fn(scope, {
242
+ $files : files,
243
+ $event : evt
244
+ });
245
+ });
246
+ }, false);
247
+
248
+ function isASCII(str) {
249
+ return /^[\000-\177]*$/.test(str);
250
+ }
251
+
252
+ function extractFiles(evt, callback) {
253
+ var files = [], items = evt.dataTransfer.items;
254
+ if (items && items.length > 0 && items[0].webkitGetAsEntry && $location.protocol() != 'file' &&
255
+ items[0].webkitGetAsEntry().isDirectory) {
256
+ for (var i = 0; i < items.length; i++) {
257
+ var entry = items[i].webkitGetAsEntry();
258
+ if (entry != null) {
259
+ //fix for chrome bug https://code.google.com/p/chromium/issues/detail?id=149735
260
+ if (isASCII(entry.name)) {
261
+ traverseFileTree(files, entry);
262
+ } else {
263
+ files.push(items[i].getAsFile());
264
+ }
265
+ }
266
+ }
267
+ } else {
268
+ var fileList = evt.dataTransfer.files;
269
+ if (fileList != null) {
270
+ for (var i = 0; i < fileList.length; i++) {
271
+ files.push(fileList.item(i));
272
+ }
273
+ }
274
+ }
275
+ (function waitForProcess(delay) {
276
+ $timeout(function() {
277
+ if (!processing) {
278
+ callback(files);
279
+ } else {
280
+ waitForProcess(10);
281
+ }
282
+ }, delay || 0)
283
+ })();
284
+ }
285
+
286
+ var processing = 0;
287
+ function traverseFileTree(files, entry) {
288
+ if (entry != null) {
289
+ if (entry.isDirectory) {
290
+ var dirReader = entry.createReader();
291
+ processing++;
292
+ dirReader.readEntries(function(entries) {
293
+ for (var i = 0; i < entries.length; i++) {
294
+ traverseFileTree(files, entries[i]);
295
+ }
296
+ processing--;
297
+ });
298
+ } else {
299
+ processing++;
300
+ entry.file(function(file) {
301
+ processing--;
302
+ files.push(file);
303
+ });
304
+ }
305
+ }
306
+ }
307
+ }
308
+ };
309
+ } ]);
310
+
311
+ })();
@@ -0,0 +1,2 @@
1
+ require 'angular-file-upload/version'
2
+ require 'angular-file-upload/rails'
@@ -0,0 +1,6 @@
1
+ module AngularFileUpload
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module AngularFileUpload
2
+ VERSION = '1.6.1'
3
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: angular-file-upload-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.6.1
5
+ platform: ruby
6
+ authors:
7
+ - Joe DiVita
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ description: " Includes an AngularJS Directive for uploading files as an asset in
56
+ the Rails Asset Pipeline "
57
+ email:
58
+ - joediv31@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - angular-file-upload-rails.gemspec
69
+ - app/assets/javascripts/FileAPI.flash.swf
70
+ - app/assets/javascripts/FileAPI.min.js
71
+ - app/assets/javascripts/angular-file-upload-html5-shim.js
72
+ - app/assets/javascripts/angular-file-upload-shim.js
73
+ - app/assets/javascripts/angular-file-upload.js
74
+ - lib/angular-file-upload.rb
75
+ - lib/angular-file-upload/rails.rb
76
+ - lib/angular-file-upload/version.rb
77
+ homepage: https://github.com/joedivita/angular-file-upload-rails
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.1.11
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Includes an AngularJS Directive for uploading files as an asset in the Rails
101
+ Asset Pipeline
102
+ test_files: []