dropzone.js 132 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851
  1. // Uses AMD or browser globals to create a jQuery plugin.
  2. (function (factory) {
  3. if (typeof define === 'function' && define.amd) {
  4. // AMD. Register as an anonymous module.
  5. define(['jquery'], factory);
  6. } else {
  7. // Browser globals
  8. factory(jQuery);
  9. }
  10. } (function (jQuery) {
  11. var module = { exports: { } }; // Fake component
  12. "use strict";
  13. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  14. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  15. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  16. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  17. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  18. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  19. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  20. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  21. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  22. /*
  23. *
  24. * More info at [www.dropzonejs.com](http://www.dropzonejs.com)
  25. *
  26. * Copyright (c) 2012, Matias Meno
  27. *
  28. * Permission is hereby granted, free of charge, to any person obtaining a copy
  29. * of this software and associated documentation files (the "Software"), to deal
  30. * in the Software without restriction, including without limitation the rights
  31. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  32. * copies of the Software, and to permit persons to whom the Software is
  33. * furnished to do so, subject to the following conditions:
  34. *
  35. * The above copyright notice and this permission notice shall be included in
  36. * all copies or substantial portions of the Software.
  37. *
  38. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  39. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  40. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  41. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  42. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  43. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  44. * THE SOFTWARE.
  45. *
  46. */
  47. // The Emitter class provides the ability to call `.on()` on Dropzone to listen
  48. // to events.
  49. // It is strongly based on component's emitter class, and I removed the
  50. // functionality because of the dependency hell with different frameworks.
  51. var Emitter =
  52. /*#__PURE__*/
  53. function () {
  54. function Emitter() {
  55. _classCallCheck(this, Emitter);
  56. }
  57. _createClass(Emitter, [{
  58. key: "on",
  59. // Add an event listener for given event
  60. value: function on(event, fn) {
  61. this._callbacks = this._callbacks || {}; // Create namespace for this event
  62. if (!this._callbacks[event]) {
  63. this._callbacks[event] = [];
  64. }
  65. this._callbacks[event].push(fn);
  66. return this;
  67. }
  68. }, {
  69. key: "emit",
  70. value: function emit(event) {
  71. this._callbacks = this._callbacks || {};
  72. var callbacks = this._callbacks[event];
  73. if (callbacks) {
  74. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  75. args[_key - 1] = arguments[_key];
  76. }
  77. var _iteratorNormalCompletion = true;
  78. var _didIteratorError = false;
  79. var _iteratorError = undefined;
  80. try {
  81. for (var _iterator = callbacks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  82. var callback = _step.value;
  83. callback.apply(this, args);
  84. }
  85. } catch (err) {
  86. _didIteratorError = true;
  87. _iteratorError = err;
  88. } finally {
  89. try {
  90. if (!_iteratorNormalCompletion && _iterator["return"] != null) {
  91. _iterator["return"]();
  92. }
  93. } finally {
  94. if (_didIteratorError) {
  95. throw _iteratorError;
  96. }
  97. }
  98. }
  99. }
  100. return this;
  101. } // Remove event listener for given event. If fn is not provided, all event
  102. // listeners for that event will be removed. If neither is provided, all
  103. // event listeners will be removed.
  104. }, {
  105. key: "off",
  106. value: function off(event, fn) {
  107. if (!this._callbacks || arguments.length === 0) {
  108. this._callbacks = {};
  109. return this;
  110. } // specific event
  111. var callbacks = this._callbacks[event];
  112. if (!callbacks) {
  113. return this;
  114. } // remove all handlers
  115. if (arguments.length === 1) {
  116. delete this._callbacks[event];
  117. return this;
  118. } // remove specific handler
  119. for (var i = 0; i < callbacks.length; i++) {
  120. var callback = callbacks[i];
  121. if (callback === fn) {
  122. callbacks.splice(i, 1);
  123. break;
  124. }
  125. }
  126. return this;
  127. }
  128. }]);
  129. return Emitter;
  130. }();
  131. var Dropzone =
  132. /*#__PURE__*/
  133. function (_Emitter) {
  134. _inherits(Dropzone, _Emitter);
  135. _createClass(Dropzone, null, [{
  136. key: "initClass",
  137. value: function initClass() {
  138. // Exposing the emitter class, mainly for tests
  139. this.prototype.Emitter = Emitter;
  140. /*
  141. This is a list of all available events you can register on a dropzone object.
  142. You can register an event handler like this:
  143. dropzone.on("dragEnter", function() { });
  144. */
  145. this.prototype.events = ["drop", "dragstart", "dragend", "dragenter", "dragover", "dragleave", "addedfile", "addedfiles", "removedfile", "thumbnail", "error", "errormultiple", "processing", "processingmultiple", "uploadprogress", "totaluploadprogress", "sending", "sendingmultiple", "success", "successmultiple", "canceled", "canceledmultiple", "complete", "completemultiple", "reset", "maxfilesexceeded", "maxfilesreached", "queuecomplete"];
  146. this.prototype.defaultOptions = {
  147. /**
  148. * Has to be specified on elements other than form (or when the form
  149. * doesn't have an `action` attribute). You can also
  150. * provide a function that will be called with `files` and
  151. * must return the url (since `v3.12.0`)
  152. */
  153. url: null,
  154. /**
  155. * Can be changed to `"put"` if necessary. You can also provide a function
  156. * that will be called with `files` and must return the method (since `v3.12.0`).
  157. */
  158. method: "post",
  159. /**
  160. * Will be set on the XHRequest.
  161. */
  162. withCredentials: false,
  163. /**
  164. * The timeout for the XHR requests in milliseconds (since `v4.4.0`).
  165. */
  166. timeout: 30000,
  167. /**
  168. * How many file uploads to process in parallel (See the
  169. * Enqueuing file uploads documentation section for more info)
  170. */
  171. parallelUploads: 2,
  172. /**
  173. * Whether to send multiple files in one request. If
  174. * this it set to true, then the fallback file input element will
  175. * have the `multiple` attribute as well. This option will
  176. * also trigger additional events (like `processingmultiple`). See the events
  177. * documentation section for more information.
  178. */
  179. uploadMultiple: false,
  180. /**
  181. * Whether you want files to be uploaded in chunks to your server. This can't be
  182. * used in combination with `uploadMultiple`.
  183. *
  184. * See [chunksUploaded](#config-chunksUploaded) for the callback to finalise an upload.
  185. */
  186. chunking: false,
  187. /**
  188. * If `chunking` is enabled, this defines whether **every** file should be chunked,
  189. * even if the file size is below chunkSize. This means, that the additional chunk
  190. * form data will be submitted and the `chunksUploaded` callback will be invoked.
  191. */
  192. forceChunking: false,
  193. /**
  194. * If `chunking` is `true`, then this defines the chunk size in bytes.
  195. */
  196. chunkSize: 2000000,
  197. /**
  198. * If `true`, the individual chunks of a file are being uploaded simultaneously.
  199. */
  200. parallelChunkUploads: false,
  201. /**
  202. * Whether a chunk should be retried if it fails.
  203. */
  204. retryChunks: false,
  205. /**
  206. * If `retryChunks` is true, how many times should it be retried.
  207. */
  208. retryChunksLimit: 3,
  209. /**
  210. * If not `null` defines how many files this Dropzone handles. If it exceeds,
  211. * the event `maxfilesexceeded` will be called. The dropzone element gets the
  212. * class `dz-max-files-reached` accordingly so you can provide visual feedback.
  213. */
  214. maxFilesize: 256,
  215. /**
  216. * The name of the file param that gets transferred.
  217. * **NOTE**: If you have the option `uploadMultiple` set to `true`, then
  218. * Dropzone will append `[]` to the name.
  219. */
  220. paramName: "file",
  221. /**
  222. * Whether thumbnails for images should be generated
  223. */
  224. createImageThumbnails: true,
  225. /**
  226. * In MB. When the filename exceeds this limit, the thumbnail will not be generated.
  227. */
  228. maxThumbnailFilesize: 10,
  229. /**
  230. * If `null`, the ratio of the image will be used to calculate it.
  231. */
  232. thumbnailWidth: 120,
  233. /**
  234. * The same as `thumbnailWidth`. If both are null, images will not be resized.
  235. */
  236. thumbnailHeight: 120,
  237. /**
  238. * How the images should be scaled down in case both, `thumbnailWidth` and `thumbnailHeight` are provided.
  239. * Can be either `contain` or `crop`.
  240. */
  241. thumbnailMethod: 'crop',
  242. /**
  243. * If set, images will be resized to these dimensions before being **uploaded**.
  244. * If only one, `resizeWidth` **or** `resizeHeight` is provided, the original aspect
  245. * ratio of the file will be preserved.
  246. *
  247. * The `options.transformFile` function uses these options, so if the `transformFile` function
  248. * is overridden, these options don't do anything.
  249. */
  250. resizeWidth: null,
  251. /**
  252. * See `resizeWidth`.
  253. */
  254. resizeHeight: null,
  255. /**
  256. * The mime type of the resized image (before it gets uploaded to the server).
  257. * If `null` the original mime type will be used. To force jpeg, for example, use `image/jpeg`.
  258. * See `resizeWidth` for more information.
  259. */
  260. resizeMimeType: null,
  261. /**
  262. * The quality of the resized images. See `resizeWidth`.
  263. */
  264. resizeQuality: 0.8,
  265. /**
  266. * How the images should be scaled down in case both, `resizeWidth` and `resizeHeight` are provided.
  267. * Can be either `contain` or `crop`.
  268. */
  269. resizeMethod: 'contain',
  270. /**
  271. * The base that is used to calculate the filesize. You can change this to
  272. * 1024 if you would rather display kibibytes, mebibytes, etc...
  273. * 1024 is technically incorrect, because `1024 bytes` are `1 kibibyte` not `1 kilobyte`.
  274. * You can change this to `1024` if you don't care about validity.
  275. */
  276. filesizeBase: 1000,
  277. /**
  278. * Can be used to limit the maximum number of files that will be handled by this Dropzone
  279. */
  280. maxFiles: null,
  281. /**
  282. * An optional object to send additional headers to the server. Eg:
  283. * `{ "My-Awesome-Header": "header value" }`
  284. */
  285. headers: null,
  286. /**
  287. * If `true`, the dropzone element itself will be clickable, if `false`
  288. * nothing will be clickable.
  289. *
  290. * You can also pass an HTML element, a CSS selector (for multiple elements)
  291. * or an array of those. In that case, all of those elements will trigger an
  292. * upload when clicked.
  293. */
  294. clickable: true,
  295. /**
  296. * Whether hidden files in directories should be ignored.
  297. */
  298. ignoreHiddenFiles: true,
  299. /**
  300. * The default implementation of `accept` checks the file's mime type or
  301. * extension against this list. This is a comma separated list of mime
  302. * types or file extensions.
  303. *
  304. * Eg.: `image/*,application/pdf,.psd`
  305. *
  306. * If the Dropzone is `clickable` this option will also be used as
  307. * [`accept`](https://developer.mozilla.org/en-US/docs/HTML/Element/input#attr-accept)
  308. * parameter on the hidden file input as well.
  309. */
  310. acceptedFiles: null,
  311. /**
  312. * **Deprecated!**
  313. * Use acceptedFiles instead.
  314. */
  315. acceptedMimeTypes: null,
  316. /**
  317. * If false, files will be added to the queue but the queue will not be
  318. * processed automatically.
  319. * This can be useful if you need some additional user input before sending
  320. * files (or if you want want all files sent at once).
  321. * If you're ready to send the file simply call `myDropzone.processQueue()`.
  322. *
  323. * See the [enqueuing file uploads](#enqueuing-file-uploads) documentation
  324. * section for more information.
  325. */
  326. autoProcessQueue: true,
  327. /**
  328. * If false, files added to the dropzone will not be queued by default.
  329. * You'll have to call `enqueueFile(file)` manually.
  330. */
  331. autoQueue: true,
  332. /**
  333. * If `true`, this will add a link to every file preview to remove or cancel (if
  334. * already uploading) the file. The `dictCancelUpload`, `dictCancelUploadConfirmation`
  335. * and `dictRemoveFile` options are used for the wording.
  336. */
  337. addRemoveLinks: false,
  338. /**
  339. * Defines where to display the file previews – if `null` the
  340. * Dropzone element itself is used. Can be a plain `HTMLElement` or a CSS
  341. * selector. The element should have the `dropzone-previews` class so
  342. * the previews are displayed properly.
  343. */
  344. previewsContainer: null,
  345. /**
  346. * This is the element the hidden input field (which is used when clicking on the
  347. * dropzone to trigger file selection) will be appended to. This might
  348. * be important in case you use frameworks to switch the content of your page.
  349. *
  350. * Can be a selector string, or an element directly.
  351. */
  352. hiddenInputContainer: "body",
  353. /**
  354. * If null, no capture type will be specified
  355. * If camera, mobile devices will skip the file selection and choose camera
  356. * If microphone, mobile devices will skip the file selection and choose the microphone
  357. * If camcorder, mobile devices will skip the file selection and choose the camera in video mode
  358. * On apple devices multiple must be set to false. AcceptedFiles may need to
  359. * be set to an appropriate mime type (e.g. "image/*", "audio/*", or "video/*").
  360. */
  361. capture: null,
  362. /**
  363. * **Deprecated**. Use `renameFile` instead.
  364. */
  365. renameFilename: null,
  366. /**
  367. * A function that is invoked before the file is uploaded to the server and renames the file.
  368. * This function gets the `File` as argument and can use the `file.name`. The actual name of the
  369. * file that gets used during the upload can be accessed through `file.upload.filename`.
  370. */
  371. renameFile: null,
  372. /**
  373. * If `true` the fallback will be forced. This is very useful to test your server
  374. * implementations first and make sure that everything works as
  375. * expected without dropzone if you experience problems, and to test
  376. * how your fallbacks will look.
  377. */
  378. forceFallback: false,
  379. /**
  380. * The text used before any files are dropped.
  381. */
  382. dictDefaultMessage: "Drop files here to upload",
  383. /**
  384. * The text that replaces the default message text it the browser is not supported.
  385. */
  386. dictFallbackMessage: "Your browser does not support drag'n'drop file uploads.",
  387. /**
  388. * The text that will be added before the fallback form.
  389. * If you provide a fallback element yourself, or if this option is `null` this will
  390. * be ignored.
  391. */
  392. dictFallbackText: "Please use the fallback form below to upload your files like in the olden days.",
  393. /**
  394. * If the filesize is too big.
  395. * `{{filesize}}` and `{{maxFilesize}}` will be replaced with the respective configuration values.
  396. */
  397. dictFileTooBig: "File is too big ({{filesize}}MiB). Max filesize: {{maxFilesize}}MiB.",
  398. /**
  399. * If the file doesn't match the file type.
  400. */
  401. dictInvalidFileType: "You can't upload files of this type.",
  402. /**
  403. * If the server response was invalid.
  404. * `{{statusCode}}` will be replaced with the servers status code.
  405. */
  406. dictResponseError: "Server responded with {{statusCode}} code.",
  407. /**
  408. * If `addRemoveLinks` is true, the text to be used for the cancel upload link.
  409. */
  410. dictCancelUpload: "Cancel upload",
  411. /**
  412. * The text that is displayed if an upload was manually canceled
  413. */
  414. dictUploadCanceled: "Upload canceled.",
  415. /**
  416. * If `addRemoveLinks` is true, the text to be used for confirmation when cancelling upload.
  417. */
  418. dictCancelUploadConfirmation: "Are you sure you want to cancel this upload?",
  419. /**
  420. * If `addRemoveLinks` is true, the text to be used to remove a file.
  421. */
  422. dictRemoveFile: "Remove file",
  423. /**
  424. * If this is not null, then the user will be prompted before removing a file.
  425. */
  426. dictRemoveFileConfirmation: null,
  427. /**
  428. * Displayed if `maxFiles` is st and exceeded.
  429. * The string `{{maxFiles}}` will be replaced by the configuration value.
  430. */
  431. dictMaxFilesExceeded: "You can not upload any more files.",
  432. /**
  433. * Allows you to translate the different units. Starting with `tb` for terabytes and going down to
  434. * `b` for bytes.
  435. */
  436. dictFileSizeUnits: {
  437. tb: "TB",
  438. gb: "GB",
  439. mb: "MB",
  440. kb: "KB",
  441. b: "b"
  442. },
  443. /**
  444. * Called when dropzone initialized
  445. * You can add event listeners here
  446. */
  447. init: function init() {},
  448. /**
  449. * Can be an **object** of additional parameters to transfer to the server, **or** a `Function`
  450. * that gets invoked with the `files`, `xhr` and, if it's a chunked upload, `chunk` arguments. In case
  451. * of a function, this needs to return a map.
  452. *
  453. * The default implementation does nothing for normal uploads, but adds relevant information for
  454. * chunked uploads.
  455. *
  456. * This is the same as adding hidden input fields in the form element.
  457. */
  458. params: function params(files, xhr, chunk) {
  459. if (chunk) {
  460. return {
  461. dzuuid: chunk.file.upload.uuid,
  462. dzchunkindex: chunk.index,
  463. dztotalfilesize: chunk.file.size,
  464. dzchunksize: this.options.chunkSize,
  465. dztotalchunkcount: chunk.file.upload.totalChunkCount,
  466. dzchunkbyteoffset: chunk.index * this.options.chunkSize
  467. };
  468. }
  469. },
  470. /**
  471. * A function that gets a [file](https://developer.mozilla.org/en-US/docs/DOM/File)
  472. * and a `done` function as parameters.
  473. *
  474. * If the done function is invoked without arguments, the file is "accepted" and will
  475. * be processed. If you pass an error message, the file is rejected, and the error
  476. * message will be displayed.
  477. * This function will not be called if the file is too big or doesn't match the mime types.
  478. */
  479. accept: function accept(file, done) {
  480. return done();
  481. },
  482. chunkSuccess: function(chunk, file, response){},
  483. /**
  484. * The callback that will be invoked when all chunks have been uploaded for a file.
  485. * It gets the file for which the chunks have been uploaded as the first parameter,
  486. * and the `done` function as second. `done()` needs to be invoked when everything
  487. * needed to finish the upload process is done.
  488. */
  489. chunksUploaded: function chunksUploaded(file, done) {
  490. done();
  491. },
  492. /**
  493. * Gets called when the browser is not supported.
  494. * The default implementation shows the fallback input field and adds
  495. * a text.
  496. */
  497. fallback: function fallback() {
  498. // This code should pass in IE7... :(
  499. var messageElement;
  500. this.element.className = "".concat(this.element.className, " dz-browser-not-supported");
  501. var _iteratorNormalCompletion2 = true;
  502. var _didIteratorError2 = false;
  503. var _iteratorError2 = undefined;
  504. try {
  505. for (var _iterator2 = this.element.getElementsByTagName("div")[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  506. var child = _step2.value;
  507. if (/(^| )dz-message($| )/.test(child.className)) {
  508. messageElement = child;
  509. child.className = "dz-message"; // Removes the 'dz-default' class
  510. break;
  511. }
  512. }
  513. } catch (err) {
  514. _didIteratorError2 = true;
  515. _iteratorError2 = err;
  516. } finally {
  517. try {
  518. if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
  519. _iterator2["return"]();
  520. }
  521. } finally {
  522. if (_didIteratorError2) {
  523. throw _iteratorError2;
  524. }
  525. }
  526. }
  527. if (!messageElement) {
  528. messageElement = Dropzone.createElement("<div class=\"dz-message\"><span></span></div>");
  529. this.element.appendChild(messageElement);
  530. }
  531. var span = messageElement.getElementsByTagName("span")[0];
  532. if (span) {
  533. if (span.textContent != null) {
  534. span.textContent = this.options.dictFallbackMessage;
  535. } else if (span.innerText != null) {
  536. span.innerText = this.options.dictFallbackMessage;
  537. }
  538. }
  539. return this.element.appendChild(this.getFallbackForm());
  540. },
  541. /**
  542. * Gets called to calculate the thumbnail dimensions.
  543. *
  544. * It gets `file`, `width` and `height` (both may be `null`) as parameters and must return an object containing:
  545. *
  546. * - `srcWidth` & `srcHeight` (required)
  547. * - `trgWidth` & `trgHeight` (required)
  548. * - `srcX` & `srcY` (optional, default `0`)
  549. * - `trgX` & `trgY` (optional, default `0`)
  550. *
  551. * Those values are going to be used by `ctx.drawImage()`.
  552. */
  553. resize: function resize(file, width, height, resizeMethod) {
  554. var info = {
  555. srcX: 0,
  556. srcY: 0,
  557. srcWidth: file.width,
  558. srcHeight: file.height
  559. };
  560. var srcRatio = file.width / file.height; // Automatically calculate dimensions if not specified
  561. if (width == null && height == null) {
  562. width = info.srcWidth;
  563. height = info.srcHeight;
  564. } else if (width == null) {
  565. width = height * srcRatio;
  566. } else if (height == null) {
  567. height = width / srcRatio;
  568. } // Make sure images aren't upscaled
  569. width = Math.min(width, info.srcWidth);
  570. height = Math.min(height, info.srcHeight);
  571. var trgRatio = width / height;
  572. if (info.srcWidth > width || info.srcHeight > height) {
  573. // Image is bigger and needs rescaling
  574. if (resizeMethod === 'crop') {
  575. if (srcRatio > trgRatio) {
  576. info.srcHeight = file.height;
  577. info.srcWidth = info.srcHeight * trgRatio;
  578. } else {
  579. info.srcWidth = file.width;
  580. info.srcHeight = info.srcWidth / trgRatio;
  581. }
  582. } else if (resizeMethod === 'contain') {
  583. // Method 'contain'
  584. if (srcRatio > trgRatio) {
  585. height = width / srcRatio;
  586. } else {
  587. width = height * srcRatio;
  588. }
  589. } else {
  590. throw new Error("Unknown resizeMethod '".concat(resizeMethod, "'"));
  591. }
  592. }
  593. info.srcX = (file.width - info.srcWidth) / 2;
  594. info.srcY = (file.height - info.srcHeight) / 2;
  595. info.trgWidth = width;
  596. info.trgHeight = height;
  597. return info;
  598. },
  599. /**
  600. * Can be used to transform the file (for example, resize an image if necessary).
  601. *
  602. * The default implementation uses `resizeWidth` and `resizeHeight` (if provided) and resizes
  603. * images according to those dimensions.
  604. *
  605. * Gets the `file` as the first parameter, and a `done()` function as the second, that needs
  606. * to be invoked with the file when the transformation is done.
  607. */
  608. transformFile: function transformFile(file, done) {
  609. if ((this.options.resizeWidth || this.options.resizeHeight) && file.type.match(/image.*/)) {
  610. return this.resizeImage(file, this.options.resizeWidth, this.options.resizeHeight, this.options.resizeMethod, done);
  611. } else {
  612. return done(file);
  613. }
  614. },
  615. /**
  616. * A string that contains the template used for each dropped
  617. * file. Change it to fulfill your needs but make sure to properly
  618. * provide all elements.
  619. *
  620. * If you want to use an actual HTML element instead of providing a String
  621. * as a config option, you could create a div with the id `tpl`,
  622. * put the template inside it and provide the element like this:
  623. *
  624. * document
  625. * .querySelector('#tpl')
  626. * .innerHTML
  627. *
  628. */
  629. previewTemplate: "<div class=\"dz-preview dz-file-preview\">\n <div class=\"dz-image\"><img data-dz-thumbnail /></div>\n <div class=\"dz-details\">\n <div class=\"dz-size\"><span data-dz-size></span></div>\n <div class=\"dz-filename\"><span data-dz-name></span></div>\n </div>\n <div class=\"dz-progress\"><span class=\"dz-upload\" data-dz-uploadprogress></span></div>\n <div class=\"dz-error-message\"><span data-dz-errormessage></span></div>\n <div class=\"dz-success-mark\">\n <svg width=\"54px\" height=\"54px\" viewBox=\"0 0 54 54\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <title>Check</title>\n <g stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n <path d=\"M23.5,31.8431458 L17.5852419,25.9283877 C16.0248253,24.3679711 13.4910294,24.366835 11.9289322,25.9289322 C10.3700136,27.4878508 10.3665912,30.0234455 11.9283877,31.5852419 L20.4147581,40.0716123 C20.5133999,40.1702541 20.6159315,40.2626649 20.7218615,40.3488435 C22.2835669,41.8725651 24.794234,41.8626202 26.3461564,40.3106978 L43.3106978,23.3461564 C44.8771021,21.7797521 44.8758057,19.2483887 43.3137085,17.6862915 C41.7547899,16.1273729 39.2176035,16.1255422 37.6538436,17.6893022 L23.5,31.8431458 Z M27,53 C41.3594035,53 53,41.3594035 53,27 C53,12.6405965 41.3594035,1 27,1 C12.6405965,1 1,12.6405965 1,27 C1,41.3594035 12.6405965,53 27,53 Z\" stroke-opacity=\"0.198794158\" stroke=\"#747474\" fill-opacity=\"0.816519475\" fill=\"#FFFFFF\"></path>\n </g>\n </svg>\n </div>\n <div class=\"dz-error-mark\">\n <svg width=\"54px\" height=\"54px\" viewBox=\"0 0 54 54\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <title>Error</title>\n <g stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n <g stroke=\"#747474\" stroke-opacity=\"0.198794158\" fill=\"#FFFFFF\" fill-opacity=\"0.816519475\">\n <path d=\"M32.6568542,29 L38.3106978,23.3461564 C39.8771021,21.7797521 39.8758057,19.2483887 38.3137085,17.6862915 C36.7547899,16.1273729 34.2176035,16.1255422 32.6538436,17.6893022 L27,23.3431458 L21.3461564,17.6893022 C19.7823965,16.1255422 17.2452101,16.1273729 15.6862915,17.6862915 C14.1241943,19.2483887 14.1228979,21.7797521 15.6893022,23.3461564 L21.3431458,29 L15.6893022,34.6538436 C14.1228979,36.2202479 14.1241943,38.7516113 15.6862915,40.3137085 C17.2452101,41.8726271 19.7823965,41.8744578 21.3461564,40.3106978 L27,34.6568542 L32.6538436,40.3106978 C34.2176035,41.8744578 36.7547899,41.8726271 38.3137085,40.3137085 C39.8758057,38.7516113 39.8771021,36.2202479 38.3106978,34.6538436 L32.6568542,29 Z M27,53 C41.3594035,53 53,41.3594035 53,27 C53,12.6405965 41.3594035,1 27,1 C12.6405965,1 1,12.6405965 1,27 C1,41.3594035 12.6405965,53 27,53 Z\"></path>\n </g>\n </g>\n </svg>\n </div>\n</div>",
  630. // END OPTIONS
  631. // (Required by the dropzone documentation parser)
  632. /*
  633. Those functions register themselves to the events on init and handle all
  634. the user interface specific stuff. Overwriting them won't break the upload
  635. but can break the way it's displayed.
  636. You can overwrite them if you don't like the default behavior. If you just
  637. want to add an additional event handler, register it on the dropzone object
  638. and don't overwrite those options.
  639. */
  640. // Those are self explanatory and simply concern the DragnDrop.
  641. drop: function drop(e) {
  642. return this.element.classList.remove("dz-drag-hover");
  643. },
  644. dragstart: function dragstart(e) {},
  645. dragend: function dragend(e) {
  646. return this.element.classList.remove("dz-drag-hover");
  647. },
  648. dragenter: function dragenter(e) {
  649. return this.element.classList.add("dz-drag-hover");
  650. },
  651. dragover: function dragover(e) {
  652. return this.element.classList.add("dz-drag-hover");
  653. },
  654. dragleave: function dragleave(e) {
  655. return this.element.classList.remove("dz-drag-hover");
  656. },
  657. paste: function paste(e) {},
  658. // Called whenever there are no files left in the dropzone anymore, and the
  659. // dropzone should be displayed as if in the initial state.
  660. reset: function reset() {
  661. return this.element.classList.remove("dz-started");
  662. },
  663. // Called when a file is added to the queue
  664. // Receives `file`
  665. addedfile: function addedfile(file) {
  666. var _this2 = this;
  667. if (this.element === this.previewsContainer) {
  668. this.element.classList.add("dz-started");
  669. }
  670. if (this.previewsContainer) {
  671. file.previewElement = Dropzone.createElement(this.options.previewTemplate.trim());
  672. file.previewTemplate = file.previewElement; // Backwards compatibility
  673. this.previewsContainer.appendChild(file.previewElement);
  674. var _iteratorNormalCompletion3 = true;
  675. var _didIteratorError3 = false;
  676. var _iteratorError3 = undefined;
  677. try {
  678. for (var _iterator3 = file.previewElement.querySelectorAll("[data-dz-name]")[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  679. var node = _step3.value;
  680. node.textContent = file.name;
  681. }
  682. } catch (err) {
  683. _didIteratorError3 = true;
  684. _iteratorError3 = err;
  685. } finally {
  686. try {
  687. if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) {
  688. _iterator3["return"]();
  689. }
  690. } finally {
  691. if (_didIteratorError3) {
  692. throw _iteratorError3;
  693. }
  694. }
  695. }
  696. var _iteratorNormalCompletion4 = true;
  697. var _didIteratorError4 = false;
  698. var _iteratorError4 = undefined;
  699. try {
  700. for (var _iterator4 = file.previewElement.querySelectorAll("[data-dz-size]")[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
  701. node = _step4.value;
  702. node.innerHTML = this.filesize(file.size);
  703. }
  704. } catch (err) {
  705. _didIteratorError4 = true;
  706. _iteratorError4 = err;
  707. } finally {
  708. try {
  709. if (!_iteratorNormalCompletion4 && _iterator4["return"] != null) {
  710. _iterator4["return"]();
  711. }
  712. } finally {
  713. if (_didIteratorError4) {
  714. throw _iteratorError4;
  715. }
  716. }
  717. }
  718. if (this.options.addRemoveLinks) {
  719. file._removeLink = Dropzone.createElement("<a class=\"dz-remove\" href=\"javascript:undefined;\" data-dz-remove>".concat(this.options.dictRemoveFile, "</a>"));
  720. file.previewElement.appendChild(file._removeLink);
  721. }
  722. var removeFileEvent = function removeFileEvent(e) {
  723. e.preventDefault();
  724. e.stopPropagation();
  725. if (file.status === Dropzone.UPLOADING) {
  726. return Dropzone.confirm(_this2.options.dictCancelUploadConfirmation, function () {
  727. return _this2.removeFile(file);
  728. });
  729. } else {
  730. if (_this2.options.dictRemoveFileConfirmation) {
  731. return Dropzone.confirm(_this2.options.dictRemoveFileConfirmation, function () {
  732. return _this2.removeFile(file);
  733. });
  734. } else {
  735. return _this2.removeFile(file);
  736. }
  737. }
  738. };
  739. var _iteratorNormalCompletion5 = true;
  740. var _didIteratorError5 = false;
  741. var _iteratorError5 = undefined;
  742. try {
  743. for (var _iterator5 = file.previewElement.querySelectorAll("[data-dz-remove]")[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
  744. var removeLink = _step5.value;
  745. removeLink.addEventListener("click", removeFileEvent);
  746. }
  747. } catch (err) {
  748. _didIteratorError5 = true;
  749. _iteratorError5 = err;
  750. } finally {
  751. try {
  752. if (!_iteratorNormalCompletion5 && _iterator5["return"] != null) {
  753. _iterator5["return"]();
  754. }
  755. } finally {
  756. if (_didIteratorError5) {
  757. throw _iteratorError5;
  758. }
  759. }
  760. }
  761. }
  762. },
  763. // Called whenever a file is removed.
  764. removedfile: function removedfile(file) {
  765. if (file.previewElement != null && file.previewElement.parentNode != null) {
  766. file.previewElement.parentNode.removeChild(file.previewElement);
  767. }
  768. return this._updateMaxFilesReachedClass();
  769. },
  770. // Called when a thumbnail has been generated
  771. // Receives `file` and `dataUrl`
  772. thumbnail: function thumbnail(file, dataUrl) {
  773. if (file.previewElement) {
  774. file.previewElement.classList.remove("dz-file-preview");
  775. var _iteratorNormalCompletion6 = true;
  776. var _didIteratorError6 = false;
  777. var _iteratorError6 = undefined;
  778. try {
  779. for (var _iterator6 = file.previewElement.querySelectorAll("[data-dz-thumbnail]")[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
  780. var thumbnailElement = _step6.value;
  781. thumbnailElement.alt = file.name;
  782. thumbnailElement.src = dataUrl;
  783. }
  784. } catch (err) {
  785. _didIteratorError6 = true;
  786. _iteratorError6 = err;
  787. } finally {
  788. try {
  789. if (!_iteratorNormalCompletion6 && _iterator6["return"] != null) {
  790. _iterator6["return"]();
  791. }
  792. } finally {
  793. if (_didIteratorError6) {
  794. throw _iteratorError6;
  795. }
  796. }
  797. }
  798. return setTimeout(function () {
  799. return file.previewElement.classList.add("dz-image-preview");
  800. }, 1);
  801. }
  802. },
  803. // Called whenever an error occurs
  804. // Receives `file` and `message`
  805. error: function error(file, message) {
  806. if (file.previewElement) {
  807. file.previewElement.classList.add("dz-error");
  808. if (typeof message !== "String" && message.error) {
  809. message = message.error;
  810. }
  811. var _iteratorNormalCompletion7 = true;
  812. var _didIteratorError7 = false;
  813. var _iteratorError7 = undefined;
  814. try {
  815. for (var _iterator7 = file.previewElement.querySelectorAll("[data-dz-errormessage]")[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
  816. var node = _step7.value;
  817. node.textContent = message;
  818. }
  819. } catch (err) {
  820. _didIteratorError7 = true;
  821. _iteratorError7 = err;
  822. } finally {
  823. try {
  824. if (!_iteratorNormalCompletion7 && _iterator7["return"] != null) {
  825. _iterator7["return"]();
  826. }
  827. } finally {
  828. if (_didIteratorError7) {
  829. throw _iteratorError7;
  830. }
  831. }
  832. }
  833. }
  834. },
  835. errormultiple: function errormultiple() {},
  836. // Called when a file gets processed. Since there is a cue, not all added
  837. // files are processed immediately.
  838. // Receives `file`
  839. processing: function processing(file) {
  840. if (file.previewElement) {
  841. file.previewElement.classList.add("dz-processing");
  842. if (file._removeLink) {
  843. return file._removeLink.innerHTML = this.options.dictCancelUpload;
  844. }
  845. }
  846. },
  847. processingmultiple: function processingmultiple() {},
  848. // Called whenever the upload progress gets updated.
  849. // Receives `file`, `progress` (percentage 0-100) and `bytesSent`.
  850. // To get the total number of bytes of the file, use `file.size`
  851. uploadprogress: function uploadprogress(file, progress, bytesSent) {
  852. if (file.previewElement) {
  853. var _iteratorNormalCompletion8 = true;
  854. var _didIteratorError8 = false;
  855. var _iteratorError8 = undefined;
  856. try {
  857. for (var _iterator8 = file.previewElement.querySelectorAll("[data-dz-uploadprogress]")[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
  858. var node = _step8.value;
  859. node.nodeName === 'PROGRESS' ? node.value = progress : node.style.width = "".concat(progress, "%");
  860. }
  861. } catch (err) {
  862. _didIteratorError8 = true;
  863. _iteratorError8 = err;
  864. } finally {
  865. try {
  866. if (!_iteratorNormalCompletion8 && _iterator8["return"] != null) {
  867. _iterator8["return"]();
  868. }
  869. } finally {
  870. if (_didIteratorError8) {
  871. throw _iteratorError8;
  872. }
  873. }
  874. }
  875. }
  876. },
  877. // Called whenever the total upload progress gets updated.
  878. // Called with totalUploadProgress (0-100), totalBytes and totalBytesSent
  879. totaluploadprogress: function totaluploadprogress() {},
  880. // Called just before the file is sent. Gets the `xhr` object as second
  881. // parameter, so you can modify it (for example to add a CSRF token) and a
  882. // `formData` object to add additional information.
  883. sending: function sending() {},
  884. sendingmultiple: function sendingmultiple() {},
  885. // When the complete upload is finished and successful
  886. // Receives `file`
  887. success: function success(file) {
  888. if (file.previewElement) {
  889. return file.previewElement.classList.add("dz-success");
  890. }
  891. },
  892. successmultiple: function successmultiple() {},
  893. // When the upload is canceled.
  894. canceled: function canceled(file) {
  895. return this.emit("error", file, this.options.dictUploadCanceled);
  896. },
  897. canceledmultiple: function canceledmultiple() {},
  898. // When the upload is finished, either with success or an error.
  899. // Receives `file`
  900. complete: function complete(file) {
  901. if (file._removeLink) {
  902. file._removeLink.innerHTML = this.options.dictRemoveFile;
  903. }
  904. if (file.previewElement) {
  905. return file.previewElement.classList.add("dz-complete");
  906. }
  907. },
  908. completemultiple: function completemultiple() {},
  909. maxfilesexceeded: function maxfilesexceeded() {},
  910. maxfilesreached: function maxfilesreached() {},
  911. queuecomplete: function queuecomplete() {},
  912. addedfiles: function addedfiles() {}
  913. };
  914. this.prototype._thumbnailQueue = [];
  915. this.prototype._processingThumbnail = false;
  916. } // global utility
  917. }, {
  918. key: "extend",
  919. value: function extend(target) {
  920. for (var _len2 = arguments.length, objects = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
  921. objects[_key2 - 1] = arguments[_key2];
  922. }
  923. for (var _i = 0, _objects = objects; _i < _objects.length; _i++) {
  924. var object = _objects[_i];
  925. for (var key in object) {
  926. var val = object[key];
  927. target[key] = val;
  928. }
  929. }
  930. return target;
  931. }
  932. }]);
  933. function Dropzone(el, options) {
  934. var _this;
  935. _classCallCheck(this, Dropzone);
  936. _this = _possibleConstructorReturn(this, _getPrototypeOf(Dropzone).call(this));
  937. var fallback, left;
  938. _this.element = el; // For backwards compatibility since the version was in the prototype previously
  939. _this.version = Dropzone.version;
  940. _this.defaultOptions.previewTemplate = _this.defaultOptions.previewTemplate.replace(/\n*/g, "");
  941. _this.clickableElements = [];
  942. _this.listeners = [];
  943. _this.files = []; // All files
  944. if (typeof _this.element === "string") {
  945. _this.element = document.querySelector(_this.element);
  946. } // Not checking if instance of HTMLElement or Element since IE9 is extremely weird.
  947. if (!_this.element || _this.element.nodeType == null) {
  948. throw new Error("Invalid dropzone element.");
  949. }
  950. if (_this.element.dropzone) {
  951. throw new Error("Dropzone already attached.");
  952. } // Now add this dropzone to the instances.
  953. Dropzone.instances.push(_assertThisInitialized(_this)); // Put the dropzone inside the element itself.
  954. _this.element.dropzone = _assertThisInitialized(_this);
  955. var elementOptions = (left = Dropzone.optionsForElement(_this.element)) != null ? left : {};
  956. _this.options = Dropzone.extend({}, _this.defaultOptions, elementOptions, options != null ? options : {}); // If the browser failed, just call the fallback and leave
  957. if (_this.options.forceFallback || !Dropzone.isBrowserSupported()) {
  958. return _possibleConstructorReturn(_this, _this.options.fallback.call(_assertThisInitialized(_this)));
  959. } // @options.url = @element.getAttribute "action" unless @options.url?
  960. if (_this.options.url == null) {
  961. _this.options.url = _this.element.getAttribute("action");
  962. }
  963. if (!_this.options.url) {
  964. throw new Error("No URL provided.");
  965. }
  966. if (_this.options.acceptedFiles && _this.options.acceptedMimeTypes) {
  967. throw new Error("You can't provide both 'acceptedFiles' and 'acceptedMimeTypes'. 'acceptedMimeTypes' is deprecated.");
  968. }
  969. if (_this.options.uploadMultiple && _this.options.chunking) {
  970. throw new Error('You cannot set both: uploadMultiple and chunking.');
  971. } // Backwards compatibility
  972. if (_this.options.acceptedMimeTypes) {
  973. _this.options.acceptedFiles = _this.options.acceptedMimeTypes;
  974. delete _this.options.acceptedMimeTypes;
  975. } // Backwards compatibility
  976. if (_this.options.renameFilename != null) {
  977. _this.options.renameFile = function (file) {
  978. return _this.options.renameFilename.call(_assertThisInitialized(_this), file.name, file);
  979. };
  980. }
  981. _this.options.method = typeof _this.options.method!=='function' ? _this.options.method.toUpperCase() : _this.options.method;
  982. if ((fallback = _this.getExistingFallback()) && fallback.parentNode) {
  983. // Remove the fallback
  984. fallback.parentNode.removeChild(fallback);
  985. } // Display previews in the previewsContainer element or the Dropzone element unless explicitly set to false
  986. if (_this.options.previewsContainer !== false) {
  987. if (_this.options.previewsContainer) {
  988. _this.previewsContainer = Dropzone.getElement(_this.options.previewsContainer, "previewsContainer");
  989. } else {
  990. _this.previewsContainer = _this.element;
  991. }
  992. }
  993. if (_this.options.clickable) {
  994. if (_this.options.clickable === true) {
  995. _this.clickableElements = [_this.element];
  996. } else {
  997. _this.clickableElements = Dropzone.getElements(_this.options.clickable, "clickable");
  998. }
  999. }
  1000. _this.init();
  1001. return _this;
  1002. } // Returns all files that have been accepted
  1003. _createClass(Dropzone, [{
  1004. key: "getAcceptedFiles",
  1005. value: function getAcceptedFiles() {
  1006. return this.files.filter(function (file) {
  1007. return file.accepted;
  1008. }).map(function (file) {
  1009. return file;
  1010. });
  1011. } // Returns all files that have been rejected
  1012. // Not sure when that's going to be useful, but added for completeness.
  1013. }, {
  1014. key: "getRejectedFiles",
  1015. value: function getRejectedFiles() {
  1016. return this.files.filter(function (file) {
  1017. return !file.accepted;
  1018. }).map(function (file) {
  1019. return file;
  1020. });
  1021. }
  1022. }, {
  1023. key: "getFilesWithStatus",
  1024. value: function getFilesWithStatus(status) {
  1025. return this.files.filter(function (file) {
  1026. return file.status === status;
  1027. }).map(function (file) {
  1028. return file;
  1029. });
  1030. } // Returns all files that are in the queue
  1031. }, {
  1032. key: "getQueuedFiles",
  1033. value: function getQueuedFiles() {
  1034. return this.getFilesWithStatus(Dropzone.QUEUED);
  1035. }
  1036. }, {
  1037. key: "getUploadingFiles",
  1038. value: function getUploadingFiles() {
  1039. return this.getFilesWithStatus(Dropzone.UPLOADING);
  1040. }
  1041. }, {
  1042. key: "getAddedFiles",
  1043. value: function getAddedFiles() {
  1044. return this.getFilesWithStatus(Dropzone.ADDED);
  1045. } // Files that are either queued or uploading
  1046. }, {
  1047. key: "getActiveFiles",
  1048. value: function getActiveFiles() {
  1049. return this.files.filter(function (file) {
  1050. return file.status === Dropzone.UPLOADING || file.status === Dropzone.QUEUED;
  1051. }).map(function (file) {
  1052. return file;
  1053. });
  1054. } // The function that gets called when Dropzone is initialized. You
  1055. // can (and should) setup event listeners inside this function.
  1056. }, {
  1057. key: "init",
  1058. value: function init() {
  1059. var _this3 = this;
  1060. // In case it isn't set already
  1061. if (this.element.tagName === "form") {
  1062. this.element.setAttribute("enctype", "multipart/form-data");
  1063. }
  1064. if (this.element.classList.contains("dropzone") && !this.element.querySelector(".dz-message")) {
  1065. this.element.appendChild(Dropzone.createElement("<div class=\"dz-default dz-message\"><button class=\"dz-button\" type=\"button\">".concat(this.options.dictDefaultMessage, "</button></div>")));
  1066. }
  1067. if (this.clickableElements.length) {
  1068. var setupHiddenFileInput = function setupHiddenFileInput() {
  1069. if (_this3.hiddenFileInput) {
  1070. _this3.hiddenFileInput.parentNode.removeChild(_this3.hiddenFileInput);
  1071. }
  1072. _this3.hiddenFileInput = document.createElement("input");
  1073. _this3.hiddenFileInput.setAttribute("type", "file");
  1074. if (_this3.options.maxFiles === null || _this3.options.maxFiles > 1) {
  1075. _this3.hiddenFileInput.setAttribute("multiple", "multiple");
  1076. }
  1077. _this3.hiddenFileInput.className = "dz-hidden-input";
  1078. if (_this3.options.acceptedFiles !== null) {
  1079. _this3.hiddenFileInput.setAttribute("accept", _this3.options.acceptedFiles);
  1080. }
  1081. if (_this3.options.capture !== null) {
  1082. _this3.hiddenFileInput.setAttribute("capture", _this3.options.capture);
  1083. } // Not setting `display="none"` because some browsers don't accept clicks
  1084. // on elements that aren't displayed.
  1085. _this3.hiddenFileInput.style.visibility = "hidden";
  1086. _this3.hiddenFileInput.style.position = "absolute";
  1087. _this3.hiddenFileInput.style.top = "0";
  1088. _this3.hiddenFileInput.style.left = "0";
  1089. _this3.hiddenFileInput.style.height = "0";
  1090. _this3.hiddenFileInput.style.width = "0";
  1091. Dropzone.getElement(_this3.options.hiddenInputContainer, 'hiddenInputContainer').appendChild(_this3.hiddenFileInput);
  1092. return _this3.hiddenFileInput.addEventListener("change", function () {
  1093. var files = _this3.hiddenFileInput.files;
  1094. if (files.length) {
  1095. var _iteratorNormalCompletion9 = true;
  1096. var _didIteratorError9 = false;
  1097. var _iteratorError9 = undefined;
  1098. try {
  1099. for (var _iterator9 = files[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
  1100. var file = _step9.value;
  1101. _this3.addFile(file);
  1102. }
  1103. } catch (err) {
  1104. _didIteratorError9 = true;
  1105. _iteratorError9 = err;
  1106. } finally {
  1107. try {
  1108. if (!_iteratorNormalCompletion9 && _iterator9["return"] != null) {
  1109. _iterator9["return"]();
  1110. }
  1111. } finally {
  1112. if (_didIteratorError9) {
  1113. throw _iteratorError9;
  1114. }
  1115. }
  1116. }
  1117. }
  1118. _this3.emit("addedfiles", files);
  1119. return setupHiddenFileInput();
  1120. });
  1121. };
  1122. setupHiddenFileInput();
  1123. }
  1124. this.URL = window.URL !== null ? window.URL : window.webkitURL; // Setup all event listeners on the Dropzone object itself.
  1125. // They're not in @setupEventListeners() because they shouldn't be removed
  1126. // again when the dropzone gets disabled.
  1127. var _iteratorNormalCompletion10 = true;
  1128. var _didIteratorError10 = false;
  1129. var _iteratorError10 = undefined;
  1130. try {
  1131. for (var _iterator10 = this.events[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) {
  1132. var eventName = _step10.value;
  1133. this.on(eventName, this.options[eventName]);
  1134. }
  1135. } catch (err) {
  1136. _didIteratorError10 = true;
  1137. _iteratorError10 = err;
  1138. } finally {
  1139. try {
  1140. if (!_iteratorNormalCompletion10 && _iterator10["return"] != null) {
  1141. _iterator10["return"]();
  1142. }
  1143. } finally {
  1144. if (_didIteratorError10) {
  1145. throw _iteratorError10;
  1146. }
  1147. }
  1148. }
  1149. this.on("uploadprogress", function () {
  1150. return _this3.updateTotalUploadProgress();
  1151. });
  1152. this.on("removedfile", function () {
  1153. return _this3.updateTotalUploadProgress();
  1154. });
  1155. this.on("canceled", function (file) {
  1156. return _this3.emit("complete", file);
  1157. }); // Emit a `queuecomplete` event if all files finished uploading.
  1158. this.on("complete", function (file) {
  1159. if (_this3.getAddedFiles().length === 0 && _this3.getUploadingFiles().length === 0 && _this3.getQueuedFiles().length === 0) {
  1160. // This needs to be deferred so that `queuecomplete` really triggers after `complete`
  1161. return setTimeout(function () {
  1162. return _this3.emit("queuecomplete");
  1163. }, 0);
  1164. }
  1165. });
  1166. var containsFiles = function containsFiles(e) {
  1167. return e.dataTransfer.types && e.dataTransfer.types.some(function (type) {
  1168. return type == "Files";
  1169. });
  1170. };
  1171. var noPropagation = function noPropagation(e) {
  1172. // If there are no files, we don't want to stop
  1173. // propagation so we don't interfere with other
  1174. // drag and drop behaviour.
  1175. if (!containsFiles(e)) return;
  1176. e.stopPropagation();
  1177. if (e.preventDefault) {
  1178. return e.preventDefault();
  1179. } else {
  1180. return e.returnValue = false;
  1181. }
  1182. }; // Create the listeners
  1183. this.listeners = [{
  1184. element: this.element,
  1185. events: {
  1186. "dragstart": function dragstart(e) {
  1187. return _this3.emit("dragstart", e);
  1188. },
  1189. "dragenter": function dragenter(e) {
  1190. noPropagation(e);
  1191. return _this3.emit("dragenter", e);
  1192. },
  1193. "dragover": function dragover(e) {
  1194. // Makes it possible to drag files from chrome's download bar
  1195. // http://stackoverflow.com/questions/19526430/drag-and-drop-file-uploads-from-chrome-downloads-bar
  1196. // Try is required to prevent bug in Internet Explorer 11 (SCRIPT65535 exception)
  1197. var efct;
  1198. try {
  1199. efct = e.dataTransfer.effectAllowed;
  1200. } catch (error) {}
  1201. e.dataTransfer.dropEffect = 'move' === efct || 'linkMove' === efct ? 'move' : 'copy';
  1202. noPropagation(e);
  1203. return _this3.emit("dragover", e);
  1204. },
  1205. "dragleave": function dragleave(e) {
  1206. return _this3.emit("dragleave", e);
  1207. },
  1208. "drop": function drop(e) {
  1209. noPropagation(e);
  1210. return _this3.drop(e);
  1211. },
  1212. "dragend": function dragend(e) {
  1213. return _this3.emit("dragend", e);
  1214. }
  1215. } // This is disabled right now, because the browsers don't implement it properly.
  1216. // "paste": (e) =>
  1217. // noPropagation e
  1218. // @paste e
  1219. }];
  1220. this.clickableElements.forEach(function (clickableElement) {
  1221. return _this3.listeners.push({
  1222. element: clickableElement,
  1223. events: {
  1224. "click": function click(evt) {
  1225. // Only the actual dropzone or the message element should trigger file selection
  1226. if (clickableElement !== _this3.element || evt.target === _this3.element || Dropzone.elementInside(evt.target, _this3.element.querySelector(".dz-message"))) {
  1227. _this3.hiddenFileInput.click(); // Forward the click
  1228. }
  1229. return true;
  1230. }
  1231. }
  1232. });
  1233. });
  1234. this.enable();
  1235. return this.options.init.call(this);
  1236. } // Not fully tested yet
  1237. }, {
  1238. key: "destroy",
  1239. value: function destroy() {
  1240. this.disable();
  1241. this.removeAllFiles(true);
  1242. if (this.hiddenFileInput != null ? this.hiddenFileInput.parentNode : undefined) {
  1243. this.hiddenFileInput.parentNode.removeChild(this.hiddenFileInput);
  1244. this.hiddenFileInput = null;
  1245. }
  1246. delete this.element.dropzone;
  1247. return Dropzone.instances.splice(Dropzone.instances.indexOf(this), 1);
  1248. }
  1249. }, {
  1250. key: "updateTotalUploadProgress",
  1251. value: function updateTotalUploadProgress() {
  1252. var totalUploadProgress;
  1253. var totalBytesSent = 0;
  1254. var totalBytes = 0;
  1255. var activeFiles = this.getActiveFiles();
  1256. if (activeFiles.length) {
  1257. var _iteratorNormalCompletion11 = true;
  1258. var _didIteratorError11 = false;
  1259. var _iteratorError11 = undefined;
  1260. try {
  1261. for (var _iterator11 = this.getActiveFiles()[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) {
  1262. var file = _step11.value;
  1263. totalBytesSent += file.upload.bytesSent;
  1264. totalBytes += file.upload.total;
  1265. }
  1266. } catch (err) {
  1267. _didIteratorError11 = true;
  1268. _iteratorError11 = err;
  1269. } finally {
  1270. try {
  1271. if (!_iteratorNormalCompletion11 && _iterator11["return"] != null) {
  1272. _iterator11["return"]();
  1273. }
  1274. } finally {
  1275. if (_didIteratorError11) {
  1276. throw _iteratorError11;
  1277. }
  1278. }
  1279. }
  1280. totalUploadProgress = 100 * totalBytesSent / totalBytes;
  1281. } else {
  1282. totalUploadProgress = 100;
  1283. }
  1284. return this.emit("totaluploadprogress", totalUploadProgress, totalBytes, totalBytesSent);
  1285. } // @options.paramName can be a function taking one parameter rather than a string.
  1286. // A parameter name for a file is obtained simply by calling this with an index number.
  1287. }, {
  1288. key: "_getParamName",
  1289. value: function _getParamName(n) {
  1290. if (typeof this.options.paramName === "function") {
  1291. return this.options.paramName(n);
  1292. } else {
  1293. return "".concat(this.options.paramName).concat(this.options.uploadMultiple ? "[".concat(n, "]") : "");
  1294. }
  1295. } // If @options.renameFile is a function,
  1296. // the function will be used to rename the file.name before appending it to the formData
  1297. }, {
  1298. key: "_renameFile",
  1299. value: function _renameFile(file) {
  1300. if (typeof this.options.renameFile !== "function") {
  1301. return file.name;
  1302. }
  1303. return this.options.renameFile(file);
  1304. } // Returns a form that can be used as fallback if the browser does not support DragnDrop
  1305. //
  1306. // If the dropzone is already a form, only the input field and button are returned. Otherwise a complete form element is provided.
  1307. // This code has to pass in IE7 :(
  1308. }, {
  1309. key: "getFallbackForm",
  1310. value: function getFallbackForm() {
  1311. var existingFallback, form;
  1312. if (existingFallback = this.getExistingFallback()) {
  1313. return existingFallback;
  1314. }
  1315. var fieldsString = "<div class=\"dz-fallback\">";
  1316. if (this.options.dictFallbackText) {
  1317. fieldsString += "<p>".concat(this.options.dictFallbackText, "</p>");
  1318. }
  1319. fieldsString += "<input type=\"file\" name=\"".concat(this._getParamName(0), "\" ").concat(this.options.uploadMultiple ? 'multiple="multiple"' : undefined, " /><input type=\"submit\" value=\"Upload!\"></div>");
  1320. var fields = Dropzone.createElement(fieldsString);
  1321. if (this.element.tagName !== "FORM") {
  1322. form = Dropzone.createElement("<form action=\"".concat(this.options.url, "\" enctype=\"multipart/form-data\" method=\"").concat(this.options.method, "\"></form>"));
  1323. form.appendChild(fields);
  1324. } else {
  1325. // Make sure that the enctype and method attributes are set properly
  1326. this.element.setAttribute("enctype", "multipart/form-data");
  1327. this.element.setAttribute("method", this.options.method);
  1328. }
  1329. return form != null ? form : fields;
  1330. } // Returns the fallback elements if they exist already
  1331. //
  1332. // This code has to pass in IE7 :(
  1333. }, {
  1334. key: "getExistingFallback",
  1335. value: function getExistingFallback() {
  1336. var getFallback = function getFallback(elements) {
  1337. var _iteratorNormalCompletion12 = true;
  1338. var _didIteratorError12 = false;
  1339. var _iteratorError12 = undefined;
  1340. try {
  1341. for (var _iterator12 = elements[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) {
  1342. var el = _step12.value;
  1343. if (/(^| )fallback($| )/.test(el.className)) {
  1344. return el;
  1345. }
  1346. }
  1347. } catch (err) {
  1348. _didIteratorError12 = true;
  1349. _iteratorError12 = err;
  1350. } finally {
  1351. try {
  1352. if (!_iteratorNormalCompletion12 && _iterator12["return"] != null) {
  1353. _iterator12["return"]();
  1354. }
  1355. } finally {
  1356. if (_didIteratorError12) {
  1357. throw _iteratorError12;
  1358. }
  1359. }
  1360. }
  1361. };
  1362. for (var _i2 = 0, _arr = ["div", "form"]; _i2 < _arr.length; _i2++) {
  1363. var tagName = _arr[_i2];
  1364. var fallback;
  1365. if (fallback = getFallback(this.element.getElementsByTagName(tagName))) {
  1366. return fallback;
  1367. }
  1368. }
  1369. } // Activates all listeners stored in @listeners
  1370. }, {
  1371. key: "setupEventListeners",
  1372. value: function setupEventListeners() {
  1373. return this.listeners.map(function (elementListeners) {
  1374. return function () {
  1375. var result = [];
  1376. for (var event in elementListeners.events) {
  1377. var listener = elementListeners.events[event];
  1378. result.push(elementListeners.element.addEventListener(event, listener, false));
  1379. }
  1380. return result;
  1381. }();
  1382. });
  1383. } // Deactivates all listeners stored in @listeners
  1384. }, {
  1385. key: "removeEventListeners",
  1386. value: function removeEventListeners() {
  1387. return this.listeners.map(function (elementListeners) {
  1388. return function () {
  1389. var result = [];
  1390. for (var event in elementListeners.events) {
  1391. var listener = elementListeners.events[event];
  1392. result.push(elementListeners.element.removeEventListener(event, listener, false));
  1393. }
  1394. return result;
  1395. }();
  1396. });
  1397. } // Removes all event listeners and cancels all files in the queue or being processed.
  1398. }, {
  1399. key: "disable",
  1400. value: function disable() {
  1401. var _this4 = this;
  1402. this.clickableElements.forEach(function (element) {
  1403. return element.classList.remove("dz-clickable");
  1404. });
  1405. this.removeEventListeners();
  1406. this.disabled = true;
  1407. return this.files.map(function (file) {
  1408. return _this4.cancelUpload(file);
  1409. });
  1410. }
  1411. }, {
  1412. key: "enable",
  1413. value: function enable() {
  1414. delete this.disabled;
  1415. this.clickableElements.forEach(function (element) {
  1416. return element.classList.add("dz-clickable");
  1417. });
  1418. return this.setupEventListeners();
  1419. } // Returns a nicely formatted filesize
  1420. }, {
  1421. key: "filesize",
  1422. value: function filesize(size) {
  1423. var selectedSize = 0;
  1424. var selectedUnit = "b";
  1425. if (size > 0) {
  1426. var units = ['tb', 'gb', 'mb', 'kb', 'b'];
  1427. for (var i = 0; i < units.length; i++) {
  1428. var unit = units[i];
  1429. var cutoff = Math.pow(this.options.filesizeBase, 4 - i) / 10;
  1430. if (size >= cutoff) {
  1431. selectedSize = size / Math.pow(this.options.filesizeBase, 4 - i);
  1432. selectedUnit = unit;
  1433. break;
  1434. }
  1435. }
  1436. selectedSize = Math.round(10 * selectedSize) / 10; // Cutting of digits
  1437. }
  1438. return "<strong>".concat(selectedSize, "</strong> ").concat(this.options.dictFileSizeUnits[selectedUnit]);
  1439. } // Adds or removes the `dz-max-files-reached` class from the form.
  1440. }, {
  1441. key: "_updateMaxFilesReachedClass",
  1442. value: function _updateMaxFilesReachedClass() {
  1443. if (this.options.maxFiles != null && this.getAcceptedFiles().length >= this.options.maxFiles) {
  1444. if (this.getAcceptedFiles().length === this.options.maxFiles) {
  1445. this.emit('maxfilesreached', this.files);
  1446. }
  1447. return this.element.classList.add("dz-max-files-reached");
  1448. } else {
  1449. return this.element.classList.remove("dz-max-files-reached");
  1450. }
  1451. }
  1452. }, {
  1453. key: "drop",
  1454. value: function drop(e) {
  1455. if (!e.dataTransfer) {
  1456. return;
  1457. }
  1458. this.emit("drop", e); // Convert the FileList to an Array
  1459. // This is necessary for IE11
  1460. var files = [];
  1461. for (var i = 0; i < e.dataTransfer.files.length; i++) {
  1462. files[i] = e.dataTransfer.files[i];
  1463. } // Even if it's a folder, files.length will contain the folders.
  1464. if (files.length) {
  1465. var items = e.dataTransfer.items;
  1466. if (items && items.length && items[0].webkitGetAsEntry != null) {
  1467. // The browser supports dropping of folders, so handle items instead of files
  1468. this._addFilesFromItems(items);
  1469. } else {
  1470. this.handleFiles(files);
  1471. }
  1472. }
  1473. this.emit("addedfiles", files);
  1474. }
  1475. }, {
  1476. key: "paste",
  1477. value: function paste(e) {
  1478. if (__guard__(e != null ? e.clipboardData : undefined, function (x) {
  1479. return x.items;
  1480. }) == null) {
  1481. return;
  1482. }
  1483. this.emit("paste", e);
  1484. var items = e.clipboardData.items;
  1485. if (items.length) {
  1486. return this._addFilesFromItems(items);
  1487. }
  1488. }
  1489. }, {
  1490. key: "handleFiles",
  1491. value: function handleFiles(files) {
  1492. var _iteratorNormalCompletion13 = true;
  1493. var _didIteratorError13 = false;
  1494. var _iteratorError13 = undefined;
  1495. try {
  1496. for (var _iterator13 = files[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) {
  1497. var file = _step13.value;
  1498. this.addFile(file);
  1499. }
  1500. } catch (err) {
  1501. _didIteratorError13 = true;
  1502. _iteratorError13 = err;
  1503. } finally {
  1504. try {
  1505. if (!_iteratorNormalCompletion13 && _iterator13["return"] != null) {
  1506. _iterator13["return"]();
  1507. }
  1508. } finally {
  1509. if (_didIteratorError13) {
  1510. throw _iteratorError13;
  1511. }
  1512. }
  1513. }
  1514. } // When a folder is dropped (or files are pasted), items must be handled
  1515. // instead of files.
  1516. }, {
  1517. key: "_addFilesFromItems",
  1518. value: function _addFilesFromItems(items) {
  1519. var _this5 = this;
  1520. return function () {
  1521. var result = [];
  1522. var _iteratorNormalCompletion14 = true;
  1523. var _didIteratorError14 = false;
  1524. var _iteratorError14 = undefined;
  1525. try {
  1526. for (var _iterator14 = items[Symbol.iterator](), _step14; !(_iteratorNormalCompletion14 = (_step14 = _iterator14.next()).done); _iteratorNormalCompletion14 = true) {
  1527. var item = _step14.value;
  1528. var entry;
  1529. if (item.webkitGetAsEntry != null && (entry = item.webkitGetAsEntry())) {
  1530. if (entry.isFile) {
  1531. result.push(_this5.addFile(item.getAsFile()));
  1532. } else if (entry.isDirectory) {
  1533. // Append all files from that directory to files
  1534. result.push(_this5._addFilesFromDirectory(entry, entry.name));
  1535. } else {
  1536. result.push(undefined);
  1537. }
  1538. } else if (item.getAsFile != null) {
  1539. if (item.kind == null || item.kind === "file") {
  1540. result.push(_this5.addFile(item.getAsFile()));
  1541. } else {
  1542. result.push(undefined);
  1543. }
  1544. } else {
  1545. result.push(undefined);
  1546. }
  1547. }
  1548. } catch (err) {
  1549. _didIteratorError14 = true;
  1550. _iteratorError14 = err;
  1551. } finally {
  1552. try {
  1553. if (!_iteratorNormalCompletion14 && _iterator14["return"] != null) {
  1554. _iterator14["return"]();
  1555. }
  1556. } finally {
  1557. if (_didIteratorError14) {
  1558. throw _iteratorError14;
  1559. }
  1560. }
  1561. }
  1562. return result;
  1563. }();
  1564. } // Goes through the directory, and adds each file it finds recursively
  1565. }, {
  1566. key: "_addFilesFromDirectory",
  1567. value: function _addFilesFromDirectory(directory, path) {
  1568. var _this6 = this;
  1569. var dirReader = directory.createReader();
  1570. var errorHandler = function errorHandler(error) {
  1571. return __guardMethod__(console, 'log', function (o) {
  1572. return o.log(error);
  1573. });
  1574. };
  1575. var readEntries = function readEntries() {
  1576. return dirReader.readEntries(function (entries) {
  1577. if (entries.length > 0) {
  1578. var _iteratorNormalCompletion15 = true;
  1579. var _didIteratorError15 = false;
  1580. var _iteratorError15 = undefined;
  1581. try {
  1582. for (var _iterator15 = entries[Symbol.iterator](), _step15; !(_iteratorNormalCompletion15 = (_step15 = _iterator15.next()).done); _iteratorNormalCompletion15 = true) {
  1583. var entry = _step15.value;
  1584. if (entry.isFile) {
  1585. entry.file(function (file) {
  1586. if (_this6.options.ignoreHiddenFiles && file.name.substring(0, 1) === '.') {
  1587. return;
  1588. }
  1589. file.fullPath = "".concat(path, "/").concat(file.name);
  1590. return _this6.addFile(file);
  1591. });
  1592. } else if (entry.isDirectory) {
  1593. _this6._addFilesFromDirectory(entry, "".concat(path, "/").concat(entry.name));
  1594. }
  1595. } // Recursively call readEntries() again, since browser only handle
  1596. // the first 100 entries.
  1597. // See: https://developer.mozilla.org/en-US/docs/Web/API/DirectoryReader#readEntries
  1598. } catch (err) {
  1599. _didIteratorError15 = true;
  1600. _iteratorError15 = err;
  1601. } finally {
  1602. try {
  1603. if (!_iteratorNormalCompletion15 && _iterator15["return"] != null) {
  1604. _iterator15["return"]();
  1605. }
  1606. } finally {
  1607. if (_didIteratorError15) {
  1608. throw _iteratorError15;
  1609. }
  1610. }
  1611. }
  1612. readEntries();
  1613. }
  1614. return null;
  1615. }, errorHandler);
  1616. };
  1617. return readEntries();
  1618. } // If `done()` is called without argument the file is accepted
  1619. // If you call it with an error message, the file is rejected
  1620. // (This allows for asynchronous validation)
  1621. //
  1622. // This function checks the filesize, and if the file.type passes the
  1623. // `acceptedFiles` check.
  1624. }, {
  1625. key: "accept",
  1626. value: function accept(file, done) {
  1627. if (this.options.maxFilesize && file.size > this.options.maxFilesize * 1024 * 1024) {
  1628. done(this.options.dictFileTooBig.replace("{{filesize}}", Math.round(file.size / 1024 / 10.24) / 100).replace("{{maxFilesize}}", this.options.maxFilesize));
  1629. } else if (!Dropzone.isValidFile(file, this.options.acceptedFiles)) {
  1630. done(this.options.dictInvalidFileType);
  1631. } else if (this.options.maxFiles != null && this.getAcceptedFiles().length >= this.options.maxFiles) {
  1632. done(this.options.dictMaxFilesExceeded.replace("{{maxFiles}}", this.options.maxFiles));
  1633. this.emit("maxfilesexceeded", file);
  1634. } else {
  1635. this.options.accept.call(this, file, done);
  1636. }
  1637. }
  1638. }, {
  1639. key: "addFile",
  1640. value: function addFile(file) {
  1641. var _this7 = this;
  1642. file.upload = {
  1643. uuid: Dropzone.uuidv4(),
  1644. progress: 0,
  1645. // Setting the total upload size to file.size for the beginning
  1646. // It's actual different than the size to be transmitted.
  1647. total: file.size,
  1648. bytesSent: 0,
  1649. filename: this._renameFile(file) // Not setting chunking information here, because the acutal data — and
  1650. // thus the chunks — might change if `options.transformFile` is set
  1651. // and does something to the data.
  1652. };
  1653. this.files.push(file);
  1654. file.status = Dropzone.ADDED;
  1655. this.emit("addedfile", file);
  1656. this._enqueueThumbnail(file);
  1657. this.accept(file, function (error) {
  1658. if (error) {
  1659. file.accepted = false;
  1660. _this7._errorProcessing([file], error); // Will set the file.status
  1661. } else {
  1662. file.accepted = true;
  1663. if (_this7.options.autoQueue) {
  1664. _this7.enqueueFile(file);
  1665. } // Will set .accepted = true
  1666. }
  1667. _this7._updateMaxFilesReachedClass();
  1668. });
  1669. } // Wrapper for enqueueFile
  1670. }, {
  1671. key: "enqueueFiles",
  1672. value: function enqueueFiles(files) {
  1673. var _iteratorNormalCompletion16 = true;
  1674. var _didIteratorError16 = false;
  1675. var _iteratorError16 = undefined;
  1676. try {
  1677. for (var _iterator16 = files[Symbol.iterator](), _step16; !(_iteratorNormalCompletion16 = (_step16 = _iterator16.next()).done); _iteratorNormalCompletion16 = true) {
  1678. var file = _step16.value;
  1679. this.enqueueFile(file);
  1680. }
  1681. } catch (err) {
  1682. _didIteratorError16 = true;
  1683. _iteratorError16 = err;
  1684. } finally {
  1685. try {
  1686. if (!_iteratorNormalCompletion16 && _iterator16["return"] != null) {
  1687. _iterator16["return"]();
  1688. }
  1689. } finally {
  1690. if (_didIteratorError16) {
  1691. throw _iteratorError16;
  1692. }
  1693. }
  1694. }
  1695. return null;
  1696. }
  1697. }, {
  1698. key: "enqueueFile",
  1699. value: function enqueueFile(file) {
  1700. var _this8 = this;
  1701. if (file.status === Dropzone.ADDED && file.accepted === true) {
  1702. file.status = Dropzone.QUEUED;
  1703. if (this.options.autoProcessQueue) {
  1704. return setTimeout(function () {
  1705. return _this8.processQueue();
  1706. }, 0); // Deferring the call
  1707. }
  1708. } else {
  1709. throw new Error("This file can't be queued because it has already been processed or was rejected.");
  1710. }
  1711. }
  1712. }, {
  1713. key: "_enqueueThumbnail",
  1714. value: function _enqueueThumbnail(file) {
  1715. var _this9 = this;
  1716. if (this.options.createImageThumbnails && file.type.match(/image.*/) && file.size <= this.options.maxThumbnailFilesize * 1024 * 1024) {
  1717. this._thumbnailQueue.push(file);
  1718. return setTimeout(function () {
  1719. return _this9._processThumbnailQueue();
  1720. }, 0); // Deferring the call
  1721. }
  1722. }
  1723. }, {
  1724. key: "_processThumbnailQueue",
  1725. value: function _processThumbnailQueue() {
  1726. var _this10 = this;
  1727. if (this._processingThumbnail || this._thumbnailQueue.length === 0) {
  1728. return;
  1729. }
  1730. this._processingThumbnail = true;
  1731. var file = this._thumbnailQueue.shift();
  1732. return this.createThumbnail(file, this.options.thumbnailWidth, this.options.thumbnailHeight, this.options.thumbnailMethod, true, function (dataUrl) {
  1733. _this10.emit("thumbnail", file, dataUrl);
  1734. _this10._processingThumbnail = false;
  1735. return _this10._processThumbnailQueue();
  1736. });
  1737. } // Can be called by the user to remove a file
  1738. }, {
  1739. key: "removeFile",
  1740. value: function removeFile(file) {
  1741. if (file.status === Dropzone.UPLOADING) {
  1742. this.cancelUpload(file);
  1743. }
  1744. this.files = without(this.files, file);
  1745. this.emit("removedfile", file);
  1746. if (this.files.length === 0) {
  1747. return this.emit("reset");
  1748. }
  1749. } // Removes all files that aren't currently processed from the list
  1750. }, {
  1751. key: "removeAllFiles",
  1752. value: function removeAllFiles(cancelIfNecessary) {
  1753. // Create a copy of files since removeFile() changes the @files array.
  1754. if (cancelIfNecessary == null) {
  1755. cancelIfNecessary = false;
  1756. }
  1757. var _iteratorNormalCompletion17 = true;
  1758. var _didIteratorError17 = false;
  1759. var _iteratorError17 = undefined;
  1760. try {
  1761. for (var _iterator17 = this.files.slice()[Symbol.iterator](), _step17; !(_iteratorNormalCompletion17 = (_step17 = _iterator17.next()).done); _iteratorNormalCompletion17 = true) {
  1762. var file = _step17.value;
  1763. if (file.status !== Dropzone.UPLOADING || cancelIfNecessary) {
  1764. this.removeFile(file);
  1765. }
  1766. }
  1767. } catch (err) {
  1768. _didIteratorError17 = true;
  1769. _iteratorError17 = err;
  1770. } finally {
  1771. try {
  1772. if (!_iteratorNormalCompletion17 && _iterator17["return"] != null) {
  1773. _iterator17["return"]();
  1774. }
  1775. } finally {
  1776. if (_didIteratorError17) {
  1777. throw _iteratorError17;
  1778. }
  1779. }
  1780. }
  1781. return null;
  1782. } // Resizes an image before it gets sent to the server. This function is the default behavior of
  1783. // `options.transformFile` if `resizeWidth` or `resizeHeight` are set. The callback is invoked with
  1784. // the resized blob.
  1785. }, {
  1786. key: "resizeImage",
  1787. value: function resizeImage(file, width, height, resizeMethod, callback) {
  1788. var _this11 = this;
  1789. return this.createThumbnail(file, width, height, resizeMethod, true, function (dataUrl, canvas) {
  1790. if (canvas == null) {
  1791. // The image has not been resized
  1792. return callback(file);
  1793. } else {
  1794. var resizeMimeType = _this11.options.resizeMimeType;
  1795. if (resizeMimeType == null) {
  1796. resizeMimeType = file.type;
  1797. }
  1798. var resizedDataURL = canvas.toDataURL(resizeMimeType, _this11.options.resizeQuality);
  1799. if (resizeMimeType === 'image/jpeg' || resizeMimeType === 'image/jpg') {
  1800. // Now add the original EXIF information
  1801. resizedDataURL = ExifRestore.restore(file.dataURL, resizedDataURL);
  1802. }
  1803. return callback(Dropzone.dataURItoBlob(resizedDataURL));
  1804. }
  1805. });
  1806. }
  1807. }, {
  1808. key: "createThumbnail",
  1809. value: function createThumbnail(file, width, height, resizeMethod, fixOrientation, callback) {
  1810. var _this12 = this;
  1811. var fileReader = new FileReader();
  1812. fileReader.onload = function () {
  1813. file.dataURL = fileReader.result; // Don't bother creating a thumbnail for SVG images since they're vector
  1814. if (file.type === "image/svg+xml") {
  1815. if (callback != null) {
  1816. callback(fileReader.result);
  1817. }
  1818. return;
  1819. }
  1820. _this12.createThumbnailFromUrl(file, width, height, resizeMethod, fixOrientation, callback);
  1821. };
  1822. fileReader.readAsDataURL(file);
  1823. } // `mockFile` needs to have these attributes:
  1824. //
  1825. // { name: 'name', size: 12345, imageUrl: '' }
  1826. //
  1827. // `callback` will be invoked when the image has been downloaded and displayed.
  1828. // `crossOrigin` will be added to the `img` tag when accessing the file.
  1829. }, {
  1830. key: "displayExistingFile",
  1831. value: function displayExistingFile(mockFile, imageUrl, callback, crossOrigin) {
  1832. var _this13 = this;
  1833. var resizeThumbnail = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
  1834. this.emit("addedfile", mockFile);
  1835. this.emit("complete", mockFile);
  1836. if (!resizeThumbnail) {
  1837. this.emit("thumbnail", mockFile, imageUrl);
  1838. if (callback) callback();
  1839. } else {
  1840. var onDone = function onDone(thumbnail) {
  1841. _this13.emit('thumbnail', mockFile, thumbnail);
  1842. if (callback) callback();
  1843. };
  1844. mockFile.dataURL = imageUrl;
  1845. this.createThumbnailFromUrl(mockFile, this.options.thumbnailWidth, this.options.thumbnailHeight, this.options.resizeMethod, this.options.fixOrientation, onDone, crossOrigin);
  1846. }
  1847. }
  1848. }, {
  1849. key: "createThumbnailFromUrl",
  1850. value: function createThumbnailFromUrl(file, width, height, resizeMethod, fixOrientation, callback, crossOrigin) {
  1851. var _this14 = this;
  1852. // Not using `new Image` here because of a bug in latest Chrome versions.
  1853. // See https://github.com/enyo/dropzone/pull/226
  1854. var img = document.createElement("img");
  1855. if (crossOrigin) {
  1856. img.crossOrigin = crossOrigin;
  1857. }
  1858. img.onload = function () {
  1859. var loadExif = function loadExif(callback) {
  1860. return callback(1);
  1861. };
  1862. if (typeof EXIF !== 'undefined' && EXIF !== null && fixOrientation) {
  1863. loadExif = function loadExif(callback) {
  1864. return EXIF.getData(img, function () {
  1865. return callback(EXIF.getTag(this, 'Orientation'));
  1866. });
  1867. };
  1868. }
  1869. return loadExif(function (orientation) {
  1870. file.width = img.width;
  1871. file.height = img.height;
  1872. var resizeInfo = _this14.options.resize.call(_this14, file, width, height, resizeMethod);
  1873. var canvas = document.createElement("canvas");
  1874. var ctx = canvas.getContext("2d");
  1875. canvas.width = resizeInfo.trgWidth;
  1876. canvas.height = resizeInfo.trgHeight;
  1877. if (orientation > 4) {
  1878. canvas.width = resizeInfo.trgHeight;
  1879. canvas.height = resizeInfo.trgWidth;
  1880. }
  1881. switch (orientation) {
  1882. case 2:
  1883. // horizontal flip
  1884. ctx.translate(canvas.width, 0);
  1885. ctx.scale(-1, 1);
  1886. break;
  1887. case 3:
  1888. // 180° rotate left
  1889. ctx.translate(canvas.width, canvas.height);
  1890. ctx.rotate(Math.PI);
  1891. break;
  1892. case 4:
  1893. // vertical flip
  1894. ctx.translate(0, canvas.height);
  1895. ctx.scale(1, -1);
  1896. break;
  1897. case 5:
  1898. // vertical flip + 90 rotate right
  1899. ctx.rotate(0.5 * Math.PI);
  1900. ctx.scale(1, -1);
  1901. break;
  1902. case 6:
  1903. // 90° rotate right
  1904. ctx.rotate(0.5 * Math.PI);
  1905. ctx.translate(0, -canvas.width);
  1906. break;
  1907. case 7:
  1908. // horizontal flip + 90 rotate right
  1909. ctx.rotate(0.5 * Math.PI);
  1910. ctx.translate(canvas.height, -canvas.width);
  1911. ctx.scale(-1, 1);
  1912. break;
  1913. case 8:
  1914. // 90° rotate left
  1915. ctx.rotate(-0.5 * Math.PI);
  1916. ctx.translate(-canvas.height, 0);
  1917. break;
  1918. } // This is a bugfix for iOS' scaling bug.
  1919. drawImageIOSFix(ctx, img, resizeInfo.srcX != null ? resizeInfo.srcX : 0, resizeInfo.srcY != null ? resizeInfo.srcY : 0, resizeInfo.srcWidth, resizeInfo.srcHeight, resizeInfo.trgX != null ? resizeInfo.trgX : 0, resizeInfo.trgY != null ? resizeInfo.trgY : 0, resizeInfo.trgWidth, resizeInfo.trgHeight);
  1920. var thumbnail = canvas.toDataURL("image/png");
  1921. if (callback != null) {
  1922. return callback(thumbnail, canvas);
  1923. }
  1924. });
  1925. };
  1926. if (callback != null) {
  1927. img.onerror = callback;
  1928. }
  1929. return img.src = file.dataURL;
  1930. } // Goes through the queue and processes files if there aren't too many already.
  1931. }, {
  1932. key: "processQueue",
  1933. value: function processQueue() {
  1934. var parallelUploads = this.options.parallelUploads;
  1935. var processingLength = this.getUploadingFiles().length;
  1936. var i = processingLength; // There are already at least as many files uploading than should be
  1937. if (processingLength >= parallelUploads) {
  1938. return;
  1939. }
  1940. var queuedFiles = this.getQueuedFiles();
  1941. if (!(queuedFiles.length > 0)) {
  1942. return;
  1943. }
  1944. if (this.options.uploadMultiple) {
  1945. // The files should be uploaded in one request
  1946. return this.processFiles(queuedFiles.slice(0, parallelUploads - processingLength));
  1947. } else {
  1948. while (i < parallelUploads) {
  1949. if (!queuedFiles.length) {
  1950. return;
  1951. } // Nothing left to process
  1952. this.processFile(queuedFiles.shift());
  1953. i++;
  1954. }
  1955. }
  1956. } // Wrapper for `processFiles`
  1957. }, {
  1958. key: "processFile",
  1959. value: function processFile(file) {
  1960. return this.processFiles([file]);
  1961. } // Loads the file, then calls finishedLoading()
  1962. }, {
  1963. key: "processFiles",
  1964. value: function processFiles(files) {
  1965. var _iteratorNormalCompletion18 = true;
  1966. var _didIteratorError18 = false;
  1967. var _iteratorError18 = undefined;
  1968. try {
  1969. for (var _iterator18 = files[Symbol.iterator](), _step18; !(_iteratorNormalCompletion18 = (_step18 = _iterator18.next()).done); _iteratorNormalCompletion18 = true) {
  1970. var file = _step18.value;
  1971. file.processing = true; // Backwards compatibility
  1972. file.status = Dropzone.UPLOADING;
  1973. this.emit("processing", file);
  1974. }
  1975. } catch (err) {
  1976. _didIteratorError18 = true;
  1977. _iteratorError18 = err;
  1978. } finally {
  1979. try {
  1980. if (!_iteratorNormalCompletion18 && _iterator18["return"] != null) {
  1981. _iterator18["return"]();
  1982. }
  1983. } finally {
  1984. if (_didIteratorError18) {
  1985. throw _iteratorError18;
  1986. }
  1987. }
  1988. }
  1989. if (this.options.uploadMultiple) {
  1990. this.emit("processingmultiple", files);
  1991. }
  1992. return this.uploadFiles(files);
  1993. }
  1994. }, {
  1995. key: "_getFilesWithXhr",
  1996. value: function _getFilesWithXhr(xhr) {
  1997. var files;
  1998. return files = this.files.filter(function (file) {
  1999. return file.xhr === xhr;
  2000. }).map(function (file) {
  2001. return file;
  2002. });
  2003. } // Cancels the file upload and sets the status to CANCELED
  2004. // **if** the file is actually being uploaded.
  2005. // If it's still in the queue, the file is being removed from it and the status
  2006. // set to CANCELED.
  2007. }, {
  2008. key: "cancelUpload",
  2009. value: function cancelUpload(file) {
  2010. if (file.status === Dropzone.UPLOADING) {
  2011. var groupedFiles = this._getFilesWithXhr(file.xhr);
  2012. var _iteratorNormalCompletion19 = true;
  2013. var _didIteratorError19 = false;
  2014. var _iteratorError19 = undefined;
  2015. try {
  2016. for (var _iterator19 = groupedFiles[Symbol.iterator](), _step19; !(_iteratorNormalCompletion19 = (_step19 = _iterator19.next()).done); _iteratorNormalCompletion19 = true) {
  2017. var groupedFile = _step19.value;
  2018. groupedFile.status = Dropzone.CANCELED;
  2019. }
  2020. } catch (err) {
  2021. _didIteratorError19 = true;
  2022. _iteratorError19 = err;
  2023. } finally {
  2024. try {
  2025. if (!_iteratorNormalCompletion19 && _iterator19["return"] != null) {
  2026. _iterator19["return"]();
  2027. }
  2028. } finally {
  2029. if (_didIteratorError19) {
  2030. throw _iteratorError19;
  2031. }
  2032. }
  2033. }
  2034. if (typeof file.xhr !== 'undefined') {
  2035. file.xhr.abort();
  2036. }
  2037. var _iteratorNormalCompletion20 = true;
  2038. var _didIteratorError20 = false;
  2039. var _iteratorError20 = undefined;
  2040. try {
  2041. for (var _iterator20 = groupedFiles[Symbol.iterator](), _step20; !(_iteratorNormalCompletion20 = (_step20 = _iterator20.next()).done); _iteratorNormalCompletion20 = true) {
  2042. var _groupedFile = _step20.value;
  2043. this.emit("canceled", _groupedFile);
  2044. }
  2045. } catch (err) {
  2046. _didIteratorError20 = true;
  2047. _iteratorError20 = err;
  2048. } finally {
  2049. try {
  2050. if (!_iteratorNormalCompletion20 && _iterator20["return"] != null) {
  2051. _iterator20["return"]();
  2052. }
  2053. } finally {
  2054. if (_didIteratorError20) {
  2055. throw _iteratorError20;
  2056. }
  2057. }
  2058. }
  2059. if (this.options.uploadMultiple) {
  2060. this.emit("canceledmultiple", groupedFiles);
  2061. }
  2062. } else if (file.status === Dropzone.ADDED || file.status === Dropzone.QUEUED) {
  2063. file.status = Dropzone.CANCELED;
  2064. this.emit("canceled", file);
  2065. if (this.options.uploadMultiple) {
  2066. this.emit("canceledmultiple", [file]);
  2067. }
  2068. }
  2069. if (this.options.autoProcessQueue) {
  2070. return this.processQueue();
  2071. }
  2072. }
  2073. }, {
  2074. key: "resolveOption",
  2075. value: function resolveOption(option) {
  2076. if (typeof option === 'function') {
  2077. for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
  2078. args[_key3 - 1] = arguments[_key3];
  2079. }
  2080. return option.apply(this, args);
  2081. }
  2082. return option;
  2083. }
  2084. }, {
  2085. key: "uploadFile",
  2086. value: function uploadFile(file) {
  2087. return this.uploadFiles([file]);
  2088. }
  2089. }, {
  2090. key: "uploadFiles",
  2091. value: function uploadFiles(files) {
  2092. var _this15 = this;
  2093. this._transformFiles(files, function (transformedFiles) {
  2094. if (_this15.options.chunking) {
  2095. // Chunking is not allowed to be used with `uploadMultiple` so we know
  2096. // that there is only __one__file.
  2097. var transformedFile = transformedFiles[0];
  2098. files[0].upload.chunked = _this15.options.chunking && (_this15.options.forceChunking || transformedFile.size > _this15.options.chunkSize);
  2099. files[0].upload.totalChunkCount = Math.ceil(transformedFile.size / _this15.options.chunkSize);
  2100. }
  2101. if (files[0].upload.chunked) {
  2102. // This file should be sent in chunks!
  2103. // If the chunking option is set, we **know** that there can only be **one** file, since
  2104. // uploadMultiple is not allowed with this option.
  2105. var file = files[0];
  2106. var _transformedFile = transformedFiles[0];
  2107. var startedChunkCount = 0;
  2108. file.upload.chunks = [];
  2109. var handleNextChunk = function handleNextChunk() {
  2110. var chunkIndex = 0; // Find the next item in file.upload.chunks that is not defined yet.
  2111. while (file.upload.chunks[chunkIndex] !== undefined) {
  2112. chunkIndex++;
  2113. } // This means, that all chunks have already been started.
  2114. if (chunkIndex >= file.upload.totalChunkCount) return;
  2115. startedChunkCount++;
  2116. var start = chunkIndex * _this15.options.chunkSize;
  2117. var end = Math.min(start + _this15.options.chunkSize, file.size);
  2118. var dataBlock = {
  2119. name: _this15._getParamName(0),
  2120. data: _transformedFile.webkitSlice ? _transformedFile.webkitSlice(start, end) : _transformedFile.slice(start, end),
  2121. filename: file.upload.filename,
  2122. chunkIndex: chunkIndex
  2123. };
  2124. file.upload.chunks[chunkIndex] = {
  2125. file: file,
  2126. index: chunkIndex,
  2127. dataBlock: dataBlock,
  2128. // In case we want to retry.
  2129. status: Dropzone.UPLOADING,
  2130. progress: 0,
  2131. retries: 0 // The number of times this block has been retried.
  2132. };
  2133. _this15._uploadData(files, [dataBlock]);
  2134. };
  2135. file.upload.finishedChunkUpload = function (chunk, response) {
  2136. var allFinished = true;
  2137. chunk.status = Dropzone.SUCCESS; // Clear the data from the chunk
  2138. _this15.options.chunkSuccess.call(_this15, chunk, file, response);
  2139. chunk.dataBlock = null; // Leaving this reference to xhr intact here will cause memory leaks in some browsers
  2140. chunk.xhr = null;
  2141. for (var i = 0; i < file.upload.totalChunkCount; i++) {
  2142. if (file.upload.chunks[i] === undefined) {
  2143. return handleNextChunk();
  2144. }
  2145. if (file.upload.chunks[i].status !== Dropzone.SUCCESS) {
  2146. allFinished = false;
  2147. }
  2148. }
  2149. if (allFinished) {
  2150. _this15.options.chunksUploaded.call(_this15, file, function (response) {
  2151. _this15._finished(files, response || "", null);
  2152. });
  2153. }
  2154. };
  2155. if (_this15.options.parallelChunkUploads) {
  2156. for (var i = 0; i < file.upload.totalChunkCount; i++) {
  2157. handleNextChunk();
  2158. }
  2159. } else {
  2160. handleNextChunk();
  2161. }
  2162. } else {
  2163. var dataBlocks = [];
  2164. for (var _i3 = 0; _i3 < files.length; _i3++) {
  2165. dataBlocks[_i3] = {
  2166. name: _this15._getParamName(_i3),
  2167. data: transformedFiles[_i3],
  2168. filename: files[_i3].upload.filename
  2169. };
  2170. }
  2171. _this15._uploadData(files, dataBlocks);
  2172. }
  2173. });
  2174. } /// Returns the right chunk for given file and xhr
  2175. }, {
  2176. key: "_getChunk",
  2177. value: function _getChunk(file, xhr) {
  2178. for (var i = 0; i < file.upload.totalChunkCount; i++) {
  2179. if (file.upload.chunks[i] !== undefined && file.upload.chunks[i].xhr === xhr) {
  2180. return file.upload.chunks[i];
  2181. }
  2182. }
  2183. } // This function actually uploads the file(s) to the server.
  2184. // If dataBlocks contains the actual data to upload (meaning, that this could either be transformed
  2185. // files, or individual chunks for chunked upload).
  2186. }, {
  2187. key: "_uploadData",
  2188. value: function _uploadData(files, dataBlocks) {
  2189. var _this16 = this;
  2190. var xhr = new XMLHttpRequest(); // Put the xhr object in the file objects to be able to reference it later.
  2191. var _iteratorNormalCompletion21 = true;
  2192. var _didIteratorError21 = false;
  2193. var _iteratorError21 = undefined;
  2194. try {
  2195. for (var _iterator21 = files[Symbol.iterator](), _step21; !(_iteratorNormalCompletion21 = (_step21 = _iterator21.next()).done); _iteratorNormalCompletion21 = true) {
  2196. var file = _step21.value;
  2197. file.xhr = xhr;
  2198. }
  2199. } catch (err) {
  2200. _didIteratorError21 = true;
  2201. _iteratorError21 = err;
  2202. } finally {
  2203. try {
  2204. if (!_iteratorNormalCompletion21 && _iterator21["return"] != null) {
  2205. _iterator21["return"]();
  2206. }
  2207. } finally {
  2208. if (_didIteratorError21) {
  2209. throw _iteratorError21;
  2210. }
  2211. }
  2212. }
  2213. if (files[0].upload.chunked) {
  2214. // Put the xhr object in the right chunk object, so it can be associated later, and found with _getChunk
  2215. files[0].upload.chunks[dataBlocks[0].chunkIndex].xhr = xhr;
  2216. }
  2217. var method = this.resolveOption(this.options.method, files);
  2218. var url = this.resolveOption(this.options.url, files);
  2219. xhr.open(method, url, true); // Setting the timeout after open because of IE11 issue: https://gitlab.com/meno/dropzone/issues/8
  2220. xhr.timeout = this.resolveOption(this.options.timeout, files); // Has to be after `.open()`. See https://github.com/enyo/dropzone/issues/179
  2221. xhr.withCredentials = !!this.options.withCredentials;
  2222. xhr.onload = function (e) {
  2223. _this16._finishedUploading(files, xhr, e);
  2224. };
  2225. xhr.ontimeout = function () {
  2226. _this16._handleUploadError(files, xhr, "Request timedout after ".concat(_this16.options.timeout, " seconds"));
  2227. };
  2228. xhr.onerror = function () {
  2229. _this16._handleUploadError(files, xhr);
  2230. }; // Some browsers do not have the .upload property
  2231. var progressObj = xhr.upload != null ? xhr.upload : xhr;
  2232. progressObj.onprogress = function (e) {
  2233. return _this16._updateFilesUploadProgress(files, xhr, e);
  2234. };
  2235. var headers = {
  2236. "Accept": "application/json",
  2237. "Cache-Control": "no-cache",
  2238. "X-Requested-With": "XMLHttpRequest"
  2239. };
  2240. if (this.options.headers) {
  2241. Dropzone.extend(headers, this.options.headers);
  2242. }
  2243. for (var headerName in headers) {
  2244. var headerValue = headers[headerName];
  2245. if (headerValue) {
  2246. xhr.setRequestHeader(headerName, headerValue);
  2247. }
  2248. }
  2249. var formData = new FormData(); // Adding all @options parameters
  2250. if (this.options.params) {
  2251. var additionalParams = this.options.params;
  2252. if (typeof additionalParams === 'function') {
  2253. additionalParams = additionalParams.call(this, files, xhr, files[0].upload.chunked ? this._getChunk(files[0], xhr) : null);
  2254. }
  2255. for (var key in additionalParams) {
  2256. var value = additionalParams[key];
  2257. formData.append(key, value);
  2258. }
  2259. } // Let the user add additional data if necessary
  2260. var _iteratorNormalCompletion22 = true;
  2261. var _didIteratorError22 = false;
  2262. var _iteratorError22 = undefined;
  2263. try {
  2264. for (var _iterator22 = files[Symbol.iterator](), _step22; !(_iteratorNormalCompletion22 = (_step22 = _iterator22.next()).done); _iteratorNormalCompletion22 = true) {
  2265. var _file = _step22.value;
  2266. this.emit("sending", _file, xhr, formData);
  2267. }
  2268. } catch (err) {
  2269. _didIteratorError22 = true;
  2270. _iteratorError22 = err;
  2271. } finally {
  2272. try {
  2273. if (!_iteratorNormalCompletion22 && _iterator22["return"] != null) {
  2274. _iterator22["return"]();
  2275. }
  2276. } finally {
  2277. if (_didIteratorError22) {
  2278. throw _iteratorError22;
  2279. }
  2280. }
  2281. }
  2282. if (this.options.uploadMultiple) {
  2283. this.emit("sendingmultiple", files, xhr, formData);
  2284. }
  2285. this._addFormElementData(formData); // Finally add the files
  2286. // Has to be last because some servers (eg: S3) expect the file to be the last parameter
  2287. for (var i = 0; i < dataBlocks.length; i++) {
  2288. var dataBlock = dataBlocks[i];
  2289. formData.append(dataBlock.name, dataBlock.data, dataBlock.filename);
  2290. }
  2291. this.submitRequest(xhr, formData, files);
  2292. } // Transforms all files with this.options.transformFile and invokes done with the transformed files when done.
  2293. }, {
  2294. key: "_transformFiles",
  2295. value: function _transformFiles(files, done) {
  2296. var _this17 = this;
  2297. var transformedFiles = []; // Clumsy way of handling asynchronous calls, until I get to add a proper Future library.
  2298. var doneCounter = 0;
  2299. var _loop = function _loop(i) {
  2300. _this17.options.transformFile.call(_this17, files[i], function (transformedFile) {
  2301. transformedFiles[i] = transformedFile;
  2302. if (++doneCounter === files.length) {
  2303. done(transformedFiles);
  2304. }
  2305. });
  2306. };
  2307. for (var i = 0; i < files.length; i++) {
  2308. _loop(i);
  2309. }
  2310. } // Takes care of adding other input elements of the form to the AJAX request
  2311. }, {
  2312. key: "_addFormElementData",
  2313. value: function _addFormElementData(formData) {
  2314. // Take care of other input elements
  2315. if (this.element.tagName === "FORM") {
  2316. var _iteratorNormalCompletion23 = true;
  2317. var _didIteratorError23 = false;
  2318. var _iteratorError23 = undefined;
  2319. try {
  2320. for (var _iterator23 = this.element.querySelectorAll("input, textarea, select, button")[Symbol.iterator](), _step23; !(_iteratorNormalCompletion23 = (_step23 = _iterator23.next()).done); _iteratorNormalCompletion23 = true) {
  2321. var input = _step23.value;
  2322. var inputName = input.getAttribute("name");
  2323. var inputType = input.getAttribute("type");
  2324. if (inputType) inputType = inputType.toLowerCase(); // If the input doesn't have a name, we can't use it.
  2325. if (typeof inputName === 'undefined' || inputName === null) continue;
  2326. if (input.tagName === "SELECT" && input.hasAttribute("multiple")) {
  2327. // Possibly multiple values
  2328. var _iteratorNormalCompletion24 = true;
  2329. var _didIteratorError24 = false;
  2330. var _iteratorError24 = undefined;
  2331. try {
  2332. for (var _iterator24 = input.options[Symbol.iterator](), _step24; !(_iteratorNormalCompletion24 = (_step24 = _iterator24.next()).done); _iteratorNormalCompletion24 = true) {
  2333. var option = _step24.value;
  2334. if (option.selected) {
  2335. formData.append(inputName, option.value);
  2336. }
  2337. }
  2338. } catch (err) {
  2339. _didIteratorError24 = true;
  2340. _iteratorError24 = err;
  2341. } finally {
  2342. try {
  2343. if (!_iteratorNormalCompletion24 && _iterator24["return"] != null) {
  2344. _iterator24["return"]();
  2345. }
  2346. } finally {
  2347. if (_didIteratorError24) {
  2348. throw _iteratorError24;
  2349. }
  2350. }
  2351. }
  2352. } else if (!inputType || inputType !== "checkbox" && inputType !== "radio" || input.checked) {
  2353. formData.append(inputName, input.value);
  2354. }
  2355. }
  2356. } catch (err) {
  2357. _didIteratorError23 = true;
  2358. _iteratorError23 = err;
  2359. } finally {
  2360. try {
  2361. if (!_iteratorNormalCompletion23 && _iterator23["return"] != null) {
  2362. _iterator23["return"]();
  2363. }
  2364. } finally {
  2365. if (_didIteratorError23) {
  2366. throw _iteratorError23;
  2367. }
  2368. }
  2369. }
  2370. }
  2371. } // Invoked when there is new progress information about given files.
  2372. // If e is not provided, it is assumed that the upload is finished.
  2373. }, {
  2374. key: "_updateFilesUploadProgress",
  2375. value: function _updateFilesUploadProgress(files, xhr, e) {
  2376. var progress;
  2377. if (typeof e !== 'undefined') {
  2378. progress = 100 * e.loaded / e.total;
  2379. if (files[0].upload.chunked) {
  2380. var file = files[0]; // Since this is a chunked upload, we need to update the appropriate chunk progress.
  2381. var chunk = this._getChunk(file, xhr);
  2382. chunk.progress = progress;
  2383. chunk.total = e.total;
  2384. chunk.bytesSent = e.loaded;
  2385. var fileProgress = 0,
  2386. fileTotal,
  2387. fileBytesSent;
  2388. file.upload.progress = 0;
  2389. file.upload.total = 0;
  2390. file.upload.bytesSent = 0;
  2391. for (var i = 0; i < file.upload.totalChunkCount; i++) {
  2392. if (file.upload.chunks[i] !== undefined && file.upload.chunks[i].progress !== undefined) {
  2393. file.upload.progress += file.upload.chunks[i].progress;
  2394. file.upload.total += file.upload.chunks[i].total;
  2395. file.upload.bytesSent += file.upload.chunks[i].bytesSent;
  2396. }
  2397. }
  2398. file.upload.progress = file.upload.progress / file.upload.totalChunkCount;
  2399. } else {
  2400. var _iteratorNormalCompletion25 = true;
  2401. var _didIteratorError25 = false;
  2402. var _iteratorError25 = undefined;
  2403. try {
  2404. for (var _iterator25 = files[Symbol.iterator](), _step25; !(_iteratorNormalCompletion25 = (_step25 = _iterator25.next()).done); _iteratorNormalCompletion25 = true) {
  2405. var _file2 = _step25.value;
  2406. _file2.upload.progress = progress;
  2407. _file2.upload.total = e.total;
  2408. _file2.upload.bytesSent = e.loaded;
  2409. }
  2410. } catch (err) {
  2411. _didIteratorError25 = true;
  2412. _iteratorError25 = err;
  2413. } finally {
  2414. try {
  2415. if (!_iteratorNormalCompletion25 && _iterator25["return"] != null) {
  2416. _iterator25["return"]();
  2417. }
  2418. } finally {
  2419. if (_didIteratorError25) {
  2420. throw _iteratorError25;
  2421. }
  2422. }
  2423. }
  2424. }
  2425. var _iteratorNormalCompletion26 = true;
  2426. var _didIteratorError26 = false;
  2427. var _iteratorError26 = undefined;
  2428. try {
  2429. for (var _iterator26 = files[Symbol.iterator](), _step26; !(_iteratorNormalCompletion26 = (_step26 = _iterator26.next()).done); _iteratorNormalCompletion26 = true) {
  2430. var _file3 = _step26.value;
  2431. this.emit("uploadprogress", _file3, _file3.upload.progress, _file3.upload.bytesSent);
  2432. }
  2433. } catch (err) {
  2434. _didIteratorError26 = true;
  2435. _iteratorError26 = err;
  2436. } finally {
  2437. try {
  2438. if (!_iteratorNormalCompletion26 && _iterator26["return"] != null) {
  2439. _iterator26["return"]();
  2440. }
  2441. } finally {
  2442. if (_didIteratorError26) {
  2443. throw _iteratorError26;
  2444. }
  2445. }
  2446. }
  2447. } else {
  2448. // Called when the file finished uploading
  2449. var allFilesFinished = true;
  2450. progress = 100;
  2451. var _iteratorNormalCompletion27 = true;
  2452. var _didIteratorError27 = false;
  2453. var _iteratorError27 = undefined;
  2454. try {
  2455. for (var _iterator27 = files[Symbol.iterator](), _step27; !(_iteratorNormalCompletion27 = (_step27 = _iterator27.next()).done); _iteratorNormalCompletion27 = true) {
  2456. var _file4 = _step27.value;
  2457. if (_file4.upload.progress !== 100 || _file4.upload.bytesSent !== _file4.upload.total) {
  2458. allFilesFinished = false;
  2459. }
  2460. _file4.upload.progress = progress;
  2461. _file4.upload.bytesSent = _file4.upload.total;
  2462. } // Nothing to do, all files already at 100%
  2463. } catch (err) {
  2464. _didIteratorError27 = true;
  2465. _iteratorError27 = err;
  2466. } finally {
  2467. try {
  2468. if (!_iteratorNormalCompletion27 && _iterator27["return"] != null) {
  2469. _iterator27["return"]();
  2470. }
  2471. } finally {
  2472. if (_didIteratorError27) {
  2473. throw _iteratorError27;
  2474. }
  2475. }
  2476. }
  2477. if (allFilesFinished) {
  2478. return;
  2479. }
  2480. var _iteratorNormalCompletion28 = true;
  2481. var _didIteratorError28 = false;
  2482. var _iteratorError28 = undefined;
  2483. try {
  2484. for (var _iterator28 = files[Symbol.iterator](), _step28; !(_iteratorNormalCompletion28 = (_step28 = _iterator28.next()).done); _iteratorNormalCompletion28 = true) {
  2485. var _file5 = _step28.value;
  2486. this.emit("uploadprogress", _file5, progress, _file5.upload.bytesSent);
  2487. }
  2488. } catch (err) {
  2489. _didIteratorError28 = true;
  2490. _iteratorError28 = err;
  2491. } finally {
  2492. try {
  2493. if (!_iteratorNormalCompletion28 && _iterator28["return"] != null) {
  2494. _iterator28["return"]();
  2495. }
  2496. } finally {
  2497. if (_didIteratorError28) {
  2498. throw _iteratorError28;
  2499. }
  2500. }
  2501. }
  2502. }
  2503. }
  2504. }, {
  2505. key: "_finishedUploading",
  2506. value: function _finishedUploading(files, xhr, e) {
  2507. var response;
  2508. if (files[0].status === Dropzone.CANCELED) {
  2509. return;
  2510. }
  2511. if (xhr.readyState !== 4) {
  2512. return;
  2513. }
  2514. if (xhr.responseType !== 'arraybuffer' && xhr.responseType !== 'blob') {
  2515. response = xhr.responseText;
  2516. if (xhr.getResponseHeader("content-type") && ~xhr.getResponseHeader("content-type").indexOf("application/json")) {
  2517. try {
  2518. response = JSON.parse(response);
  2519. } catch (error) {
  2520. e = error;
  2521. response = "Invalid JSON response from server.";
  2522. }
  2523. }
  2524. }
  2525. this._updateFilesUploadProgress(files);
  2526. if (!(200 <= xhr.status && xhr.status < 300)) {
  2527. this._handleUploadError(files, xhr, response);
  2528. } else {
  2529. if (files[0].upload.chunked) {
  2530. files[0].upload.finishedChunkUpload(this._getChunk(files[0], xhr), response);
  2531. } else {
  2532. this._finished(files, response, e);
  2533. }
  2534. }
  2535. }
  2536. }, {
  2537. key: "_handleUploadError",
  2538. value: function _handleUploadError(files, xhr, response) {
  2539. if (files[0].status === Dropzone.CANCELED) {
  2540. return;
  2541. }
  2542. if (files[0].upload.chunked && this.options.retryChunks) {
  2543. var chunk = this._getChunk(files[0], xhr);
  2544. if (chunk.retries++ < this.options.retryChunksLimit) {
  2545. this._uploadData(files, [chunk.dataBlock]);
  2546. return;
  2547. } else {
  2548. console.warn('Retried this chunk too often. Giving up.');
  2549. }
  2550. }
  2551. this._errorProcessing(files, response || this.options.dictResponseError.replace("{{statusCode}}", xhr.status), xhr);
  2552. }
  2553. }, {
  2554. key: "submitRequest",
  2555. value: function submitRequest(xhr, formData, files) {
  2556. xhr.send(formData);
  2557. } // Called internally when processing is finished.
  2558. // Individual callbacks have to be called in the appropriate sections.
  2559. }, {
  2560. key: "_finished",
  2561. value: function _finished(files, responseText, e) {
  2562. var _iteratorNormalCompletion29 = true;
  2563. var _didIteratorError29 = false;
  2564. var _iteratorError29 = undefined;
  2565. try {
  2566. for (var _iterator29 = files[Symbol.iterator](), _step29; !(_iteratorNormalCompletion29 = (_step29 = _iterator29.next()).done); _iteratorNormalCompletion29 = true) {
  2567. var file = _step29.value;
  2568. file.status = Dropzone.SUCCESS;
  2569. this.emit("success", file, responseText, e);
  2570. this.emit("complete", file);
  2571. }
  2572. } catch (err) {
  2573. _didIteratorError29 = true;
  2574. _iteratorError29 = err;
  2575. } finally {
  2576. try {
  2577. if (!_iteratorNormalCompletion29 && _iterator29["return"] != null) {
  2578. _iterator29["return"]();
  2579. }
  2580. } finally {
  2581. if (_didIteratorError29) {
  2582. throw _iteratorError29;
  2583. }
  2584. }
  2585. }
  2586. if (this.options.uploadMultiple) {
  2587. this.emit("successmultiple", files, responseText, e);
  2588. this.emit("completemultiple", files);
  2589. }
  2590. if (this.options.autoProcessQueue) {
  2591. return this.processQueue();
  2592. }
  2593. } // Called internally when processing is finished.
  2594. // Individual callbacks have to be called in the appropriate sections.
  2595. }, {
  2596. key: "_errorProcessing",
  2597. value: function _errorProcessing(files, message, xhr) {
  2598. var _iteratorNormalCompletion30 = true;
  2599. var _didIteratorError30 = false;
  2600. var _iteratorError30 = undefined;
  2601. try {
  2602. for (var _iterator30 = files[Symbol.iterator](), _step30; !(_iteratorNormalCompletion30 = (_step30 = _iterator30.next()).done); _iteratorNormalCompletion30 = true) {
  2603. var file = _step30.value;
  2604. file.status = Dropzone.ERROR;
  2605. this.emit("error", file, message, xhr);
  2606. this.emit("complete", file);
  2607. }
  2608. } catch (err) {
  2609. _didIteratorError30 = true;
  2610. _iteratorError30 = err;
  2611. } finally {
  2612. try {
  2613. if (!_iteratorNormalCompletion30 && _iterator30["return"] != null) {
  2614. _iterator30["return"]();
  2615. }
  2616. } finally {
  2617. if (_didIteratorError30) {
  2618. throw _iteratorError30;
  2619. }
  2620. }
  2621. }
  2622. if (this.options.uploadMultiple) {
  2623. this.emit("errormultiple", files, message, xhr);
  2624. this.emit("completemultiple", files);
  2625. }
  2626. if (this.options.autoProcessQueue) {
  2627. return this.processQueue();
  2628. }
  2629. }
  2630. }], [{
  2631. key: "uuidv4",
  2632. value: function uuidv4() {
  2633. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  2634. var r = Math.random() * 16 | 0,
  2635. v = c === 'x' ? r : r & 0x3 | 0x8;
  2636. return v.toString(16);
  2637. });
  2638. }
  2639. }]);
  2640. return Dropzone;
  2641. }(Emitter);
  2642. Dropzone.initClass();
  2643. Dropzone.version = "5.7.0"; // This is a map of options for your different dropzones. Add configurations
  2644. // to this object for your different dropzone elemens.
  2645. //
  2646. // Example:
  2647. //
  2648. // Dropzone.options.myDropzoneElementId = { maxFilesize: 1 };
  2649. //
  2650. // To disable autoDiscover for a specific element, you can set `false` as an option:
  2651. //
  2652. // Dropzone.options.myDisabledElementId = false;
  2653. //
  2654. // And in html:
  2655. //
  2656. // <form action="/upload" id="my-dropzone-element-id" class="dropzone"></form>
  2657. Dropzone.options = {}; // Returns the options for an element or undefined if none available.
  2658. Dropzone.optionsForElement = function (element) {
  2659. // Get the `Dropzone.options.elementId` for this element if it exists
  2660. if (element.getAttribute("id")) {
  2661. return Dropzone.options[camelize(element.getAttribute("id"))];
  2662. } else {
  2663. return undefined;
  2664. }
  2665. }; // Holds a list of all dropzone instances
  2666. Dropzone.instances = []; // Returns the dropzone for given element if any
  2667. Dropzone.forElement = function (element) {
  2668. if (typeof element === "string") {
  2669. element = document.querySelector(element);
  2670. }
  2671. if ((element != null ? element.dropzone : undefined) == null) {
  2672. throw new Error("No Dropzone found for given element. This is probably because you're trying to access it before Dropzone had the time to initialize. Use the `init` option to setup any additional observers on your Dropzone.");
  2673. }
  2674. return element.dropzone;
  2675. }; // Set to false if you don't want Dropzone to automatically find and attach to .dropzone elements.
  2676. Dropzone.autoDiscover = true; // Looks for all .dropzone elements and creates a dropzone for them
  2677. Dropzone.discover = function () {
  2678. var dropzones;
  2679. if (document.querySelectorAll) {
  2680. dropzones = document.querySelectorAll(".dropzone");
  2681. } else {
  2682. dropzones = []; // IE :(
  2683. var checkElements = function checkElements(elements) {
  2684. return function () {
  2685. var result = [];
  2686. var _iteratorNormalCompletion31 = true;
  2687. var _didIteratorError31 = false;
  2688. var _iteratorError31 = undefined;
  2689. try {
  2690. for (var _iterator31 = elements[Symbol.iterator](), _step31; !(_iteratorNormalCompletion31 = (_step31 = _iterator31.next()).done); _iteratorNormalCompletion31 = true) {
  2691. var el = _step31.value;
  2692. if (/(^| )dropzone($| )/.test(el.className)) {
  2693. result.push(dropzones.push(el));
  2694. } else {
  2695. result.push(undefined);
  2696. }
  2697. }
  2698. } catch (err) {
  2699. _didIteratorError31 = true;
  2700. _iteratorError31 = err;
  2701. } finally {
  2702. try {
  2703. if (!_iteratorNormalCompletion31 && _iterator31["return"] != null) {
  2704. _iterator31["return"]();
  2705. }
  2706. } finally {
  2707. if (_didIteratorError31) {
  2708. throw _iteratorError31;
  2709. }
  2710. }
  2711. }
  2712. return result;
  2713. }();
  2714. };
  2715. checkElements(document.getElementsByTagName("div"));
  2716. checkElements(document.getElementsByTagName("form"));
  2717. }
  2718. return function () {
  2719. var result = [];
  2720. var _iteratorNormalCompletion32 = true;
  2721. var _didIteratorError32 = false;
  2722. var _iteratorError32 = undefined;
  2723. try {
  2724. for (var _iterator32 = dropzones[Symbol.iterator](), _step32; !(_iteratorNormalCompletion32 = (_step32 = _iterator32.next()).done); _iteratorNormalCompletion32 = true) {
  2725. var dropzone = _step32.value;
  2726. // Create a dropzone unless auto discover has been disabled for specific element
  2727. if (Dropzone.optionsForElement(dropzone) !== false) {
  2728. result.push(new Dropzone(dropzone));
  2729. } else {
  2730. result.push(undefined);
  2731. }
  2732. }
  2733. } catch (err) {
  2734. _didIteratorError32 = true;
  2735. _iteratorError32 = err;
  2736. } finally {
  2737. try {
  2738. if (!_iteratorNormalCompletion32 && _iterator32["return"] != null) {
  2739. _iterator32["return"]();
  2740. }
  2741. } finally {
  2742. if (_didIteratorError32) {
  2743. throw _iteratorError32;
  2744. }
  2745. }
  2746. }
  2747. return result;
  2748. }();
  2749. }; // Since the whole Drag'n'Drop API is pretty new, some browsers implement it,
  2750. // but not correctly.
  2751. // So I created a blacklist of userAgents. Yes, yes. Browser sniffing, I know.
  2752. // But what to do when browsers *theoretically* support an API, but crash
  2753. // when using it.
  2754. //
  2755. // This is a list of regular expressions tested against navigator.userAgent
  2756. //
  2757. // ** It should only be used on browser that *do* support the API, but
  2758. // incorrectly **
  2759. //
  2760. Dropzone.blacklistedBrowsers = [// The mac os and windows phone version of opera 12 seems to have a problem with the File drag'n'drop API.
  2761. /opera.*(Macintosh|Windows Phone).*version\/12/i]; // Checks if the browser is supported
  2762. Dropzone.isBrowserSupported = function () {
  2763. var capableBrowser = true;
  2764. if (window.File && window.FileReader && window.FileList && window.Blob && window.FormData && document.querySelector) {
  2765. if (!("classList" in document.createElement("a"))) {
  2766. capableBrowser = false;
  2767. } else {
  2768. // The browser supports the API, but may be blacklisted.
  2769. var _iteratorNormalCompletion33 = true;
  2770. var _didIteratorError33 = false;
  2771. var _iteratorError33 = undefined;
  2772. try {
  2773. for (var _iterator33 = Dropzone.blacklistedBrowsers[Symbol.iterator](), _step33; !(_iteratorNormalCompletion33 = (_step33 = _iterator33.next()).done); _iteratorNormalCompletion33 = true) {
  2774. var regex = _step33.value;
  2775. if (regex.test(navigator.userAgent)) {
  2776. capableBrowser = false;
  2777. continue;
  2778. }
  2779. }
  2780. } catch (err) {
  2781. _didIteratorError33 = true;
  2782. _iteratorError33 = err;
  2783. } finally {
  2784. try {
  2785. if (!_iteratorNormalCompletion33 && _iterator33["return"] != null) {
  2786. _iterator33["return"]();
  2787. }
  2788. } finally {
  2789. if (_didIteratorError33) {
  2790. throw _iteratorError33;
  2791. }
  2792. }
  2793. }
  2794. }
  2795. } else {
  2796. capableBrowser = false;
  2797. }
  2798. return capableBrowser;
  2799. };
  2800. Dropzone.dataURItoBlob = function (dataURI) {
  2801. // convert base64 to raw binary data held in a string
  2802. // doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this
  2803. var byteString = atob(dataURI.split(',')[1]); // separate out the mime component
  2804. var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]; // write the bytes of the string to an ArrayBuffer
  2805. var ab = new ArrayBuffer(byteString.length);
  2806. var ia = new Uint8Array(ab);
  2807. for (var i = 0, end = byteString.length, asc = 0 <= end; asc ? i <= end : i >= end; asc ? i++ : i--) {
  2808. ia[i] = byteString.charCodeAt(i);
  2809. } // write the ArrayBuffer to a blob
  2810. return new Blob([ab], {
  2811. type: mimeString
  2812. });
  2813. }; // Returns an array without the rejected item
  2814. var without = function without(list, rejectedItem) {
  2815. return list.filter(function (item) {
  2816. return item !== rejectedItem;
  2817. }).map(function (item) {
  2818. return item;
  2819. });
  2820. }; // abc-def_ghi -> abcDefGhi
  2821. var camelize = function camelize(str) {
  2822. return str.replace(/[\-_](\w)/g, function (match) {
  2823. return match.charAt(1).toUpperCase();
  2824. });
  2825. }; // Creates an element from string
  2826. Dropzone.createElement = function (string) {
  2827. var div = document.createElement("div");
  2828. div.innerHTML = string;
  2829. return div.childNodes[0];
  2830. }; // Tests if given element is inside (or simply is) the container
  2831. Dropzone.elementInside = function (element, container) {
  2832. if (element === container) {
  2833. return true;
  2834. } // Coffeescript doesn't support do/while loops
  2835. while (element = element.parentNode) {
  2836. if (element === container) {
  2837. return true;
  2838. }
  2839. }
  2840. return false;
  2841. };
  2842. Dropzone.getElement = function (el, name) {
  2843. var element;
  2844. if (typeof el === "string") {
  2845. element = document.querySelector(el);
  2846. } else if (el.nodeType != null) {
  2847. element = el;
  2848. }
  2849. if (element == null) {
  2850. throw new Error("Invalid `".concat(name, "` option provided. Please provide a CSS selector or a plain HTML element."));
  2851. }
  2852. return element;
  2853. };
  2854. Dropzone.getElements = function (els, name) {
  2855. var el, elements;
  2856. if (els instanceof Array) {
  2857. elements = [];
  2858. try {
  2859. var _iteratorNormalCompletion34 = true;
  2860. var _didIteratorError34 = false;
  2861. var _iteratorError34 = undefined;
  2862. try {
  2863. for (var _iterator34 = els[Symbol.iterator](), _step34; !(_iteratorNormalCompletion34 = (_step34 = _iterator34.next()).done); _iteratorNormalCompletion34 = true) {
  2864. el = _step34.value;
  2865. elements.push(this.getElement(el, name));
  2866. }
  2867. } catch (err) {
  2868. _didIteratorError34 = true;
  2869. _iteratorError34 = err;
  2870. } finally {
  2871. try {
  2872. if (!_iteratorNormalCompletion34 && _iterator34["return"] != null) {
  2873. _iterator34["return"]();
  2874. }
  2875. } finally {
  2876. if (_didIteratorError34) {
  2877. throw _iteratorError34;
  2878. }
  2879. }
  2880. }
  2881. } catch (e) {
  2882. elements = null;
  2883. }
  2884. } else if (typeof els === "string") {
  2885. elements = [];
  2886. var _iteratorNormalCompletion35 = true;
  2887. var _didIteratorError35 = false;
  2888. var _iteratorError35 = undefined;
  2889. try {
  2890. for (var _iterator35 = document.querySelectorAll(els)[Symbol.iterator](), _step35; !(_iteratorNormalCompletion35 = (_step35 = _iterator35.next()).done); _iteratorNormalCompletion35 = true) {
  2891. el = _step35.value;
  2892. elements.push(el);
  2893. }
  2894. } catch (err) {
  2895. _didIteratorError35 = true;
  2896. _iteratorError35 = err;
  2897. } finally {
  2898. try {
  2899. if (!_iteratorNormalCompletion35 && _iterator35["return"] != null) {
  2900. _iterator35["return"]();
  2901. }
  2902. } finally {
  2903. if (_didIteratorError35) {
  2904. throw _iteratorError35;
  2905. }
  2906. }
  2907. }
  2908. } else if (els.nodeType != null) {
  2909. elements = [els];
  2910. }
  2911. if (elements == null || !elements.length) {
  2912. throw new Error("Invalid `".concat(name, "` option provided. Please provide a CSS selector, a plain HTML element or a list of those."));
  2913. }
  2914. return elements;
  2915. }; // Asks the user the question and calls accepted or rejected accordingly
  2916. //
  2917. // The default implementation just uses `window.confirm` and then calls the
  2918. // appropriate callback.
  2919. Dropzone.confirm = function (question, accepted, rejected) {
  2920. if (window.confirm(question)) {
  2921. return accepted();
  2922. } else if (rejected != null) {
  2923. return rejected();
  2924. }
  2925. }; // Validates the mime type like this:
  2926. //
  2927. // https://developer.mozilla.org/en-US/docs/HTML/Element/input#attr-accept
  2928. Dropzone.isValidFile = function (file, acceptedFiles) {
  2929. if (!acceptedFiles) {
  2930. return true;
  2931. } // If there are no accepted mime types, it's OK
  2932. acceptedFiles = acceptedFiles.split(",");
  2933. var mimeType = file.type;
  2934. var baseMimeType = mimeType.replace(/\/.*$/, "");
  2935. var _iteratorNormalCompletion36 = true;
  2936. var _didIteratorError36 = false;
  2937. var _iteratorError36 = undefined;
  2938. try {
  2939. for (var _iterator36 = acceptedFiles[Symbol.iterator](), _step36; !(_iteratorNormalCompletion36 = (_step36 = _iterator36.next()).done); _iteratorNormalCompletion36 = true) {
  2940. var validType = _step36.value;
  2941. validType = validType.trim();
  2942. if (validType.charAt(0) === ".") {
  2943. if (file.name.toLowerCase().indexOf(validType.toLowerCase(), file.name.length - validType.length) !== -1) {
  2944. return true;
  2945. }
  2946. } else if (/\/\*$/.test(validType)) {
  2947. // This is something like a image/* mime type
  2948. if (baseMimeType === validType.replace(/\/.*$/, "")) {
  2949. return true;
  2950. }
  2951. } else {
  2952. if (mimeType === validType) {
  2953. return true;
  2954. }
  2955. }
  2956. }
  2957. } catch (err) {
  2958. _didIteratorError36 = true;
  2959. _iteratorError36 = err;
  2960. } finally {
  2961. try {
  2962. if (!_iteratorNormalCompletion36 && _iterator36["return"] != null) {
  2963. _iterator36["return"]();
  2964. }
  2965. } finally {
  2966. if (_didIteratorError36) {
  2967. throw _iteratorError36;
  2968. }
  2969. }
  2970. }
  2971. return false;
  2972. }; // Augment jQuery
  2973. if (typeof jQuery !== 'undefined' && jQuery !== null) {
  2974. jQuery.fn.dropzone = function (options) {
  2975. return this.each(function () {
  2976. return new Dropzone(this, options);
  2977. });
  2978. };
  2979. }
  2980. if (typeof module !== 'undefined' && module !== null) {
  2981. module.exports = Dropzone;
  2982. } else {
  2983. window.Dropzone = Dropzone;
  2984. } // Dropzone file status codes
  2985. Dropzone.ADDED = "added";
  2986. Dropzone.QUEUED = "queued"; // For backwards compatibility. Now, if a file is accepted, it's either queued
  2987. // or uploading.
  2988. Dropzone.ACCEPTED = Dropzone.QUEUED;
  2989. Dropzone.UPLOADING = "uploading";
  2990. Dropzone.PROCESSING = Dropzone.UPLOADING; // alias
  2991. Dropzone.CANCELED = "canceled";
  2992. Dropzone.ERROR = "error";
  2993. Dropzone.SUCCESS = "success";
  2994. /*
  2995. Bugfix for iOS 6 and 7
  2996. Source: http://stackoverflow.com/questions/11929099/html5-canvas-drawimage-ratio-bug-ios
  2997. based on the work of https://github.com/stomita/ios-imagefile-megapixel
  2998. */
  2999. // Detecting vertical squash in loaded image.
  3000. // Fixes a bug which squash image vertically while drawing into canvas for some images.
  3001. // This is a bug in iOS6 devices. This function from https://github.com/stomita/ios-imagefile-megapixel
  3002. var detectVerticalSquash = function detectVerticalSquash(img) {
  3003. var iw = img.naturalWidth;
  3004. var ih = img.naturalHeight;
  3005. var canvas = document.createElement("canvas");
  3006. canvas.width = 1;
  3007. canvas.height = ih;
  3008. var ctx = canvas.getContext("2d");
  3009. ctx.drawImage(img, 0, 0);
  3010. var _ctx$getImageData = ctx.getImageData(1, 0, 1, ih),
  3011. data = _ctx$getImageData.data; // search image edge pixel position in case it is squashed vertically.
  3012. var sy = 0;
  3013. var ey = ih;
  3014. var py = ih;
  3015. while (py > sy) {
  3016. var alpha = data[(py - 1) * 4 + 3];
  3017. if (alpha === 0) {
  3018. ey = py;
  3019. } else {
  3020. sy = py;
  3021. }
  3022. py = ey + sy >> 1;
  3023. }
  3024. var ratio = py / ih;
  3025. if (ratio === 0) {
  3026. return 1;
  3027. } else {
  3028. return ratio;
  3029. }
  3030. }; // A replacement for context.drawImage
  3031. // (args are for source and destination).
  3032. var drawImageIOSFix = function drawImageIOSFix(ctx, img, sx, sy, sw, sh, dx, dy, dw, dh) {
  3033. var vertSquashRatio = detectVerticalSquash(img);
  3034. return ctx.drawImage(img, sx, sy, sw, sh, dx, dy, dw, dh / vertSquashRatio);
  3035. }; // Based on MinifyJpeg
  3036. // Source: http://www.perry.cz/files/ExifRestorer.js
  3037. // http://elicon.blog57.fc2.com/blog-entry-206.html
  3038. var ExifRestore =
  3039. /*#__PURE__*/
  3040. function () {
  3041. function ExifRestore() {
  3042. _classCallCheck(this, ExifRestore);
  3043. }
  3044. _createClass(ExifRestore, null, [{
  3045. key: "initClass",
  3046. value: function initClass() {
  3047. this.KEY_STR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  3048. }
  3049. }, {
  3050. key: "encode64",
  3051. value: function encode64(input) {
  3052. var output = '';
  3053. var chr1 = undefined;
  3054. var chr2 = undefined;
  3055. var chr3 = '';
  3056. var enc1 = undefined;
  3057. var enc2 = undefined;
  3058. var enc3 = undefined;
  3059. var enc4 = '';
  3060. var i = 0;
  3061. while (true) {
  3062. chr1 = input[i++];
  3063. chr2 = input[i++];
  3064. chr3 = input[i++];
  3065. enc1 = chr1 >> 2;
  3066. enc2 = (chr1 & 3) << 4 | chr2 >> 4;
  3067. enc3 = (chr2 & 15) << 2 | chr3 >> 6;
  3068. enc4 = chr3 & 63;
  3069. if (isNaN(chr2)) {
  3070. enc3 = enc4 = 64;
  3071. } else if (isNaN(chr3)) {
  3072. enc4 = 64;
  3073. }
  3074. output = output + this.KEY_STR.charAt(enc1) + this.KEY_STR.charAt(enc2) + this.KEY_STR.charAt(enc3) + this.KEY_STR.charAt(enc4);
  3075. chr1 = chr2 = chr3 = '';
  3076. enc1 = enc2 = enc3 = enc4 = '';
  3077. if (!(i < input.length)) {
  3078. break;
  3079. }
  3080. }
  3081. return output;
  3082. }
  3083. }, {
  3084. key: "restore",
  3085. value: function restore(origFileBase64, resizedFileBase64) {
  3086. if (!origFileBase64.match('data:image/jpeg;base64,')) {
  3087. return resizedFileBase64;
  3088. }
  3089. var rawImage = this.decode64(origFileBase64.replace('data:image/jpeg;base64,', ''));
  3090. var segments = this.slice2Segments(rawImage);
  3091. var image = this.exifManipulation(resizedFileBase64, segments);
  3092. return "data:image/jpeg;base64,".concat(this.encode64(image));
  3093. }
  3094. }, {
  3095. key: "exifManipulation",
  3096. value: function exifManipulation(resizedFileBase64, segments) {
  3097. var exifArray = this.getExifArray(segments);
  3098. var newImageArray = this.insertExif(resizedFileBase64, exifArray);
  3099. var aBuffer = new Uint8Array(newImageArray);
  3100. return aBuffer;
  3101. }
  3102. }, {
  3103. key: "getExifArray",
  3104. value: function getExifArray(segments) {
  3105. var seg = undefined;
  3106. var x = 0;
  3107. while (x < segments.length) {
  3108. seg = segments[x];
  3109. if (seg[0] === 255 & seg[1] === 225) {
  3110. return seg;
  3111. }
  3112. x++;
  3113. }
  3114. return [];
  3115. }
  3116. }, {
  3117. key: "insertExif",
  3118. value: function insertExif(resizedFileBase64, exifArray) {
  3119. var imageData = resizedFileBase64.replace('data:image/jpeg;base64,', '');
  3120. var buf = this.decode64(imageData);
  3121. var separatePoint = buf.indexOf(255, 3);
  3122. var mae = buf.slice(0, separatePoint);
  3123. var ato = buf.slice(separatePoint);
  3124. var array = mae;
  3125. array = array.concat(exifArray);
  3126. array = array.concat(ato);
  3127. return array;
  3128. }
  3129. }, {
  3130. key: "slice2Segments",
  3131. value: function slice2Segments(rawImageArray) {
  3132. var head = 0;
  3133. var segments = [];
  3134. while (true) {
  3135. var length;
  3136. if (rawImageArray[head] === 255 & rawImageArray[head + 1] === 218) {
  3137. break;
  3138. }
  3139. if (rawImageArray[head] === 255 & rawImageArray[head + 1] === 216) {
  3140. head += 2;
  3141. } else {
  3142. length = rawImageArray[head + 2] * 256 + rawImageArray[head + 3];
  3143. var endPoint = head + length + 2;
  3144. var seg = rawImageArray.slice(head, endPoint);
  3145. segments.push(seg);
  3146. head = endPoint;
  3147. }
  3148. if (head > rawImageArray.length) {
  3149. break;
  3150. }
  3151. }
  3152. return segments;
  3153. }
  3154. }, {
  3155. key: "decode64",
  3156. value: function decode64(input) {
  3157. var output = '';
  3158. var chr1 = undefined;
  3159. var chr2 = undefined;
  3160. var chr3 = '';
  3161. var enc1 = undefined;
  3162. var enc2 = undefined;
  3163. var enc3 = undefined;
  3164. var enc4 = '';
  3165. var i = 0;
  3166. var buf = []; // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
  3167. var base64test = /[^A-Za-z0-9\+\/\=]/g;
  3168. if (base64test.exec(input)) {
  3169. console.warn('There were invalid base64 characters in the input text.\nValid base64 characters are A-Z, a-z, 0-9, \'+\', \'/\',and \'=\'\nExpect errors in decoding.');
  3170. }
  3171. input = input.replace(/[^A-Za-z0-9\+\/\=]/g, '');
  3172. while (true) {
  3173. enc1 = this.KEY_STR.indexOf(input.charAt(i++));
  3174. enc2 = this.KEY_STR.indexOf(input.charAt(i++));
  3175. enc3 = this.KEY_STR.indexOf(input.charAt(i++));
  3176. enc4 = this.KEY_STR.indexOf(input.charAt(i++));
  3177. chr1 = enc1 << 2 | enc2 >> 4;
  3178. chr2 = (enc2 & 15) << 4 | enc3 >> 2;
  3179. chr3 = (enc3 & 3) << 6 | enc4;
  3180. buf.push(chr1);
  3181. if (enc3 !== 64) {
  3182. buf.push(chr2);
  3183. }
  3184. if (enc4 !== 64) {
  3185. buf.push(chr3);
  3186. }
  3187. chr1 = chr2 = chr3 = '';
  3188. enc1 = enc2 = enc3 = enc4 = '';
  3189. if (!(i < input.length)) {
  3190. break;
  3191. }
  3192. }
  3193. return buf;
  3194. }
  3195. }]);
  3196. return ExifRestore;
  3197. }();
  3198. ExifRestore.initClass();
  3199. /*
  3200. * contentloaded.js
  3201. *
  3202. * Author: Diego Perini (diego.perini at gmail.com)
  3203. * Summary: cross-browser wrapper for DOMContentLoaded
  3204. * Updated: 20101020
  3205. * License: MIT
  3206. * Version: 1.2
  3207. *
  3208. * URL:
  3209. * http://javascript.nwbox.com/ContentLoaded/
  3210. * http://javascript.nwbox.com/ContentLoaded/MIT-LICENSE
  3211. */
  3212. // @win window reference
  3213. // @fn function reference
  3214. var contentLoaded = function contentLoaded(win, fn) {
  3215. var done = false;
  3216. var top = true;
  3217. var doc = win.document;
  3218. var root = doc.documentElement;
  3219. var add = doc.addEventListener ? "addEventListener" : "attachEvent";
  3220. var rem = doc.addEventListener ? "removeEventListener" : "detachEvent";
  3221. var pre = doc.addEventListener ? "" : "on";
  3222. var init = function init(e) {
  3223. if (e.type === "readystatechange" && doc.readyState !== "complete") {
  3224. return;
  3225. }
  3226. (e.type === "load" ? win : doc)[rem](pre + e.type, init, false);
  3227. if (!done && (done = true)) {
  3228. return fn.call(win, e.type || e);
  3229. }
  3230. };
  3231. var poll = function poll() {
  3232. try {
  3233. root.doScroll("left");
  3234. } catch (e) {
  3235. setTimeout(poll, 50);
  3236. return;
  3237. }
  3238. return init("poll");
  3239. };
  3240. if (doc.readyState !== "complete") {
  3241. if (doc.createEventObject && root.doScroll) {
  3242. try {
  3243. top = !win.frameElement;
  3244. } catch (error) {}
  3245. if (top) {
  3246. poll();
  3247. }
  3248. }
  3249. doc[add](pre + "DOMContentLoaded", init, false);
  3250. doc[add](pre + "readystatechange", init, false);
  3251. return win[add](pre + "load", init, false);
  3252. }
  3253. }; // As a single function to be able to write tests.
  3254. Dropzone._autoDiscoverFunction = function () {
  3255. if (Dropzone.autoDiscover) {
  3256. return Dropzone.discover();
  3257. }
  3258. };
  3259. contentLoaded(window, Dropzone._autoDiscoverFunction);
  3260. function __guard__(value, transform) {
  3261. return typeof value !== 'undefined' && value !== null ? transform(value) : undefined;
  3262. }
  3263. function __guardMethod__(obj, methodName, transform) {
  3264. if (typeof obj !== 'undefined' && obj !== null && typeof obj[methodName] === 'function') {
  3265. return transform(obj, methodName);
  3266. } else {
  3267. return undefined;
  3268. }
  3269. }
  3270. return module.exports;
  3271. }));