dropzone.js 131 KB

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