jquery.fileupload.js 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423
  1. !function(a){"use strict";var b=function(a,c,d){var e,f,g=document.createElement("img");if(g.onerror=c,g.onload=function(){!f||d&&d.noRevoke||b.revokeObjectURL(f),c&&c(b.scale(g,d))},b.isInstanceOf("Blob",a)||b.isInstanceOf("File",a))e=f=b.createObjectURL(a),g._type=a.type;else{if("string"!=typeof a)return!1;e=a,d&&d.crossOrigin&&(g.crossOrigin=d.crossOrigin)}return e?(g.src=e,g):b.readFile(a,function(a){var b=a.target;b&&b.result?g.src=b.result:c&&c(a)})},c=window.createObjectURL&&window||window.URL&&URL.revokeObjectURL&&URL||window.webkitURL&&webkitURL;b.isInstanceOf=function(a,b){return Object.prototype.toString.call(b)==="[object "+a+"]"},b.transformCoordinates=function(){},b.getTransformedOptions=function(a,b){var c,d,e,f,g=b.aspectRatio;if(!g)return b;c={};for(d in b)b.hasOwnProperty(d)&&(c[d]=b[d]);return c.crop=!0,e=a.naturalWidth||a.width,f=a.naturalHeight||a.height,e/f>g?(c.maxWidth=f*g,c.maxHeight=f):(c.maxWidth=e,c.maxHeight=e/g),c},b.renderImageToCanvas=function(a,b,c,d,e,f,g,h,i,j){return a.getContext("2d").drawImage(b,c,d,e,f,g,h,i,j),a},b.hasCanvasOption=function(a){return a.canvas||a.crop||a.aspectRatio},b.scale=function(a,c){c=c||{};var d,e,f,g,h,i,j,k,l,m=document.createElement("canvas"),n=a.getContext||b.hasCanvasOption(c)&&m.getContext,o=a.naturalWidth||a.width,p=a.naturalHeight||a.height,q=o,r=p,s=function(){var a=Math.max((f||q)/q,(g||r)/r);a>1&&(q*=a,r*=a)},t=function(){var a=Math.min((d||q)/q,(e||r)/r);1>a&&(q*=a,r*=a)};return n&&(c=b.getTransformedOptions(a,c),j=c.left||0,k=c.top||0,c.sourceWidth?(h=c.sourceWidth,void 0!==c.right&&void 0===c.left&&(j=o-h-c.right)):h=o-j-(c.right||0),c.sourceHeight?(i=c.sourceHeight,void 0!==c.bottom&&void 0===c.top&&(k=p-i-c.bottom)):i=p-k-(c.bottom||0),q=h,r=i),d=c.maxWidth,e=c.maxHeight,f=c.minWidth,g=c.minHeight,n&&d&&e&&c.crop?(q=d,r=e,l=h/i-d/e,0>l?(i=e*h/d,void 0===c.top&&void 0===c.bottom&&(k=(p-i)/2)):l>0&&(h=d*i/e,void 0===c.left&&void 0===c.right&&(j=(o-h)/2))):((c.contain||c.cover)&&(f=d=d||f,g=e=e||g),c.cover?(t(),s()):(s(),t())),n?(m.width=q,m.height=r,b.transformCoordinates(m,c),b.renderImageToCanvas(m,a,j,k,h,i,0,0,q,r)):(a.width=q,a.height=r,a)},b.createObjectURL=function(a){return c?c.createObjectURL(a):!1},b.revokeObjectURL=function(a){return c?c.revokeObjectURL(a):!1},b.readFile=function(a,b,c){if(window.FileReader){var d=new FileReader;if(d.onload=d.onerror=b,c=c||"readAsDataURL",d[c])return d[c](a),d}return!1},"function"==typeof define&&define.amd?define(function(){return b}):a.loadImage=b}(window),function(a){"use strict";"function"==typeof define&&define.amd?define(["load-image"],a):a(window.loadImage)}(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){"use strict";"function"==typeof define&&define.amd?define(["load-image"],a):a(window.loadImage)}(function(a){"use strict";var b=a.hasCanvasOption,c=a.transformCoordinates,d=a.getTransformedOptions;a.hasCanvasOption=function(c){return b.call(a,c)||c.orientation},a.transformCoordinates=function(b,d){c.call(a,b,d);var e=b.getContext("2d"),f=b.width,g=b.height,h=d.orientation;if(h&&!(h>8))switch(h>4&&(b.width=g,b.height=f),h){case 2:e.translate(f,0),e.scale(-1,1);break;case 3:e.translate(f,g),e.rotate(Math.PI);break;case 4:e.translate(0,g),e.scale(1,-1);break;case 5:e.rotate(.5*Math.PI),e.scale(1,-1);break;case 6:e.rotate(.5*Math.PI),e.translate(0,-g);break;case 7:e.rotate(.5*Math.PI),e.translate(f,-g),e.scale(-1,1);break;case 8:e.rotate(-.5*Math.PI),e.translate(-f,0)}},a.getTransformedOptions=function(b,c){var e,f,g=d.call(a,b,c),h=g.orientation;if(!h||h>8||1===h)return g;e={};for(f in g)g.hasOwnProperty(f)&&(e[f]=g[f]);switch(g.orientation){case 2:e.left=g.right,e.right=g.left;break;case 3:e.left=g.right,e.top=g.bottom,e.right=g.left,e.bottom=g.top;break;case 4:e.top=g.bottom,e.bottom=g.top;break;case 5:e.left=g.top,e.top=g.left,e.right=g.bottom,e.bottom=g.right;break;case 6:e.left=g.top,e.top=g.right,e.right=g.bottom,e.bottom=g.left;break;case 7:e.left=g.bottom,e.top=g.right,e.right=g.top,e.bottom=g.left;break;case 8:e.left=g.bottom,e.top=g.left,e.right=g.top,e.bottom=g.right}return g.orientation>4&&(e.maxWidth=g.maxHeight,e.maxHeight=g.maxWidth,e.minWidth=g.minHeight,e.minHeight=g.minWidth,e.sourceWidth=g.sourceHeight,e.sourceHeight=g.sourceWidth),e}}),function(a){"use strict";"function"==typeof define&&define.amd?define(["load-image"],a):a(window.loadImage)}(function(a){"use strict";var b=window.Blob&&(Blob.prototype.slice||Blob.prototype.webkitSlice||Blob.prototype.mozSlice);a.blobSlice=b&&function(){var a=this.slice||this.webkitSlice||this.mozSlice;return a.apply(this,arguments)},a.metaDataParsers={jpeg:{65505:[]}},a.parseMetaData=function(b,c,d){d=d||{};var e=this,f=d.maxMetaDataSize||262144,g={},h=!(window.DataView&&b&&b.size>=12&&"image/jpeg"===b.type&&a.blobSlice);(h||!a.readFile(a.blobSlice.call(b,0,f),function(b){if(b.target.error)return console.log(b.target.error),void c(g);var f,h,i,j,k=b.target.result,l=new DataView(k),m=2,n=l.byteLength-4,o=m;if(65496===l.getUint16(0)){for(;n>m&&(f=l.getUint16(m),f>=65504&&65519>=f||65534===f);){if(h=l.getUint16(m+2)+2,m+h>l.byteLength){console.log("Invalid meta data: Invalid segment size.");break}if(i=a.metaDataParsers.jpeg[f])for(j=0;j<i.length;j+=1)i[j].call(e,l,m,h,g,d);m+=h,o=m}!d.disableImageHead&&o>6&&(g.imageHead=k.slice?k.slice(0,o):new Uint8Array(k).subarray(0,o))}else console.log("Invalid JPEG file: Missing JPEG marker.");c(g)},"readAsArrayBuffer"))&&c(g)}}),function(a){"use strict";"function"==typeof define&&define.amd?define(["load-image","load-image-meta"],a):a(window.loadImage)}(function(a){"use strict";a.ExifMap=function(){return this},a.ExifMap.prototype.map={Orientation:274},a.ExifMap.prototype.get=function(a){return this[a]||this[this.map[a]]},a.getExifThumbnail=function(a,b,c){var d,e,f;if(!c||b+c>a.byteLength)return void console.log("Invalid Exif data: Invalid thumbnail data.");for(d=[],e=0;c>e;e+=1)f=a.getUint8(b+e),d.push((16>f?"0":"")+f.toString(16));return"data:image/jpeg,%"+d.join("%")},a.exifTagTypes={1:{getValue:function(a,b){return a.getUint8(b)},size:1},2:{getValue:function(a,b){return String.fromCharCode(a.getUint8(b))},size:1,ascii:!0},3:{getValue:function(a,b,c){return a.getUint16(b,c)},size:2},4:{getValue:function(a,b,c){return a.getUint32(b,c)},size:4},5:{getValue:function(a,b,c){return a.getUint32(b,c)/a.getUint32(b+4,c)},size:8},9:{getValue:function(a,b,c){return a.getInt32(b,c)},size:4},10:{getValue:function(a,b,c){return a.getInt32(b,c)/a.getInt32(b+4,c)},size:8}},a.exifTagTypes[7]=a.exifTagTypes[1],a.getExifValue=function(b,c,d,e,f,g){var h,i,j,k,l,m,n=a.exifTagTypes[e];if(!n)return void console.log("Invalid Exif data: Invalid tag type.");if(h=n.size*f,i=h>4?c+b.getUint32(d+8,g):d+8,i+h>b.byteLength)return void console.log("Invalid Exif data: Invalid data offset.");if(1===f)return n.getValue(b,i,g);for(j=[],k=0;f>k;k+=1)j[k]=n.getValue(b,i+k*n.size,g);if(n.ascii){for(l="",k=0;k<j.length&&(m=j[k],"\x00"!==m);k+=1)l+=m;return l}return j},a.parseExifTag=function(b,c,d,e,f){var g=b.getUint16(d,e);f.exif[g]=a.getExifValue(b,c,d,b.getUint16(d+2,e),b.getUint32(d+4,e),e)},a.parseExifTags=function(a,b,c,d,e){var f,g,h;if(c+6>a.byteLength)return void console.log("Invalid Exif data: Invalid directory offset.");if(f=a.getUint16(c,d),g=c+2+12*f,g+4>a.byteLength)return void console.log("Invalid Exif data: Invalid directory size.");for(h=0;f>h;h+=1)this.parseExifTag(a,b,c+2+12*h,d,e);return a.getUint32(g,d)},a.parseExifData=function(b,c,d,e,f){if(!f.disableExif){var g,h,i,j=c+10;if(1165519206===b.getUint32(c+4)){if(j+8>b.byteLength)return void console.log("Invalid Exif data: Invalid segment size.");if(0!==b.getUint16(c+8))return void console.log("Invalid Exif data: Missing byte alignment offset.");switch(b.getUint16(j)){case 18761:g=!0;break;case 19789:g=!1;break;default:return void console.log("Invalid Exif data: Invalid byte alignment marker.")}if(42!==b.getUint16(j+2,g))return void console.log("Invalid Exif data: Missing TIFF marker.");h=b.getUint32(j+4,g),e.exif=new a.ExifMap,h=a.parseExifTags(b,j,j+h,g,e),h&&!f.disableExifThumbnail&&(i={exif:{}},h=a.parseExifTags(b,j,j+h,g,i),i.exif[513]&&(e.exif.Thumbnail=a.getExifThumbnail(b,j+i.exif[513],i.exif[514]))),e.exif[34665]&&!f.disableExifSub&&a.parseExifTags(b,j,j+e.exif[34665],g,e),e.exif[34853]&&!f.disableExifGps&&a.parseExifTags(b,j,j+e.exif[34853],g,e)}}},a.metaDataParsers.jpeg[65505].push(a.parseExifData)}),function(a){"use strict";"function"==typeof define&&define.amd?define(["load-image","load-image-exif"],a):a(window.loadImage)}(function(a){"use strict";a.ExifMap.prototype.tags={256:"ImageWidth",257:"ImageHeight",34665:"ExifIFDPointer",34853:"GPSInfoIFDPointer",40965:"InteroperabilityIFDPointer",258:"BitsPerSample",259:"Compression",262:"PhotometricInterpretation",274:"Orientation",277:"SamplesPerPixel",284:"PlanarConfiguration",530:"YCbCrSubSampling",531:"YCbCrPositioning",282:"XResolution",283:"YResolution",296:"ResolutionUnit",273:"StripOffsets",278:"RowsPerStrip",279:"StripByteCounts",513:"JPEGInterchangeFormat",514:"JPEGInterchangeFormatLength",301:"TransferFunction",318:"WhitePoint",319:"PrimaryChromaticities",529:"YCbCrCoefficients",532:"ReferenceBlackWhite",306:"DateTime",270:"ImageDescription",271:"Make",272:"Model",305:"Software",315:"Artist",33432:"Copyright",36864:"ExifVersion",40960:"FlashpixVersion",40961:"ColorSpace",40962:"PixelXDimension",40963:"PixelYDimension",42240:"Gamma",37121:"ComponentsConfiguration",37122:"CompressedBitsPerPixel",37500:"MakerNote",37510:"UserComment",40964:"RelatedSoundFile",36867:"DateTimeOriginal",36868:"DateTimeDigitized",37520:"SubSecTime",37521:"SubSecTimeOriginal",37522:"SubSecTimeDigitized",33434:"ExposureTime",33437:"FNumber",34850:"ExposureProgram",34852:"SpectralSensitivity",34855:"PhotographicSensitivity",34856:"OECF",34864:"SensitivityType",34865:"StandardOutputSensitivity",34866:"RecommendedExposureIndex",34867:"ISOSpeed",34868:"ISOSpeedLatitudeyyy",34869:"ISOSpeedLatitudezzz",37377:"ShutterSpeedValue",37378:"ApertureValue",37379:"BrightnessValue",37380:"ExposureBias",37381:"MaxApertureValue",37382:"SubjectDistance",37383:"MeteringMode",37384:"LightSource",37385:"Flash",37396:"SubjectArea",37386:"FocalLength",41483:"FlashEnergy",41484:"SpatialFrequencyResponse",41486:"FocalPlaneXResolution",41487:"FocalPlaneYResolution",41488:"FocalPlaneResolutionUnit",41492:"SubjectLocation",41493:"ExposureIndex",41495:"SensingMethod",41728:"FileSource",41729:"SceneType",41730:"CFAPattern",41985:"CustomRendered",41986:"ExposureMode",41987:"WhiteBalance",41988:"DigitalZoomRatio",41989:"FocalLengthIn35mmFilm",41990:"SceneCaptureType",41991:"GainControl",41992:"Contrast",41993:"Saturation",41994:"Sharpness",41995:"DeviceSettingDescription",41996:"SubjectDistanceRange",42016:"ImageUniqueID",42032:"CameraOwnerName",42033:"BodySerialNumber",42034:"LensSpecification",42035:"LensMake",42036:"LensModel",42037:"LensSerialNumber",0:"GPSVersionID",1:"GPSLatitudeRef",2:"GPSLatitude",3:"GPSLongitudeRef",4:"GPSLongitude",5:"GPSAltitudeRef",6:"GPSAltitude",7:"GPSTimeStamp",8:"GPSSatellites",9:"GPSStatus",10:"GPSMeasureMode",11:"GPSDOP",12:"GPSSpeedRef",13:"GPSSpeed",14:"GPSTrackRef",15:"GPSTrack",16:"GPSImgDirectionRef",17:"GPSImgDirection",18:"GPSMapDatum",19:"GPSDestLatitudeRef",20:"GPSDestLatitude",21:"GPSDestLongitudeRef",22:"GPSDestLongitude",23:"GPSDestBearingRef",24:"GPSDestBearing",25:"GPSDestDistanceRef",26:"GPSDestDistance",27:"GPSProcessingMethod",28:"GPSAreaInformation",29:"GPSDateStamp",30:"GPSDifferential",31:"GPSHPositioningError"},a.ExifMap.prototype.stringValues={ExposureProgram:{0:"Undefined",1:"Manual",2:"Normal program",3:"Aperture priority",4:"Shutter priority",5:"Creative program",6:"Action program",7:"Portrait mode",8:"Landscape mode"},MeteringMode:{0:"Unknown",1:"Average",2:"CenterWeightedAverage",3:"Spot",4:"MultiSpot",5:"Pattern",6:"Partial",255:"Other"},LightSource:{0:"Unknown",1:"Daylight",2:"Fluorescent",3:"Tungsten (incandescent light)",4:"Flash",9:"Fine weather",10:"Cloudy weather",11:"Shade",12:"Daylight fluorescent (D 5700 - 7100K)",13:"Day white fluorescent (N 4600 - 5400K)",14:"Cool white fluorescent (W 3900 - 4500K)",15:"White fluorescent (WW 3200 - 3700K)",17:"Standard light A",18:"Standard light B",19:"Standard light C",20:"D55",21:"D65",22:"D75",23:"D50",24:"ISO studio tungsten",255:"Other"},Flash:{0:"Flash did not fire",1:"Flash fired",5:"Strobe return light not detected",7:"Strobe return light detected",9:"Flash fired, compulsory flash mode",13:"Flash fired, compulsory flash mode, return light not detected",15:"Flash fired, compulsory flash mode, return light detected",16:"Flash did not fire, compulsory flash mode",24:"Flash did not fire, auto mode",25:"Flash fired, auto mode",29:"Flash fired, auto mode, return light not detected",31:"Flash fired, auto mode, return light detected",32:"No flash function",65:"Flash fired, red-eye reduction mode",69:"Flash fired, red-eye reduction mode, return light not detected",71:"Flash fired, red-eye reduction mode, return light detected",73:"Flash fired, compulsory flash mode, red-eye reduction mode",77:"Flash fired, compulsory flash mode, red-eye reduction mode, return light not detected",79:"Flash fired, compulsory flash mode, red-eye reduction mode, return light detected",89:"Flash fired, auto mode, red-eye reduction mode",93:"Flash fired, auto mode, return light not detected, red-eye reduction mode",95:"Flash fired, auto mode, return light detected, red-eye reduction mode"},SensingMethod:{1:"Undefined",2:"One-chip color area sensor",3:"Two-chip color area sensor",4:"Three-chip color area sensor",5:"Color sequential area sensor",7:"Trilinear sensor",8:"Color sequential linear sensor"},SceneCaptureType:{0:"Standard",1:"Landscape",2:"Portrait",3:"Night scene"},SceneType:{1:"Directly photographed"},CustomRendered:{0:"Normal process",1:"Custom process"},WhiteBalance:{0:"Auto white balance",1:"Manual white balance"},GainControl:{0:"None",1:"Low gain up",2:"High gain up",3:"Low gain down",4:"High gain down"},Contrast:{0:"Normal",1:"Soft",2:"Hard"},Saturation:{0:"Normal",1:"Low saturation",2:"High saturation"},Sharpness:{0:"Normal",1:"Soft",2:"Hard"},SubjectDistanceRange:{0:"Unknown",1:"Macro",2:"Close view",3:"Distant view"},FileSource:{3:"DSC"},ComponentsConfiguration:{0:"",1:"Y",2:"Cb",3:"Cr",4:"R",5:"G",6:"B"},Orientation:{1:"top-left",2:"top-right",3:"bottom-right",4:"bottom-left",5:"left-top",6:"right-top",7:"right-bottom",8:"left-bottom"}},a.ExifMap.prototype.getText=function(a){var b=this.get(a);switch(a){case"LightSource":case"Flash":case"MeteringMode":case"ExposureProgram":case"SensingMethod":case"SceneCaptureType":case"SceneType":case"CustomRendered":case"WhiteBalance":case"GainControl":case"Contrast":case"Saturation":case"Sharpness":case"SubjectDistanceRange":case"FileSource":case"Orientation":return this.stringValues[a][b];case"ExifVersion":case"FlashpixVersion":return String.fromCharCode(b[0],b[1],b[2],b[3]);case"ComponentsConfiguration":return this.stringValues[a][b[0]]+this.stringValues[a][b[1]]+this.stringValues[a][b[2]]+this.stringValues[a][b[3]];case"GPSVersionID":return b[0]+"."+b[1]+"."+b[2]+"."+b[3]}return String(b)},function(a){var b,c=a.tags,d=a.map;for(b in c)c.hasOwnProperty(b)&&(d[c[b]]=b)}(a.ExifMap.prototype),a.ExifMap.prototype.getAll=function(){var a,b,c={};for(a in this)this.hasOwnProperty(a)&&(b=this.tags[a],b&&(c[b]=this.getText(b)));return c}});
  2. /*
  3. * jquery.ui.widget
  4. */
  5. ;(function( factory ) {
  6. if ( typeof define === "function" && define.amd ) {
  7. define([ "jquery" ], factory );
  8. } else if ( typeof exports === "object" ) {
  9. factory( require( "jquery" ) );
  10. } else {
  11. factory( jQuery );
  12. }
  13. }(function( $ ) {
  14. var widget_uuid = 0,
  15. widget_slice = Array.prototype.slice;
  16. $.cleanData = (function( orig ) {
  17. return function( elems ) {
  18. var events, elem, i;
  19. for ( i = 0; (elem = elems[i]) != null; i++ ) {
  20. try {
  21. events = $._data( elem, "events" );
  22. if ( events && events.remove ) {
  23. $( elem ).triggerHandler( "remove" );
  24. }
  25. } catch ( e ) {}
  26. }
  27. orig( elems );
  28. };
  29. })( $.cleanData );
  30. $.widget = function( name, base, prototype ) {
  31. var fullName, existingConstructor, constructor, basePrototype,
  32. proxiedPrototype = {},
  33. namespace = name.split( "." )[ 0 ];
  34. name = name.split( "." )[ 1 ];
  35. fullName = namespace + "-" + name;
  36. if ( !prototype ) {
  37. prototype = base;
  38. base = $.Widget;
  39. }
  40. $.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) {
  41. return !!$.data( elem, fullName );
  42. };
  43. $[ namespace ] = $[ namespace ] || {};
  44. existingConstructor = $[ namespace ][ name ];
  45. constructor = $[ namespace ][ name ] = function( options, element ) {
  46. if ( !this._createWidget ) {
  47. return new constructor( options, element );
  48. }
  49. if ( arguments.length ) {
  50. this._createWidget( options, element );
  51. }
  52. };
  53. $.extend( constructor, existingConstructor, {
  54. version: prototype.version,
  55. _proto: $.extend( {}, prototype ),
  56. _childConstructors: []
  57. });
  58. basePrototype = new base();
  59. basePrototype.options = $.widget.extend( {}, basePrototype.options );
  60. $.each( prototype, function( prop, value ) {
  61. if ( !$.isFunction( value ) ) {
  62. proxiedPrototype[ prop ] = value;
  63. return;
  64. }
  65. proxiedPrototype[ prop ] = (function() {
  66. var _super = function() {
  67. return base.prototype[ prop ].apply( this, arguments );
  68. },
  69. _superApply = function( args ) {
  70. return base.prototype[ prop ].apply( this, args );
  71. };
  72. return function() {
  73. var __super = this._super,
  74. __superApply = this._superApply,
  75. returnValue;
  76. this._super = _super;
  77. this._superApply = _superApply;
  78. returnValue = value.apply( this, arguments );
  79. this._super = __super;
  80. this._superApply = __superApply;
  81. return returnValue;
  82. };
  83. })();
  84. });
  85. constructor.prototype = $.widget.extend( basePrototype, {
  86. widgetEventPrefix: existingConstructor ? (basePrototype.widgetEventPrefix || name) : name
  87. }, proxiedPrototype, {
  88. constructor: constructor,
  89. namespace: namespace,
  90. widgetName: name,
  91. widgetFullName: fullName
  92. });
  93. if ( existingConstructor ) {
  94. $.each( existingConstructor._childConstructors, function( i, child ) {
  95. var childPrototype = child.prototype;
  96. $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto );
  97. });
  98. delete existingConstructor._childConstructors;
  99. } else {
  100. base._childConstructors.push( constructor );
  101. }
  102. $.widget.bridge( name, constructor );
  103. return constructor;
  104. };
  105. $.widget.extend = function( target ) {
  106. var input = widget_slice.call( arguments, 1 ),
  107. inputIndex = 0,
  108. inputLength = input.length,
  109. key,
  110. value;
  111. for ( ; inputIndex < inputLength; inputIndex++ ) {
  112. for ( key in input[ inputIndex ] ) {
  113. value = input[ inputIndex ][ key ];
  114. if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
  115. if ( $.isPlainObject( value ) ) {
  116. target[ key ] = $.isPlainObject( target[ key ] ) ?
  117. $.widget.extend( {}, target[ key ], value ) :
  118. $.widget.extend( {}, value );
  119. } else {
  120. target[ key ] = value;
  121. }
  122. }
  123. }
  124. }
  125. return target;
  126. };
  127. $.widget.bridge = function( name, object ) {
  128. var fullName = object.prototype.widgetFullName || name;
  129. $.fn[ name ] = function( options ) {
  130. var isMethodCall = typeof options === "string",
  131. args = widget_slice.call( arguments, 1 ),
  132. returnValue = this;
  133. if ( isMethodCall ) {
  134. this.each(function() {
  135. var methodValue,
  136. instance = $.data( this, fullName );
  137. if ( options === "instance" ) {
  138. returnValue = instance;
  139. return false;
  140. }
  141. if ( !instance ) {
  142. return $.error( "cannot call methods on " + name + " prior to initialization; " +
  143. "attempted to call method '" + options + "'" );
  144. }
  145. if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
  146. return $.error( "no such method '" + options + "' for " + name + " widget instance" );
  147. }
  148. methodValue = instance[ options ].apply( instance, args );
  149. if ( methodValue !== instance && methodValue !== undefined ) {
  150. returnValue = methodValue && methodValue.jquery ?
  151. returnValue.pushStack( methodValue.get() ) :
  152. methodValue;
  153. return false;
  154. }
  155. });
  156. } else {
  157. if ( args.length ) {
  158. options = $.widget.extend.apply( null, [ options ].concat(args) );
  159. }
  160. this.each(function() {
  161. var instance = $.data( this, fullName );
  162. if ( instance ) {
  163. instance.option( options || {} );
  164. if ( instance._init ) {
  165. instance._init();
  166. }
  167. } else {
  168. $.data( this, fullName, new object( options, this ) );
  169. }
  170. });
  171. }
  172. return returnValue;
  173. };
  174. };
  175. $.Widget = function( /* options, element */ ) {};
  176. $.Widget._childConstructors = [];
  177. $.Widget.prototype = {
  178. widgetName: "widget",
  179. widgetEventPrefix: "",
  180. defaultElement: "<div>",
  181. options: {
  182. disabled: false,
  183. create: null
  184. },
  185. _createWidget: function( options, element ) {
  186. element = $( element || this.defaultElement || this )[ 0 ];
  187. this.element = $( element );
  188. this.uuid = widget_uuid++;
  189. this.eventNamespace = "." + this.widgetName + this.uuid;
  190. this.bindings = $();
  191. this.hoverable = $();
  192. this.focusable = $();
  193. if ( element !== this ) {
  194. $.data( element, this.widgetFullName, this );
  195. this._on( true, this.element, {
  196. remove: function( event ) {
  197. if ( event.target === element ) {
  198. this.destroy();
  199. }
  200. }
  201. });
  202. this.document = $( element.style ?
  203. element.ownerDocument :
  204. element.document || element );
  205. this.window = $( this.document[0].defaultView || this.document[0].parentWindow );
  206. }
  207. this.options = $.widget.extend( {},
  208. this.options,
  209. this._getCreateOptions(),
  210. options );
  211. this._create();
  212. this._trigger( "create", null, this._getCreateEventData() );
  213. this._init();
  214. },
  215. _getCreateOptions: $.noop,
  216. _getCreateEventData: $.noop,
  217. _create: $.noop,
  218. _init: $.noop,
  219. destroy: function() {
  220. this._destroy();
  221. this.element
  222. .unbind( this.eventNamespace )
  223. .removeData( this.widgetFullName )
  224. .removeData( $.camelCase( this.widgetFullName ) );
  225. this.widget()
  226. .unbind( this.eventNamespace )
  227. .removeAttr( "aria-disabled" )
  228. .removeClass(
  229. this.widgetFullName + "-disabled " +
  230. "ui-state-disabled" );
  231. this.bindings.unbind( this.eventNamespace );
  232. this.hoverable.removeClass( "ui-state-hover" );
  233. this.focusable.removeClass( "ui-state-focus" );
  234. },
  235. _destroy: $.noop,
  236. widget: function() {
  237. return this.element;
  238. },
  239. option: function( key, value ) {
  240. var options = key,
  241. parts,
  242. curOption,
  243. i;
  244. if ( arguments.length === 0 ) {
  245. return $.widget.extend( {}, this.options );
  246. }
  247. if ( typeof key === "string" ) {
  248. options = {};
  249. parts = key.split( "." );
  250. key = parts.shift();
  251. if ( parts.length ) {
  252. curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
  253. for ( i = 0; i < parts.length - 1; i++ ) {
  254. curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
  255. curOption = curOption[ parts[ i ] ];
  256. }
  257. key = parts.pop();
  258. if ( arguments.length === 1 ) {
  259. return curOption[ key ] === undefined ? null : curOption[ key ];
  260. }
  261. curOption[ key ] = value;
  262. } else {
  263. if ( arguments.length === 1 ) {
  264. return this.options[ key ] === undefined ? null : this.options[ key ];
  265. }
  266. options[ key ] = value;
  267. }
  268. }
  269. this._setOptions( options );
  270. return this;
  271. },
  272. _setOptions: function( options ) {
  273. var key;
  274. for ( key in options ) {
  275. this._setOption( key, options[ key ] );
  276. }
  277. return this;
  278. },
  279. _setOption: function( key, value ) {
  280. this.options[ key ] = value;
  281. if ( key === "disabled" ) {
  282. this.widget()
  283. .toggleClass( this.widgetFullName + "-disabled", !!value );
  284. if ( value ) {
  285. this.hoverable.removeClass( "ui-state-hover" );
  286. this.focusable.removeClass( "ui-state-focus" );
  287. }
  288. }
  289. return this;
  290. },
  291. enable: function() {
  292. return this._setOptions({ disabled: false });
  293. },
  294. disable: function() {
  295. return this._setOptions({ disabled: true });
  296. },
  297. _on: function( suppressDisabledCheck, element, handlers ) {
  298. var delegateElement,
  299. instance = this;
  300. if ( typeof suppressDisabledCheck !== "boolean" ) {
  301. handlers = element;
  302. element = suppressDisabledCheck;
  303. suppressDisabledCheck = false;
  304. }
  305. if ( !handlers ) {
  306. handlers = element;
  307. element = this.element;
  308. delegateElement = this.widget();
  309. } else {
  310. element = delegateElement = $( element );
  311. this.bindings = this.bindings.add( element );
  312. }
  313. $.each( handlers, function( event, handler ) {
  314. function handlerProxy() {
  315. if ( !suppressDisabledCheck &&
  316. ( instance.options.disabled === true ||
  317. $( this ).hasClass( "ui-state-disabled" ) ) ) {
  318. return;
  319. }
  320. return ( typeof handler === "string" ? instance[ handler ] : handler )
  321. .apply( instance, arguments );
  322. }
  323. if ( typeof handler !== "string" ) {
  324. handlerProxy.guid = handler.guid =
  325. handler.guid || handlerProxy.guid || $.guid++;
  326. }
  327. var match = event.match( /^([\w:-]*)\s*(.*)$/ ),
  328. eventName = match[1] + instance.eventNamespace,
  329. selector = match[2];
  330. if ( selector ) {
  331. delegateElement.delegate( selector, eventName, handlerProxy );
  332. } else {
  333. element.bind( eventName, handlerProxy );
  334. }
  335. });
  336. },
  337. _off: function( element, eventName ) {
  338. eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) +
  339. this.eventNamespace;
  340. element.unbind( eventName ).undelegate( eventName );
  341. this.bindings = $( this.bindings.not( element ).get() );
  342. this.focusable = $( this.focusable.not( element ).get() );
  343. this.hoverable = $( this.hoverable.not( element ).get() );
  344. },
  345. _delay: function( handler, delay ) {
  346. function handlerProxy() {
  347. return ( typeof handler === "string" ? instance[ handler ] : handler )
  348. .apply( instance, arguments );
  349. }
  350. var instance = this;
  351. return setTimeout( handlerProxy, delay || 0 );
  352. },
  353. _hoverable: function( element ) {
  354. this.hoverable = this.hoverable.add( element );
  355. this._on( element, {
  356. mouseenter: function( event ) {
  357. $( event.currentTarget ).addClass( "ui-state-hover" );
  358. },
  359. mouseleave: function( event ) {
  360. $( event.currentTarget ).removeClass( "ui-state-hover" );
  361. }
  362. });
  363. },
  364. _focusable: function( element ) {
  365. this.focusable = this.focusable.add( element );
  366. this._on( element, {
  367. focusin: function( event ) {
  368. $( event.currentTarget ).addClass( "ui-state-focus" );
  369. },
  370. focusout: function( event ) {
  371. $( event.currentTarget ).removeClass( "ui-state-focus" );
  372. }
  373. });
  374. },
  375. _trigger: function( type, event, data ) {
  376. var prop, orig,
  377. callback = this.options[ type ];
  378. data = data || {};
  379. event = $.Event( event );
  380. event.type = ( type === this.widgetEventPrefix ?
  381. type :
  382. this.widgetEventPrefix + type ).toLowerCase();
  383. event.target = this.element[ 0 ];
  384. orig = event.originalEvent;
  385. if ( orig ) {
  386. for ( prop in orig ) {
  387. if ( !( prop in event ) ) {
  388. event[ prop ] = orig[ prop ];
  389. }
  390. }
  391. }
  392. this.element.trigger( event, data );
  393. return !( $.isFunction( callback ) &&
  394. callback.apply( this.element[0], [ event ].concat( data ) ) === false ||
  395. event.isDefaultPrevented() );
  396. }
  397. };
  398. $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
  399. $.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
  400. if ( typeof options === "string" ) {
  401. options = { effect: options };
  402. }
  403. var hasOptions,
  404. effectName = !options ?
  405. method :
  406. options === true || typeof options === "number" ?
  407. defaultEffect :
  408. options.effect || defaultEffect;
  409. options = options || {};
  410. if ( typeof options === "number" ) {
  411. options = { duration: options };
  412. }
  413. hasOptions = !$.isEmptyObject( options );
  414. options.complete = callback;
  415. if ( options.delay ) {
  416. element.delay( options.delay );
  417. }
  418. if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) {
  419. element[ method ]( options );
  420. } else if ( effectName !== method && element[ effectName ] ) {
  421. element[ effectName ]( options.duration, options.easing, callback );
  422. } else {
  423. element.queue(function( next ) {
  424. $( this )[ method ]();
  425. if ( callback ) {
  426. callback.call( element[ 0 ] );
  427. }
  428. next();
  429. });
  430. }
  431. };
  432. });
  433. var widget = $.widget;
  434. }));
  435. /*
  436. * jquery.fileupload.js
  437. */
  438. (function (factory) {
  439. 'use strict';
  440. if (typeof define === 'function' && define.amd) {
  441. define([
  442. 'jquery',
  443. 'jquery.ui.widget'
  444. ], factory);
  445. } else if (typeof exports === 'object') {
  446. factory(
  447. require('jquery'),
  448. require('jquery.ui.widget')
  449. );
  450. } else {
  451. factory(window.jQuery);
  452. }
  453. }(function ($) {
  454. 'use strict';
  455. $.support.fileInput = !(new RegExp(
  456. '(Android (1\\.[0156]|2\\.[01]))' +
  457. '|(Windows Phone (OS 7|8\\.0))|(XBLWP)|(ZuneWP)|(WPDesktop)' +
  458. '|(w(eb)?OSBrowser)|(webOS)' +
  459. '|(Kindle/(1\\.0|2\\.[05]|3\\.0))'
  460. ).test(window.navigator.userAgent) ||
  461. $('<input type="file">').prop('disabled'));
  462. $.support.xhrFileUpload = !!(window.ProgressEvent && window.FileReader);
  463. $.support.xhrFormDataFileUpload = !!window.FormData;
  464. $.support.blobSlice = window.Blob && (Blob.prototype.slice ||
  465. Blob.prototype.webkitSlice || Blob.prototype.mozSlice);
  466. function getDragHandler(type) {
  467. var isDragOver = type === 'dragover';
  468. return function (e) {
  469. e.dataTransfer = e.originalEvent && e.originalEvent.dataTransfer;
  470. var dataTransfer = e.dataTransfer;
  471. if (dataTransfer && $.inArray('Files', dataTransfer.types) !== -1 &&
  472. this._trigger(
  473. type,
  474. $.Event(type, {delegatedEvent: e})
  475. ) !== false) {
  476. e.preventDefault();
  477. if (isDragOver) {
  478. dataTransfer.dropEffect = 'copy';
  479. }
  480. }
  481. };
  482. }
  483. $.widget('blueimp.fileupload', {
  484. options: {
  485. dropZone: $(document),
  486. pasteZone: undefined,
  487. fileInput: undefined,
  488. replaceFileInput: true,
  489. paramName: undefined,
  490. singleFileUploads: true,
  491. limitMultiFileUploads: undefined,
  492. limitMultiFileUploadSize: undefined,
  493. limitMultiFileUploadSizeOverhead: 512,
  494. sequentialUploads: false,
  495. limitConcurrentUploads: undefined,
  496. forceIframeTransport: false,
  497. redirect: undefined,
  498. redirectParamName: undefined,
  499. postMessage: undefined,
  500. multipart: true,
  501. maxChunkSize: undefined,
  502. uploadedBytes: undefined,
  503. recalculateProgress: true,
  504. progressInterval: 100,
  505. bitrateInterval: 500,
  506. autoUpload: true,
  507. messages: {
  508. uploadedBytes: 'Uploaded bytes exceed file size'
  509. },
  510. i18n: function (message, context) {
  511. message = this.messages[message] || message.toString();
  512. if (context) {
  513. $.each(context, function (key, value) {
  514. message = message.replace('{' + key + '}', value);
  515. });
  516. }
  517. return message;
  518. },
  519. formData: function (form) {
  520. return form.serializeArray();
  521. },
  522. add: function (e, data) {
  523. if (e.isDefaultPrevented()) {
  524. return false;
  525. }
  526. if (data.autoUpload || (data.autoUpload !== false &&
  527. $(this).fileupload('option', 'autoUpload'))) {
  528. data.process().done(function () {
  529. data.submit();
  530. });
  531. }
  532. },
  533. processData: false,
  534. contentType: false,
  535. cache: false,
  536. timeout: 0
  537. },
  538. _specialOptions: [
  539. 'fileInput',
  540. 'dropZone',
  541. 'pasteZone',
  542. 'multipart',
  543. 'forceIframeTransport'
  544. ],
  545. _blobSlice: $.support.blobSlice && function () {
  546. var slice = this.slice || this.webkitSlice || this.mozSlice;
  547. return slice.apply(this, arguments);
  548. },
  549. _BitrateTimer: function () {
  550. this.timestamp = ((Date.now) ? Date.now() : (new Date()).getTime());
  551. this.loaded = 0;
  552. this.bitrate = 0;
  553. this.getBitrate = function (now, loaded, interval) {
  554. var timeDiff = now - this.timestamp;
  555. if (!this.bitrate || !interval || timeDiff > interval) {
  556. this.bitrate = (loaded - this.loaded) * (1000 / timeDiff) * 8;
  557. this.loaded = loaded;
  558. this.timestamp = now;
  559. }
  560. return this.bitrate;
  561. };
  562. },
  563. _isXHRUpload: function (options) {
  564. return !options.forceIframeTransport &&
  565. ((!options.multipart && $.support.xhrFileUpload) ||
  566. $.support.xhrFormDataFileUpload);
  567. },
  568. _getFormData: function (options) {
  569. var formData;
  570. if ($.type(options.formData) === 'function') {
  571. return options.formData(options.form);
  572. }
  573. if ($.isArray(options.formData)) {
  574. return options.formData;
  575. }
  576. if ($.type(options.formData) === 'object') {
  577. formData = [];
  578. $.each(options.formData, function (name, value) {
  579. formData.push({name: name, value: value});
  580. });
  581. return formData;
  582. }
  583. return [];
  584. },
  585. _getTotal: function (files) {
  586. var total = 0;
  587. $.each(files, function (index, file) {
  588. total += file.size || 1;
  589. });
  590. return total;
  591. },
  592. _initProgressObject: function (obj) {
  593. var progress = {
  594. loaded: 0,
  595. total: 0,
  596. bitrate: 0
  597. };
  598. if (obj._progress) {
  599. $.extend(obj._progress, progress);
  600. } else {
  601. obj._progress = progress;
  602. }
  603. },
  604. _initResponseObject: function (obj) {
  605. var prop;
  606. if (obj._response) {
  607. for (prop in obj._response) {
  608. if (obj._response.hasOwnProperty(prop)) {
  609. delete obj._response[prop];
  610. }
  611. }
  612. } else {
  613. obj._response = {};
  614. }
  615. },
  616. _onProgress: function (e, data) {
  617. if (e.lengthComputable) {
  618. var now = ((Date.now) ? Date.now() : (new Date()).getTime()),
  619. loaded;
  620. if (data._time && data.progressInterval &&
  621. (now - data._time < data.progressInterval) &&
  622. e.loaded !== e.total) {
  623. return;
  624. }
  625. data._time = now;
  626. loaded = Math.floor(
  627. e.loaded / e.total * (data.chunkSize || data._progress.total)
  628. ) + (data.uploadedBytes || 0);
  629. this._progress.loaded += (loaded - data._progress.loaded);
  630. this._progress.bitrate = this._bitrateTimer.getBitrate(
  631. now,
  632. this._progress.loaded,
  633. data.bitrateInterval
  634. );
  635. data._progress.loaded = data.loaded = loaded;
  636. data._progress.bitrate = data.bitrate = data._bitrateTimer.getBitrate(
  637. now,
  638. loaded,
  639. data.bitrateInterval
  640. );
  641. this._trigger(
  642. 'progress',
  643. $.Event('progress', {delegatedEvent: e}),
  644. data
  645. );
  646. this._trigger(
  647. 'progressall',
  648. $.Event('progressall', {delegatedEvent: e}),
  649. this._progress
  650. );
  651. }
  652. },
  653. _initProgressListener: function (options) {
  654. var that = this,
  655. xhr = options.xhr ? options.xhr() : $.ajaxSettings.xhr();
  656. if (xhr.upload) {
  657. $(xhr.upload).bind('progress', function (e) {
  658. var oe = e.originalEvent;
  659. e.lengthComputable = oe.lengthComputable;
  660. e.loaded = oe.loaded;
  661. e.total = oe.total;
  662. that._onProgress(e, options);
  663. });
  664. options.xhr = function () {
  665. return xhr;
  666. };
  667. }
  668. },
  669. _isInstanceOf: function (type, obj) {
  670. return Object.prototype.toString.call(obj) === '[object ' + type + ']';
  671. },
  672. _initXHRData: function (options) {
  673. var that = this,
  674. formData,
  675. file = options.files[0],
  676. multipart = options.multipart || !$.support.xhrFileUpload,
  677. paramName = $.type(options.paramName) === 'array' ?
  678. options.paramName[0] : options.paramName;
  679. options.headers = $.extend({}, options.headers);
  680. if (options.contentRange) {
  681. options.headers['Content-Range'] = options.contentRange;
  682. }
  683. if (!multipart || options.blob || !this._isInstanceOf('File', file)) {
  684. options.headers['Content-Disposition'] = 'attachment; filename="' +
  685. encodeURI(file.name) + '"';
  686. }
  687. if (!multipart) {
  688. options.contentType = file.type || 'application/octet-stream';
  689. options.data = options.blob || file;
  690. } else if ($.support.xhrFormDataFileUpload) {
  691. if (options.postMessage) {
  692. formData = this._getFormData(options);
  693. if (options.blob) {
  694. formData.push({
  695. name: paramName,
  696. value: options.blob
  697. });
  698. } else {
  699. $.each(options.files, function (index, file) {
  700. formData.push({
  701. name: ($.type(options.paramName) === 'array' &&
  702. options.paramName[index]) || paramName,
  703. value: file
  704. });
  705. });
  706. }
  707. } else {
  708. if (that._isInstanceOf('FormData', options.formData)) {
  709. formData = options.formData;
  710. } else {
  711. formData = new FormData();
  712. $.each(this._getFormData(options), function (index, field) {
  713. formData.append(field.name, field.value);
  714. });
  715. }
  716. if (options.blob) {
  717. formData.append(paramName, options.blob, file.name);
  718. } else {
  719. $.each(options.files, function (index, file) {
  720. if (that._isInstanceOf('File', file) ||
  721. that._isInstanceOf('Blob', file)) {
  722. formData.append(
  723. ($.type(options.paramName) === 'array' &&
  724. options.paramName[index]) || paramName,
  725. file,
  726. file.uploadName || file.name
  727. );
  728. }
  729. });
  730. }
  731. }
  732. options.data = formData;
  733. }
  734. options.blob = null;
  735. },
  736. _initIframeSettings: function (options) {
  737. var targetHost = $('<a></a>').prop('href', options.url).prop('host');
  738. options.dataType = 'iframe ' + (options.dataType || '');
  739. options.formData = this._getFormData(options);
  740. if (options.redirect && targetHost && targetHost !== location.host) {
  741. options.formData.push({
  742. name: options.redirectParamName || 'redirect',
  743. value: options.redirect
  744. });
  745. }
  746. },
  747. _initDataSettings: function (options) {
  748. if (this._isXHRUpload(options)) {
  749. if (!this._chunkedUpload(options, true)) {
  750. if (!options.data) {
  751. this._initXHRData(options);
  752. }
  753. this._initProgressListener(options);
  754. }
  755. if (options.postMessage) {
  756. options.dataType = 'postmessage ' + (options.dataType || '');
  757. }
  758. } else {
  759. this._initIframeSettings(options);
  760. }
  761. },
  762. _getParamName: function (options) {
  763. var fileInput = $(options.fileInput),
  764. paramName = options.paramName;
  765. if (!paramName) {
  766. paramName = [];
  767. fileInput.each(function () {
  768. var input = $(this),
  769. name = input.prop('name') || 'files[]',
  770. i = (input.prop('files') || [1]).length;
  771. while (i) {
  772. paramName.push(name);
  773. i -= 1;
  774. }
  775. });
  776. if (!paramName.length) {
  777. paramName = [fileInput.prop('name') || 'files[]'];
  778. }
  779. } else if (!$.isArray(paramName)) {
  780. paramName = [paramName];
  781. }
  782. return paramName;
  783. },
  784. _initFormSettings: function (options) {
  785. if (!options.form || !options.form.length) {
  786. options.form = $(options.fileInput.prop('form'));
  787. if (!options.form.length) {
  788. options.form = $(this.options.fileInput.prop('form'));
  789. }
  790. }
  791. options.paramName = this._getParamName(options);
  792. if (!options.url) {
  793. options.url = options.form.prop('action') || location.href;
  794. }
  795. options.type = (options.type ||
  796. ($.type(options.form.prop('method')) === 'string' &&
  797. options.form.prop('method')) || ''
  798. ).toUpperCase();
  799. if (options.type !== 'POST' && options.type !== 'PUT' &&
  800. options.type !== 'PATCH') {
  801. options.type = 'POST';
  802. }
  803. if (!options.formAcceptCharset) {
  804. options.formAcceptCharset = options.form.attr('accept-charset');
  805. }
  806. },
  807. _getAJAXSettings: function (data) {
  808. var options = $.extend({}, this.options, data);
  809. this._initFormSettings(options);
  810. this._initDataSettings(options);
  811. return options;
  812. },
  813. _getDeferredState: function (deferred) {
  814. if (deferred.state) {
  815. return deferred.state();
  816. }
  817. if (deferred.isResolved()) {
  818. return 'resolved';
  819. }
  820. if (deferred.isRejected()) {
  821. return 'rejected';
  822. }
  823. return 'pending';
  824. },
  825. _enhancePromise: function (promise) {
  826. promise.success = promise.done;
  827. promise.error = promise.fail;
  828. promise.complete = promise.always;
  829. return promise;
  830. },
  831. _getXHRPromise: function (resolveOrReject, context, args) {
  832. var dfd = $.Deferred(),
  833. promise = dfd.promise();
  834. context = context || this.options.context || promise;
  835. if (resolveOrReject === true) {
  836. dfd.resolveWith(context, args);
  837. } else if (resolveOrReject === false) {
  838. dfd.rejectWith(context, args);
  839. }
  840. promise.abort = dfd.promise;
  841. return this._enhancePromise(promise);
  842. },
  843. _addConvenienceMethods: function (e, data) {
  844. var that = this,
  845. getPromise = function (args) {
  846. return $.Deferred().resolveWith(that, args).promise();
  847. };
  848. data.process = function (resolveFunc, rejectFunc) {
  849. if (resolveFunc || rejectFunc) {
  850. data._processQueue = this._processQueue =
  851. (this._processQueue || getPromise([this])).pipe(
  852. function () {
  853. if (data.errorThrown) {
  854. return $.Deferred()
  855. .rejectWith(that, [data]).promise();
  856. }
  857. return getPromise(arguments);
  858. }
  859. ).pipe(resolveFunc, rejectFunc);
  860. }
  861. return this._processQueue || getPromise([this]);
  862. };
  863. data.submit = function () {
  864. if (this.state() !== 'pending') {
  865. data.jqXHR = this.jqXHR =
  866. (that._trigger(
  867. 'submit',
  868. $.Event('submit', {delegatedEvent: e}),
  869. this
  870. ) !== false) && that._onSend(e, this);
  871. }
  872. return this.jqXHR || that._getXHRPromise();
  873. };
  874. data.abort = function () {
  875. if (this.jqXHR) {
  876. return this.jqXHR.abort();
  877. }
  878. this.errorThrown = 'abort';
  879. that._trigger('fail', null, this);
  880. return that._getXHRPromise(false);
  881. };
  882. data.state = function () {
  883. if (this.jqXHR) {
  884. return that._getDeferredState(this.jqXHR);
  885. }
  886. if (this._processQueue) {
  887. return that._getDeferredState(this._processQueue);
  888. }
  889. };
  890. data.processing = function () {
  891. return !this.jqXHR && this._processQueue && that
  892. ._getDeferredState(this._processQueue) === 'pending';
  893. };
  894. data.progress = function () {
  895. return this._progress;
  896. };
  897. data.response = function () {
  898. return this._response;
  899. };
  900. },
  901. _getUploadedBytes: function (jqXHR) {
  902. var range = jqXHR.getResponseHeader('Range'),
  903. parts = range && range.split('-'),
  904. upperBytesPos = parts && parts.length > 1 &&
  905. parseInt(parts[1], 10);
  906. return upperBytesPos && upperBytesPos + 1;
  907. },
  908. _chunkedUpload: function (options, testOnly) {
  909. options.uploadedBytes = options.uploadedBytes || 0;
  910. var that = this,
  911. file = options.files[0],
  912. fs = file.size,
  913. ub = options.uploadedBytes,
  914. mcs = options.maxChunkSize || fs,
  915. slice = this._blobSlice,
  916. dfd = $.Deferred(),
  917. promise = dfd.promise(),
  918. jqXHR,
  919. upload;
  920. if (!(this._isXHRUpload(options) && slice && (ub || mcs < fs)) ||
  921. options.data) {
  922. return false;
  923. }
  924. if (testOnly) {
  925. return true;
  926. }
  927. if (ub >= fs) {
  928. file.error = options.i18n('uploadedBytes');
  929. return this._getXHRPromise(
  930. false,
  931. options.context,
  932. [null, 'error', file.error]
  933. );
  934. }
  935. upload = function () {
  936. var o = $.extend({}, options),
  937. currentLoaded = o._progress.loaded;
  938. o.blob = slice.call(
  939. file,
  940. ub,
  941. ub + mcs,
  942. file.type
  943. );
  944. o.chunkSize = o.blob.size;
  945. o.contentRange = 'bytes ' + ub + '-' +
  946. (ub + o.chunkSize - 1) + '/' + fs;
  947. that._initXHRData(o);
  948. that._initProgressListener(o);
  949. jqXHR = ((that._trigger('chunksend', null, o) !== false && $.ajax(o)) ||
  950. that._getXHRPromise(false, o.context))
  951. .done(function (result, textStatus, jqXHR) {
  952. ub = that._getUploadedBytes(jqXHR) ||
  953. (ub + o.chunkSize);
  954. if (currentLoaded + o.chunkSize - o._progress.loaded) {
  955. that._onProgress($.Event('progress', {
  956. lengthComputable: true,
  957. loaded: ub - o.uploadedBytes,
  958. total: ub - o.uploadedBytes
  959. }), o);
  960. }
  961. options.uploadedBytes = o.uploadedBytes = ub;
  962. o.result = result;
  963. o.textStatus = textStatus;
  964. o.jqXHR = jqXHR;
  965. that._trigger('chunkdone', null, o);
  966. that._trigger('chunkalways', null, o);
  967. if (ub < fs) {
  968. upload();
  969. } else {
  970. dfd.resolveWith(
  971. o.context,
  972. [result, textStatus, jqXHR]
  973. );
  974. }
  975. })
  976. .fail(function (jqXHR, textStatus, errorThrown) {
  977. o.jqXHR = jqXHR;
  978. o.textStatus = textStatus;
  979. o.errorThrown = errorThrown;
  980. that._trigger('chunkfail', null, o);
  981. that._trigger('chunkalways', null, o);
  982. dfd.rejectWith(
  983. o.context,
  984. [jqXHR, textStatus, errorThrown]
  985. );
  986. });
  987. };
  988. this._enhancePromise(promise);
  989. promise.abort = function () {
  990. return jqXHR.abort();
  991. };
  992. upload();
  993. return promise;
  994. },
  995. _beforeSend: function (e, data) {
  996. if (this._active === 0) {
  997. this._trigger('start');
  998. this._bitrateTimer = new this._BitrateTimer();
  999. this._progress.loaded = this._progress.total = 0;
  1000. this._progress.bitrate = 0;
  1001. }
  1002. this._initResponseObject(data);
  1003. this._initProgressObject(data);
  1004. data._progress.loaded = data.loaded = data.uploadedBytes || 0;
  1005. data._progress.total = data.total = this._getTotal(data.files) || 1;
  1006. data._progress.bitrate = data.bitrate = 0;
  1007. this._active += 1;
  1008. this._progress.loaded += data.loaded;
  1009. this._progress.total += data.total;
  1010. },
  1011. _onDone: function (result, textStatus, jqXHR, options) {
  1012. var total = options._progress.total,
  1013. response = options._response;
  1014. if (options._progress.loaded < total) {
  1015. this._onProgress($.Event('progress', {
  1016. lengthComputable: true,
  1017. loaded: total,
  1018. total: total
  1019. }), options);
  1020. }
  1021. response.result = options.result = result;
  1022. response.textStatus = options.textStatus = textStatus;
  1023. response.jqXHR = options.jqXHR = jqXHR;
  1024. this._trigger('done', null, options);
  1025. },
  1026. _onFail: function (jqXHR, textStatus, errorThrown, options) {
  1027. var response = options._response;
  1028. if (options.recalculateProgress) {
  1029. this._progress.loaded -= options._progress.loaded;
  1030. this._progress.total -= options._progress.total;
  1031. }
  1032. response.jqXHR = options.jqXHR = jqXHR;
  1033. response.textStatus = options.textStatus = textStatus;
  1034. response.errorThrown = options.errorThrown = errorThrown;
  1035. this._trigger('fail', null, options);
  1036. },
  1037. _onAlways: function (jqXHRorResult, textStatus, jqXHRorError, options) {
  1038. this._trigger('always', null, options);
  1039. },
  1040. _onSend: function (e, data) {
  1041. if (!data.submit) {
  1042. this._addConvenienceMethods(e, data);
  1043. }
  1044. var that = this,
  1045. jqXHR,
  1046. aborted,
  1047. slot,
  1048. pipe,
  1049. options = that._getAJAXSettings(data),
  1050. send = function () {
  1051. that._sending += 1;
  1052. options._bitrateTimer = new that._BitrateTimer();
  1053. jqXHR = jqXHR || (
  1054. ((aborted || that._trigger(
  1055. 'send',
  1056. $.Event('send', {delegatedEvent: e}),
  1057. options
  1058. ) === false) &&
  1059. that._getXHRPromise(false, options.context, aborted)) ||
  1060. that._chunkedUpload(options) || $.ajax(options)
  1061. ).done(function (result, textStatus, jqXHR) {
  1062. that._onDone(result, textStatus, jqXHR, options);
  1063. }).fail(function (jqXHR, textStatus, errorThrown) {
  1064. that._onFail(jqXHR, textStatus, errorThrown, options);
  1065. }).always(function (jqXHRorResult, textStatus, jqXHRorError) {
  1066. that._onAlways(
  1067. jqXHRorResult,
  1068. textStatus,
  1069. jqXHRorError,
  1070. options
  1071. );
  1072. that._sending -= 1;
  1073. that._active -= 1;
  1074. if (options.limitConcurrentUploads &&
  1075. options.limitConcurrentUploads > that._sending) {
  1076. var nextSlot = that._slots.shift();
  1077. while (nextSlot) {
  1078. if (that._getDeferredState(nextSlot) === 'pending') {
  1079. nextSlot.resolve();
  1080. break;
  1081. }
  1082. nextSlot = that._slots.shift();
  1083. }
  1084. }
  1085. if (that._active === 0) {
  1086. that._trigger('stop');
  1087. }
  1088. });
  1089. return jqXHR;
  1090. };
  1091. this._beforeSend(e, options);
  1092. if (this.options.sequentialUploads ||
  1093. (this.options.limitConcurrentUploads &&
  1094. this.options.limitConcurrentUploads <= this._sending)) {
  1095. if (this.options.limitConcurrentUploads > 1) {
  1096. slot = $.Deferred();
  1097. this._slots.push(slot);
  1098. pipe = slot.pipe(send);
  1099. } else {
  1100. this._sequence = this._sequence.pipe(send, send);
  1101. pipe = this._sequence;
  1102. }
  1103. pipe.abort = function () {
  1104. aborted = [undefined, 'abort', 'abort'];
  1105. if (!jqXHR) {
  1106. if (slot) {
  1107. slot.rejectWith(options.context, aborted);
  1108. }
  1109. return send();
  1110. }
  1111. return jqXHR.abort();
  1112. };
  1113. return this._enhancePromise(pipe);
  1114. }
  1115. return send();
  1116. },
  1117. _onAdd: function (e, data) {
  1118. var that = this,
  1119. result = true,
  1120. options = $.extend({}, this.options, data),
  1121. files = data.files,
  1122. filesLength = files.length,
  1123. limit = options.limitMultiFileUploads,
  1124. limitSize = options.limitMultiFileUploadSize,
  1125. overhead = options.limitMultiFileUploadSizeOverhead,
  1126. batchSize = 0,
  1127. paramName = this._getParamName(options),
  1128. paramNameSet,
  1129. paramNameSlice,
  1130. fileSet,
  1131. i,
  1132. j = 0;
  1133. if (!filesLength) {
  1134. return false;
  1135. }
  1136. if (limitSize && files[0].size === undefined) {
  1137. limitSize = undefined;
  1138. }
  1139. if (!(options.singleFileUploads || limit || limitSize) ||
  1140. !this._isXHRUpload(options)) {
  1141. fileSet = [files];
  1142. paramNameSet = [paramName];
  1143. } else if (!(options.singleFileUploads || limitSize) && limit) {
  1144. fileSet = [];
  1145. paramNameSet = [];
  1146. for (i = 0; i < filesLength; i += limit) {
  1147. fileSet.push(files.slice(i, i + limit));
  1148. paramNameSlice = paramName.slice(i, i + limit);
  1149. if (!paramNameSlice.length) {
  1150. paramNameSlice = paramName;
  1151. }
  1152. paramNameSet.push(paramNameSlice);
  1153. }
  1154. } else if (!options.singleFileUploads && limitSize) {
  1155. fileSet = [];
  1156. paramNameSet = [];
  1157. for (i = 0; i < filesLength; i = i + 1) {
  1158. batchSize += files[i].size + overhead;
  1159. if (i + 1 === filesLength ||
  1160. ((batchSize + files[i + 1].size + overhead) > limitSize) ||
  1161. (limit && i + 1 - j >= limit)) {
  1162. fileSet.push(files.slice(j, i + 1));
  1163. paramNameSlice = paramName.slice(j, i + 1);
  1164. if (!paramNameSlice.length) {
  1165. paramNameSlice = paramName;
  1166. }
  1167. paramNameSet.push(paramNameSlice);
  1168. j = i + 1;
  1169. batchSize = 0;
  1170. }
  1171. }
  1172. } else {
  1173. paramNameSet = paramName;
  1174. }
  1175. data.originalFiles = files;
  1176. $.each(fileSet || files, function (index, element) {
  1177. var newData = $.extend({}, data);
  1178. newData.files = fileSet ? element : [element];
  1179. newData.paramName = paramNameSet[index];
  1180. that._initResponseObject(newData);
  1181. that._initProgressObject(newData);
  1182. that._addConvenienceMethods(e, newData);
  1183. result = that._trigger(
  1184. 'add',
  1185. $.Event('add', {delegatedEvent: e}),
  1186. newData
  1187. );
  1188. return result;
  1189. });
  1190. return result;
  1191. },
  1192. _replaceFileInput: function (data) {
  1193. var input = data.fileInput,
  1194. inputClone = input.clone(true),
  1195. restoreFocus = input.is(document.activeElement);
  1196. data.fileInputClone = inputClone;
  1197. $('<form></form>').append(inputClone)[0].reset();
  1198. input.after(inputClone).detach();
  1199. if (restoreFocus) {
  1200. inputClone.focus();
  1201. }
  1202. $.cleanData(input.unbind('remove'));
  1203. this.options.fileInput = this.options.fileInput.map(function (i, el) {
  1204. if (el === input[0]) {
  1205. return inputClone[0];
  1206. }
  1207. return el;
  1208. });
  1209. if (input[0] === this.element[0]) {
  1210. this.element = inputClone;
  1211. }
  1212. },
  1213. _handleFileTreeEntry: function (entry, path) {
  1214. var that = this,
  1215. dfd = $.Deferred(),
  1216. errorHandler = function (e) {
  1217. if (e && !e.entry) {
  1218. e.entry = entry;
  1219. }
  1220. dfd.resolve([e]);
  1221. },
  1222. successHandler = function (entries) {
  1223. that._handleFileTreeEntries(
  1224. entries,
  1225. path + entry.name + '/'
  1226. ).done(function (files) {
  1227. dfd.resolve(files);
  1228. }).fail(errorHandler);
  1229. },
  1230. readEntries = function () {
  1231. dirReader.readEntries(function (results) {
  1232. if (!results.length) {
  1233. successHandler(entries);
  1234. } else {
  1235. entries = entries.concat(results);
  1236. readEntries();
  1237. }
  1238. }, errorHandler);
  1239. },
  1240. dirReader, entries = [];
  1241. path = path || '';
  1242. if (entry.isFile) {
  1243. if (entry._file) {
  1244. entry._file.relativePath = path;
  1245. dfd.resolve(entry._file);
  1246. } else {
  1247. entry.file(function (file) {
  1248. file.relativePath = path;
  1249. dfd.resolve(file);
  1250. }, errorHandler);
  1251. }
  1252. } else if (entry.isDirectory) {
  1253. dirReader = entry.createReader();
  1254. readEntries();
  1255. } else {
  1256. dfd.resolve([]);
  1257. }
  1258. return dfd.promise();
  1259. },
  1260. _handleFileTreeEntries: function (entries, path) {
  1261. var that = this;
  1262. return $.when.apply(
  1263. $,
  1264. $.map(entries, function (entry) {
  1265. return that._handleFileTreeEntry(entry, path);
  1266. })
  1267. ).pipe(function () {
  1268. return Array.prototype.concat.apply(
  1269. [],
  1270. arguments
  1271. );
  1272. });
  1273. },
  1274. _getDroppedFiles: function (dataTransfer) {
  1275. dataTransfer = dataTransfer || {};
  1276. var items = dataTransfer.items;
  1277. if (items && items.length && (items[0].webkitGetAsEntry ||
  1278. items[0].getAsEntry)) {
  1279. return this._handleFileTreeEntries(
  1280. $.map(items, function (item) {
  1281. var entry;
  1282. if (item.webkitGetAsEntry) {
  1283. entry = item.webkitGetAsEntry();
  1284. if (entry) {
  1285. entry._file = item.getAsFile();
  1286. }
  1287. return entry;
  1288. }
  1289. return item.getAsEntry();
  1290. })
  1291. );
  1292. }
  1293. return $.Deferred().resolve(
  1294. $.makeArray(dataTransfer.files)
  1295. ).promise();
  1296. },
  1297. _getSingleFileInputFiles: function (fileInput) {
  1298. fileInput = $(fileInput);
  1299. var entries = fileInput.prop('webkitEntries') ||
  1300. fileInput.prop('entries'),
  1301. files,
  1302. value;
  1303. if (entries && entries.length) {
  1304. return this._handleFileTreeEntries(entries);
  1305. }
  1306. files = $.makeArray(fileInput.prop('files'));
  1307. if (!files.length) {
  1308. value = fileInput.prop('value');
  1309. if (!value) {
  1310. return $.Deferred().resolve([]).promise();
  1311. }
  1312. files = [{name: value.replace(/^.*\\/, '')}];
  1313. } else if (files[0].name === undefined && files[0].fileName) {
  1314. $.each(files, function (index, file) {
  1315. file.name = file.fileName;
  1316. file.size = file.fileSize;
  1317. });
  1318. }
  1319. return $.Deferred().resolve(files).promise();
  1320. },
  1321. _getFileInputFiles: function (fileInput) {
  1322. if (!(fileInput instanceof $) || fileInput.length === 1) {
  1323. return this._getSingleFileInputFiles(fileInput);
  1324. }
  1325. return $.when.apply(
  1326. $,
  1327. $.map(fileInput, this._getSingleFileInputFiles)
  1328. ).pipe(function () {
  1329. return Array.prototype.concat.apply(
  1330. [],
  1331. arguments
  1332. );
  1333. });
  1334. },
  1335. _onChange: function (e) {
  1336. var that = this,
  1337. data = {
  1338. fileInput: $(e.target),
  1339. form: $(e.target.form)
  1340. };
  1341. this._getFileInputFiles(data.fileInput).always(function (files) {
  1342. data.files = files;
  1343. if (that.options.replaceFileInput) {
  1344. that._replaceFileInput(data);
  1345. }
  1346. if (that._trigger(
  1347. 'change',
  1348. $.Event('change', {delegatedEvent: e}),
  1349. data
  1350. ) !== false) {
  1351. that._onAdd(e, data);
  1352. }
  1353. });
  1354. },
  1355. _onPaste: function (e) {
  1356. var items = e.originalEvent && e.originalEvent.clipboardData &&
  1357. e.originalEvent.clipboardData.items,
  1358. data = {files: []};
  1359. if (items && items.length) {
  1360. $.each(items, function (index, item) {
  1361. var file = item.getAsFile && item.getAsFile();
  1362. if (file) {
  1363. data.files.push(file);
  1364. }
  1365. });
  1366. if (this._trigger(
  1367. 'paste',
  1368. $.Event('paste', {delegatedEvent: e}),
  1369. data
  1370. ) !== false) {
  1371. this._onAdd(e, data);
  1372. }
  1373. }
  1374. },
  1375. _onDrop: function (e) {
  1376. e.dataTransfer = e.originalEvent && e.originalEvent.dataTransfer;
  1377. var that = this,
  1378. dataTransfer = e.dataTransfer,
  1379. data = {};
  1380. if (dataTransfer && dataTransfer.files && dataTransfer.files.length) {
  1381. e.preventDefault();
  1382. this._getDroppedFiles(dataTransfer).always(function (files) {
  1383. data.files = files;
  1384. if (that._trigger(
  1385. 'drop',
  1386. $.Event('drop', {delegatedEvent: e}),
  1387. data
  1388. ) !== false) {
  1389. that._onAdd(e, data);
  1390. }
  1391. });
  1392. }
  1393. },
  1394. _onDragOver: getDragHandler('dragover'),
  1395. _onDragEnter: getDragHandler('dragenter'),
  1396. _onDragLeave: getDragHandler('dragleave'),
  1397. _initEventHandlers: function () {
  1398. if (this._isXHRUpload(this.options)) {
  1399. this._on(this.options.dropZone, {
  1400. dragover: this._onDragOver,
  1401. drop: this._onDrop,
  1402. dragenter: this._onDragEnter,
  1403. dragleave: this._onDragLeave
  1404. });
  1405. this._on(this.options.pasteZone, {
  1406. paste: this._onPaste
  1407. });
  1408. }
  1409. if ($.support.fileInput) {
  1410. this._on(this.options.fileInput, {
  1411. change: this._onChange
  1412. });
  1413. }
  1414. },
  1415. _destroyEventHandlers: function () {
  1416. this._off(this.options.dropZone, 'dragenter dragleave dragover drop');
  1417. this._off(this.options.pasteZone, 'paste');
  1418. this._off(this.options.fileInput, 'change');
  1419. },
  1420. _setOption: function (key, value) {
  1421. var reinit = $.inArray(key, this._specialOptions) !== -1;
  1422. if (reinit) {
  1423. this._destroyEventHandlers();
  1424. }
  1425. this._super(key, value);
  1426. if (reinit) {
  1427. this._initSpecialOptions();
  1428. this._initEventHandlers();
  1429. }
  1430. },
  1431. _initSpecialOptions: function () {
  1432. var options = this.options;
  1433. if (options.fileInput === undefined) {
  1434. options.fileInput = this.element.is('input[type="file"]') ?
  1435. this.element : this.element.find('input[type="file"]');
  1436. } else if (!(options.fileInput instanceof $)) {
  1437. options.fileInput = $(options.fileInput);
  1438. }
  1439. if (!(options.dropZone instanceof $)) {
  1440. options.dropZone = $(options.dropZone);
  1441. }
  1442. if (!(options.pasteZone instanceof $)) {
  1443. options.pasteZone = $(options.pasteZone);
  1444. }
  1445. },
  1446. _getRegExp: function (str) {
  1447. var parts = str.split('/'),
  1448. modifiers = parts.pop();
  1449. parts.shift();
  1450. return new RegExp(parts.join('/'), modifiers);
  1451. },
  1452. _isRegExpOption: function (key, value) {
  1453. return key !== 'url' && $.type(value) === 'string' &&
  1454. /^\/.*\/[igm]{0,3}$/.test(value);
  1455. },
  1456. _initDataAttributes: function () {
  1457. var that = this,
  1458. options = this.options,
  1459. data = this.element.data();
  1460. $.each(
  1461. this.element[0].attributes,
  1462. function (index, attr) {
  1463. var key = attr.name.toLowerCase(),
  1464. value;
  1465. if (/^data-/.test(key)) {
  1466. key = key.slice(5).replace(/-[a-z]/g, function (str) {
  1467. return str.charAt(1).toUpperCase();
  1468. });
  1469. value = data[key];
  1470. if (that._isRegExpOption(key, value)) {
  1471. value = that._getRegExp(value);
  1472. }
  1473. options[key] = value;
  1474. }
  1475. }
  1476. );
  1477. },
  1478. _create: function () {
  1479. this._initDataAttributes();
  1480. this._initSpecialOptions();
  1481. this._slots = [];
  1482. this._sequence = this._getXHRPromise(true);
  1483. this._sending = this._active = 0;
  1484. this._initProgressObject(this);
  1485. this._initEventHandlers();
  1486. },
  1487. active: function () {
  1488. return this._active;
  1489. },
  1490. progress: function () {
  1491. return this._progress;
  1492. },
  1493. add: function (data) {
  1494. var that = this;
  1495. if (!data || this.options.disabled) {
  1496. return;
  1497. }
  1498. if (data.fileInput && !data.files) {
  1499. this._getFileInputFiles(data.fileInput).always(function (files) {
  1500. data.files = files;
  1501. that._onAdd(null, data);
  1502. });
  1503. } else {
  1504. data.files = $.makeArray(data.files);
  1505. this._onAdd(null, data);
  1506. }
  1507. },
  1508. send: function (data) {
  1509. if (data && !this.options.disabled) {
  1510. if (data.fileInput && !data.files) {
  1511. var that = this,
  1512. dfd = $.Deferred(),
  1513. promise = dfd.promise(),
  1514. jqXHR,
  1515. aborted;
  1516. promise.abort = function () {
  1517. aborted = true;
  1518. if (jqXHR) {
  1519. return jqXHR.abort();
  1520. }
  1521. dfd.reject(null, 'abort', 'abort');
  1522. return promise;
  1523. };
  1524. this._getFileInputFiles(data.fileInput).always(
  1525. function (files) {
  1526. if (aborted) {
  1527. return;
  1528. }
  1529. if (!files.length) {
  1530. dfd.reject();
  1531. return;
  1532. }
  1533. data.files = files;
  1534. jqXHR = that._onSend(null, data);
  1535. jqXHR.then(
  1536. function (result, textStatus, jqXHR) {
  1537. dfd.resolve(result, textStatus, jqXHR);
  1538. },
  1539. function (jqXHR, textStatus, errorThrown) {
  1540. dfd.reject(jqXHR, textStatus, errorThrown);
  1541. }
  1542. );
  1543. }
  1544. );
  1545. return this._enhancePromise(promise);
  1546. }
  1547. data.files = $.makeArray(data.files);
  1548. if (data.files.length) {
  1549. return this._onSend(null, data);
  1550. }
  1551. }
  1552. return this._getXHRPromise(false, data && data.context);
  1553. }
  1554. });
  1555. }));
  1556. /*
  1557. * jquery.iframe-transport.js
  1558. */
  1559. (function (factory) {
  1560. 'use strict';
  1561. if (typeof define === 'function' && define.amd) {
  1562. define(['jquery'], factory);
  1563. } else if (typeof exports === 'object') {
  1564. factory(require('jquery'));
  1565. } else {
  1566. factory(window.jQuery);
  1567. }
  1568. }(function ($) {
  1569. 'use strict';
  1570. var counter = 0;
  1571. $.ajaxTransport('iframe', function (options) {
  1572. if (options.async) {
  1573. var initialIframeSrc = options.initialIframeSrc || 'javascript:false;',
  1574. form,
  1575. iframe,
  1576. addParamChar;
  1577. return {
  1578. send: function (_, completeCallback) {
  1579. form = $('<form style="display:none;"></form>');
  1580. form.attr('accept-charset', options.formAcceptCharset);
  1581. addParamChar = /\?/.test(options.url) ? '&' : '?';
  1582. if (options.type === 'DELETE') {
  1583. options.url = options.url + addParamChar + '_method=DELETE';
  1584. options.type = 'POST';
  1585. } else if (options.type === 'PUT') {
  1586. options.url = options.url + addParamChar + '_method=PUT';
  1587. options.type = 'POST';
  1588. } else if (options.type === 'PATCH') {
  1589. options.url = options.url + addParamChar + '_method=PATCH';
  1590. options.type = 'POST';
  1591. }
  1592. counter += 1;
  1593. iframe = $(
  1594. '<iframe src="' + initialIframeSrc +
  1595. '" name="iframe-transport-' + counter + '"></iframe>'
  1596. ).bind('load', function () {
  1597. var fileInputClones,
  1598. paramNames = $.isArray(options.paramName) ?
  1599. options.paramName : [options.paramName];
  1600. iframe
  1601. .unbind('load')
  1602. .bind('load', function () {
  1603. var response;
  1604. try {
  1605. response = iframe.contents();
  1606. if (!response.length || !response[0].firstChild) {
  1607. throw new Error();
  1608. }
  1609. } catch (e) {
  1610. response = undefined;
  1611. }
  1612. completeCallback(
  1613. 200,
  1614. 'success',
  1615. {'iframe': response}
  1616. );
  1617. $('<iframe src="' + initialIframeSrc + '"></iframe>')
  1618. .appendTo(form);
  1619. window.setTimeout(function () {
  1620. form.remove();
  1621. }, 0);
  1622. });
  1623. form
  1624. .prop('target', iframe.prop('name'))
  1625. .prop('action', options.url)
  1626. .prop('method', options.type);
  1627. if (options.formData) {
  1628. $.each(options.formData, function (index, field) {
  1629. $('<input type="hidden"/>')
  1630. .prop('name', field.name)
  1631. .val(field.value)
  1632. .appendTo(form);
  1633. });
  1634. }
  1635. if (options.fileInput && options.fileInput.length &&
  1636. options.type === 'POST') {
  1637. fileInputClones = options.fileInput.clone();
  1638. options.fileInput.after(function (index) {
  1639. return fileInputClones[index];
  1640. });
  1641. if (options.paramName) {
  1642. options.fileInput.each(function (index) {
  1643. $(this).prop(
  1644. 'name',
  1645. paramNames[index] || options.paramName
  1646. );
  1647. });
  1648. }
  1649. form
  1650. .append(options.fileInput)
  1651. .prop('enctype', 'multipart/form-data')
  1652. .prop('encoding', 'multipart/form-data');
  1653. options.fileInput.removeAttr('form');
  1654. }
  1655. form.submit();
  1656. if (fileInputClones && fileInputClones.length) {
  1657. options.fileInput.each(function (index, input) {
  1658. var clone = $(fileInputClones[index]);
  1659. $(input)
  1660. .prop('name', clone.prop('name'))
  1661. .attr('form', clone.attr('form'));
  1662. clone.replaceWith(input);
  1663. });
  1664. }
  1665. });
  1666. form.append(iframe).appendTo(document.body);
  1667. },
  1668. abort: function () {
  1669. if (iframe) {
  1670. iframe
  1671. .unbind('load')
  1672. .prop('src', initialIframeSrc);
  1673. }
  1674. if (form) {
  1675. form.remove();
  1676. }
  1677. }
  1678. };
  1679. }
  1680. });
  1681. $.ajaxSetup({
  1682. converters: {
  1683. 'iframe text': function (iframe) {
  1684. return iframe && $(iframe[0].body).text();
  1685. },
  1686. 'iframe json': function (iframe) {
  1687. return iframe && $.parseJSON($(iframe[0].body).text());
  1688. },
  1689. 'iframe html': function (iframe) {
  1690. return iframe && $(iframe[0].body).html();
  1691. },
  1692. 'iframe xml': function (iframe) {
  1693. var xmlDoc = iframe && iframe[0];
  1694. return xmlDoc && $.isXMLDoc(xmlDoc) ? xmlDoc :
  1695. $.parseXML((xmlDoc.XMLDocument && xmlDoc.XMLDocument.xml) ||
  1696. $(xmlDoc.body).html());
  1697. },
  1698. 'iframe script': function (iframe) {
  1699. return iframe && $.globalEval($(iframe[0].body).text());
  1700. }
  1701. }
  1702. });
  1703. }));
  1704. /*
  1705. * jquery.fileupload-process.js
  1706. */
  1707. (function (factory) {
  1708. 'use strict';
  1709. if (typeof define === 'function' && define.amd) {
  1710. // Register as an anonymous AMD module:
  1711. define([
  1712. 'jquery',
  1713. './jquery.fileupload'
  1714. ], factory);
  1715. } else if (typeof exports === 'object') {
  1716. // Node/CommonJS:
  1717. factory(require('jquery'));
  1718. } else {
  1719. // Browser globals:
  1720. factory(
  1721. window.jQuery
  1722. );
  1723. }
  1724. }(function ($) {
  1725. 'use strict';
  1726. var originalAdd = $.blueimp.fileupload.prototype.options.add;
  1727. // The File Upload Processing plugin extends the fileupload widget
  1728. // with file processing functionality:
  1729. $.widget('blueimp.fileupload', $.blueimp.fileupload, {
  1730. options: {
  1731. // The list of processing actions:
  1732. processQueue: [
  1733. /*
  1734. {
  1735. action: 'log',
  1736. type: 'debug'
  1737. }
  1738. */
  1739. ],
  1740. add: function (e, data) {
  1741. var $this = $(this);
  1742. data.process(function () {
  1743. return $this.fileupload('process', data);
  1744. });
  1745. originalAdd.call(this, e, data);
  1746. }
  1747. },
  1748. processActions: {
  1749. /*
  1750. log: function (data, options) {
  1751. console[options.type](
  1752. 'Processing "' + data.files[data.index].name + '"'
  1753. );
  1754. }
  1755. */
  1756. },
  1757. _processFile: function (data, originalData) {
  1758. var that = this,
  1759. dfd = $.Deferred().resolveWith(that, [data]),
  1760. chain = dfd.promise();
  1761. this._trigger('process', null, data);
  1762. $.each(data.processQueue, function (i, settings) {
  1763. var func = function (data) {
  1764. if (originalData.errorThrown) {
  1765. return $.Deferred()
  1766. .rejectWith(that, [originalData]).promise();
  1767. }
  1768. return that.processActions[settings.action].call(
  1769. that,
  1770. data,
  1771. settings
  1772. );
  1773. };
  1774. chain = chain.pipe(func, settings.always && func);
  1775. });
  1776. chain
  1777. .done(function () {
  1778. that._trigger('processdone', null, data);
  1779. that._trigger('processalways', null, data);
  1780. })
  1781. .fail(function () {
  1782. that._trigger('processfail', null, data);
  1783. that._trigger('processalways', null, data);
  1784. });
  1785. return chain;
  1786. },
  1787. // Replaces the settings of each processQueue item that
  1788. // are strings starting with an "@", using the remaining
  1789. // substring as key for the option map,
  1790. // e.g. "@autoUpload" is replaced with options.autoUpload:
  1791. _transformProcessQueue: function (options) {
  1792. var processQueue = [];
  1793. $.each(options.processQueue, function () {
  1794. var settings = {},
  1795. action = this.action,
  1796. prefix = this.prefix === true ? action : this.prefix;
  1797. $.each(this, function (key, value) {
  1798. if ($.type(value) === 'string' &&
  1799. value.charAt(0) === '@') {
  1800. settings[key] = options[
  1801. value.slice(1) || (prefix ? prefix +
  1802. key.charAt(0).toUpperCase() + key.slice(1) : key)
  1803. ];
  1804. } else {
  1805. settings[key] = value;
  1806. }
  1807. });
  1808. processQueue.push(settings);
  1809. });
  1810. options.processQueue = processQueue;
  1811. },
  1812. // Returns the number of files currently in the processsing queue:
  1813. processing: function () {
  1814. return this._processing;
  1815. },
  1816. // Processes the files given as files property of the data parameter,
  1817. // returns a Promise object that allows to bind callbacks:
  1818. process: function (data) {
  1819. var that = this,
  1820. options = $.extend({}, this.options, data);
  1821. if (options.processQueue && options.processQueue.length) {
  1822. this._transformProcessQueue(options);
  1823. if (this._processing === 0) {
  1824. this._trigger('processstart');
  1825. }
  1826. $.each(data.files, function (index) {
  1827. var opts = index ? $.extend({}, options) : options,
  1828. func = function () {
  1829. if (data.errorThrown) {
  1830. return $.Deferred()
  1831. .rejectWith(that, [data]).promise();
  1832. }
  1833. return that._processFile(opts, data);
  1834. };
  1835. opts.index = index;
  1836. that._processing += 1;
  1837. that._processingQueue = that._processingQueue.pipe(func, func)
  1838. .always(function () {
  1839. that._processing -= 1;
  1840. if (that._processing === 0) {
  1841. that._trigger('processstop');
  1842. }
  1843. });
  1844. });
  1845. }
  1846. return this._processingQueue;
  1847. },
  1848. _create: function () {
  1849. this._super();
  1850. this._processing = 0;
  1851. this._processingQueue = $.Deferred().resolveWith(this)
  1852. .promise();
  1853. }
  1854. });
  1855. }));
  1856. /*
  1857. * jquery.fileupload-image.js
  1858. */
  1859. (function (factory) {
  1860. 'use strict';
  1861. if (typeof define === 'function' && define.amd) {
  1862. // Register as an anonymous AMD module:
  1863. define([
  1864. 'jquery',
  1865. 'load-image',
  1866. 'load-image-meta',
  1867. 'load-image-exif',
  1868. 'load-image-ios',
  1869. 'canvas-to-blob',
  1870. './jquery.fileupload-process'
  1871. ], factory);
  1872. } else if (typeof exports === 'object') {
  1873. // Node/CommonJS:
  1874. factory(
  1875. require('jquery'),
  1876. require('load-image')
  1877. );
  1878. } else {
  1879. // Browser globals:
  1880. factory(
  1881. window.jQuery,
  1882. window.loadImage
  1883. );
  1884. }
  1885. }(function ($, loadImage) {
  1886. 'use strict';
  1887. // Prepend to the default processQueue:
  1888. $.blueimp.fileupload.prototype.options.processQueue.unshift(
  1889. {
  1890. action: 'loadImageMetaData',
  1891. disableImageHead: '@',
  1892. disableExif: '@',
  1893. disableExifThumbnail: '@',
  1894. disableExifSub: '@',
  1895. disableExifGps: '@',
  1896. disabled: '@disableImageMetaDataLoad'
  1897. },
  1898. {
  1899. action: 'loadImage',
  1900. // Use the action as prefix for the "@" options:
  1901. prefix: true,
  1902. fileTypes: '@',
  1903. maxFileSize: '@',
  1904. noRevoke: '@',
  1905. disabled: '@disableImageLoad'
  1906. },
  1907. {
  1908. action: 'resizeImage',
  1909. // Use "image" as prefix for the "@" options:
  1910. prefix: 'image',
  1911. maxWidth: '@',
  1912. maxHeight: '@',
  1913. minWidth: '@',
  1914. minHeight: '@',
  1915. crop: '@',
  1916. orientation: '@',
  1917. forceResize: '@',
  1918. disabled: '@disableImageResize'
  1919. },
  1920. {
  1921. action: 'saveImage',
  1922. quality: '@imageQuality',
  1923. type: '@imageType',
  1924. disabled: '@disableImageResize'
  1925. },
  1926. {
  1927. action: 'saveImageMetaData',
  1928. disabled: '@disableImageMetaDataSave'
  1929. },
  1930. {
  1931. action: 'resizeImage',
  1932. // Use "preview" as prefix for the "@" options:
  1933. prefix: 'preview',
  1934. maxWidth: '@',
  1935. maxHeight: '@',
  1936. minWidth: '@',
  1937. minHeight: '@',
  1938. crop: '@',
  1939. orientation: '@',
  1940. thumbnail: '@',
  1941. canvas: '@',
  1942. disabled: '@disableImagePreview'
  1943. },
  1944. {
  1945. action: 'setImage',
  1946. name: '@imagePreviewName',
  1947. disabled: '@disableImagePreview'
  1948. },
  1949. {
  1950. action: 'deleteImageReferences',
  1951. disabled: '@disableImageReferencesDeletion'
  1952. }
  1953. );
  1954. $.widget('blueimp.fileupload', $.blueimp.fileupload, {
  1955. options: {
  1956. loadImageFileTypes: /^image\/(gif|jpeg|png|svg\+xml)$/,
  1957. loadImageMaxFileSize: 10000000,
  1958. imageMaxWidth: 1920,
  1959. imageMaxHeight: 1080,
  1960. imageOrientation: false,
  1961. imageCrop: false,
  1962. disableImageResize: true,
  1963. previewMaxWidth: 80,
  1964. previewMaxHeight: 80,
  1965. previewOrientation: true,
  1966. previewThumbnail: true,
  1967. previewCrop: false,
  1968. previewCanvas: true
  1969. },
  1970. processActions: {
  1971. loadImage: function (data, options) {
  1972. if (options.disabled) {
  1973. return data;
  1974. }
  1975. var that = this,
  1976. file = data.files[data.index],
  1977. dfd = $.Deferred();
  1978. if (($.type(options.maxFileSize) === 'number' &&
  1979. file.size > options.maxFileSize) ||
  1980. (options.fileTypes &&
  1981. !options.fileTypes.test(file.type)) ||
  1982. !loadImage(
  1983. file,
  1984. function (img) {
  1985. if (img.src) {
  1986. data.img = img;
  1987. }
  1988. dfd.resolveWith(that, [data]);
  1989. },
  1990. options
  1991. )) {
  1992. return data;
  1993. }
  1994. return dfd.promise();
  1995. },
  1996. resizeImage: function (data, options) {
  1997. if (options.disabled || !(data.canvas || data.img)) {
  1998. return data;
  1999. }
  2000. options = $.extend({canvas: true}, options);
  2001. var that = this,
  2002. dfd = $.Deferred(),
  2003. img = (options.canvas && data.canvas) || data.img,
  2004. resolve = function (newImg) {
  2005. if (newImg && (newImg.width !== img.width ||
  2006. newImg.height !== img.height ||
  2007. options.forceResize)) {
  2008. data[newImg.getContext ? 'canvas' : 'img'] = newImg;
  2009. }
  2010. data.preview = newImg;
  2011. dfd.resolveWith(that, [data]);
  2012. },
  2013. thumbnail;
  2014. if (data.exif) {
  2015. if (options.orientation === true) {
  2016. options.orientation = data.exif.get('Orientation');
  2017. }
  2018. if (options.thumbnail) {
  2019. thumbnail = data.exif.get('Thumbnail');
  2020. if (thumbnail) {
  2021. loadImage(thumbnail, resolve, options);
  2022. return dfd.promise();
  2023. }
  2024. }
  2025. if (data.orientation) {
  2026. delete options.orientation;
  2027. } else {
  2028. data.orientation = options.orientation;
  2029. }
  2030. }
  2031. if (img) {
  2032. resolve(loadImage.scale(img, options));
  2033. return dfd.promise();
  2034. }
  2035. return data;
  2036. },
  2037. saveImage: function (data, options) {
  2038. if (!data.canvas || options.disabled) {
  2039. return data;
  2040. }
  2041. var that = this,
  2042. file = data.files[data.index],
  2043. dfd = $.Deferred();
  2044. if (data.canvas.toBlob) {
  2045. data.canvas.toBlob(
  2046. function (blob) {
  2047. if (!blob.name) {
  2048. if (file.type === blob.type) {
  2049. blob.name = file.name;
  2050. } else if (file.name) {
  2051. blob.name = file.name.replace(
  2052. /\.\w+$/,
  2053. '.' + blob.type.substr(6)
  2054. );
  2055. }
  2056. }
  2057. if (file.type !== blob.type) {
  2058. delete data.imageHead;
  2059. }
  2060. data.files[data.index] = blob;
  2061. dfd.resolveWith(that, [data]);
  2062. },
  2063. options.type || file.type,
  2064. options.quality
  2065. );
  2066. } else {
  2067. return data;
  2068. }
  2069. return dfd.promise();
  2070. },
  2071. loadImageMetaData: function (data, options) {
  2072. if (options.disabled) {
  2073. return data;
  2074. }
  2075. var that = this,
  2076. dfd = $.Deferred();
  2077. loadImage.parseMetaData(data.files[data.index], function (result) {
  2078. $.extend(data, result);
  2079. dfd.resolveWith(that, [data]);
  2080. }, options);
  2081. return dfd.promise();
  2082. },
  2083. saveImageMetaData: function (data, options) {
  2084. if (!(data.imageHead && data.canvas &&
  2085. data.canvas.toBlob && !options.disabled)) {
  2086. return data;
  2087. }
  2088. var file = data.files[data.index],
  2089. blob = new Blob([
  2090. data.imageHead,
  2091. this._blobSlice.call(file, 20)
  2092. ], {type: file.type});
  2093. blob.name = file.name;
  2094. data.files[data.index] = blob;
  2095. return data;
  2096. },
  2097. setImage: function (data, options) {
  2098. if (data.preview && !options.disabled) {
  2099. data.files[data.index][options.name || 'preview'] = data.preview;
  2100. }
  2101. return data;
  2102. },
  2103. deleteImageReferences: function (data, options) {
  2104. if (!options.disabled) {
  2105. delete data.img;
  2106. delete data.canvas;
  2107. delete data.preview;
  2108. delete data.imageHead;
  2109. }
  2110. return data;
  2111. }
  2112. }
  2113. });
  2114. }));
  2115. /*
  2116. * jquery.fileupload-validate.js
  2117. */
  2118. (function (factory) {
  2119. 'use strict';
  2120. if (typeof define === 'function' && define.amd) {
  2121. define([
  2122. 'jquery',
  2123. './jquery.fileupload-process'
  2124. ], factory);
  2125. } else if (typeof exports === 'object') {
  2126. factory(require('jquery'));
  2127. } else {
  2128. factory(
  2129. window.jQuery
  2130. );
  2131. }
  2132. }(function ($) {
  2133. 'use strict';
  2134. $.blueimp.fileupload.prototype.options.processQueue.push(
  2135. {
  2136. action: 'validate',
  2137. always: true,
  2138. acceptFileTypes: '@',
  2139. maxFileSize: '@',
  2140. minFileSize: '@',
  2141. maxNumberOfFiles: '@',
  2142. disabled: '@disableValidation'
  2143. }
  2144. );
  2145. $.widget('blueimp.fileupload', $.blueimp.fileupload, {
  2146. options: {
  2147. getNumberOfFiles: $.noop,
  2148. messages: {
  2149. maxNumberOfFiles: 'Maximum number of files exceeded',
  2150. acceptFileTypes: 'File type not allowed',
  2151. maxFileSize: 'File is too large',
  2152. minFileSize: 'File is too small'
  2153. }
  2154. },
  2155. processActions: {
  2156. validate: function (data, options) {
  2157. if (options.disabled) {
  2158. return data;
  2159. }
  2160. var dfd = $.Deferred(),
  2161. settings = this.options,
  2162. file = data.files[data.index],
  2163. fileSize;
  2164. if (options.minFileSize || options.maxFileSize) {
  2165. fileSize = file.size;
  2166. }
  2167. if ($.type(options.maxNumberOfFiles) === 'number' &&
  2168. (settings.getNumberOfFiles() || 0) + data.files.length >
  2169. options.maxNumberOfFiles) {
  2170. file.error = settings.i18n('maxNumberOfFiles');
  2171. } else if (options.acceptFileTypes &&
  2172. !(options.acceptFileTypes.test(file.type) ||
  2173. options.acceptFileTypes.test(file.name))) {
  2174. file.error = settings.i18n('acceptFileTypes');
  2175. } else if (fileSize > options.maxFileSize) {
  2176. file.error = settings.i18n('maxFileSize');
  2177. } else if ($.type(fileSize) === 'number' &&
  2178. fileSize < options.minFileSize) {
  2179. file.error = settings.i18n('minFileSize');
  2180. } else {
  2181. delete file.error;
  2182. }
  2183. if (file.error || data.files.error) {
  2184. data.files.error = true;
  2185. dfd.rejectWith(this, [data]);
  2186. } else {
  2187. dfd.resolveWith(this, [data]);
  2188. }
  2189. return dfd.promise();
  2190. }
  2191. }
  2192. });
  2193. }));