dropzone.js 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842
  1. ;(function(){
  2. /**
  3. * Require the module at `name`.
  4. *
  5. * @param {String} name
  6. * @return {Object} exports
  7. * @api public
  8. */
  9. function require(name) {
  10. var module = require.modules[name];
  11. if (!module) throw new Error('failed to require "' + name + '"');
  12. if (!('exports' in module) && typeof module.definition === 'function') {
  13. module.client = module.component = true;
  14. module.definition.call(this, module.exports = {}, module);
  15. delete module.definition;
  16. }
  17. return module.exports;
  18. }
  19. /**
  20. * Registered modules.
  21. */
  22. require.modules = {};
  23. /**
  24. * Register module at `name` with callback `definition`.
  25. *
  26. * @param {String} name
  27. * @param {Function} definition
  28. * @api private
  29. */
  30. require.register = function (name, definition) {
  31. require.modules[name] = {
  32. definition: definition
  33. };
  34. };
  35. /**
  36. * Define a module's exports immediately with `exports`.
  37. *
  38. * @param {String} name
  39. * @param {Generic} exports
  40. * @api private
  41. */
  42. require.define = function (name, exports) {
  43. require.modules[name] = {
  44. exports: exports
  45. };
  46. };
  47. require.register("component~emitter@1.1.2", function (exports, module) {
  48. /**
  49. * Expose `Emitter`.
  50. */
  51. module.exports = Emitter;
  52. /**
  53. * Initialize a new `Emitter`.
  54. *
  55. * @api public
  56. */
  57. function Emitter(obj) {
  58. if (obj) return mixin(obj);
  59. };
  60. /**
  61. * Mixin the emitter properties.
  62. *
  63. * @param {Object} obj
  64. * @return {Object}
  65. * @api private
  66. */
  67. function mixin(obj) {
  68. for (var key in Emitter.prototype) {
  69. obj[key] = Emitter.prototype[key];
  70. }
  71. return obj;
  72. }
  73. /**
  74. * Listen on the given `event` with `fn`.
  75. *
  76. * @param {String} event
  77. * @param {Function} fn
  78. * @return {Emitter}
  79. * @api public
  80. */
  81. Emitter.prototype.on =
  82. Emitter.prototype.addEventListener = function(event, fn){
  83. this._callbacks = this._callbacks || {};
  84. (this._callbacks[event] = this._callbacks[event] || [])
  85. .push(fn);
  86. return this;
  87. };
  88. /**
  89. * Adds an `event` listener that will be invoked a single
  90. * time then automatically removed.
  91. *
  92. * @param {String} event
  93. * @param {Function} fn
  94. * @return {Emitter}
  95. * @api public
  96. */
  97. Emitter.prototype.once = function(event, fn){
  98. var self = this;
  99. this._callbacks = this._callbacks || {};
  100. function on() {
  101. self.off(event, on);
  102. fn.apply(this, arguments);
  103. }
  104. on.fn = fn;
  105. this.on(event, on);
  106. return this;
  107. };
  108. /**
  109. * Remove the given callback for `event` or all
  110. * registered callbacks.
  111. *
  112. * @param {String} event
  113. * @param {Function} fn
  114. * @return {Emitter}
  115. * @api public
  116. */
  117. Emitter.prototype.off =
  118. Emitter.prototype.removeListener =
  119. Emitter.prototype.removeAllListeners =
  120. Emitter.prototype.removeEventListener = function(event, fn){
  121. this._callbacks = this._callbacks || {};
  122. // all
  123. if (0 == arguments.length) {
  124. this._callbacks = {};
  125. return this;
  126. }
  127. // specific event
  128. var callbacks = this._callbacks[event];
  129. if (!callbacks) return this;
  130. // remove all handlers
  131. if (1 == arguments.length) {
  132. delete this._callbacks[event];
  133. return this;
  134. }
  135. // remove specific handler
  136. var cb;
  137. for (var i = 0; i < callbacks.length; i++) {
  138. cb = callbacks[i];
  139. if (cb === fn || cb.fn === fn) {
  140. callbacks.splice(i, 1);
  141. break;
  142. }
  143. }
  144. return this;
  145. };
  146. /**
  147. * Emit `event` with the given args.
  148. *
  149. * @param {String} event
  150. * @param {Mixed} ...
  151. * @return {Emitter}
  152. */
  153. Emitter.prototype.emit = function(event){
  154. this._callbacks = this._callbacks || {};
  155. var args = [].slice.call(arguments, 1)
  156. , callbacks = this._callbacks[event];
  157. if (callbacks) {
  158. callbacks = callbacks.slice(0);
  159. for (var i = 0, len = callbacks.length; i < len; ++i) {
  160. callbacks[i].apply(this, args);
  161. }
  162. }
  163. return this;
  164. };
  165. /**
  166. * Return array of callbacks for `event`.
  167. *
  168. * @param {String} event
  169. * @return {Array}
  170. * @api public
  171. */
  172. Emitter.prototype.listeners = function(event){
  173. this._callbacks = this._callbacks || {};
  174. return this._callbacks[event] || [];
  175. };
  176. /**
  177. * Check if this emitter has `event` handlers.
  178. *
  179. * @param {String} event
  180. * @return {Boolean}
  181. * @api public
  182. */
  183. Emitter.prototype.hasListeners = function(event){
  184. return !! this.listeners(event).length;
  185. };
  186. });
  187. require.register("dropzone", function (exports, module) {
  188. /**
  189. * Exposing dropzone
  190. */
  191. module.exports = require("dropzone/lib/dropzone.js");
  192. });
  193. require.register("dropzone/lib/dropzone.js", function (exports, module) {
  194. /*
  195. *
  196. * More info at [www.dropzonejs.com](http://www.dropzonejs.com)
  197. *
  198. * Copyright (c) 2012, Matias Meno
  199. *
  200. * Permission is hereby granted, free of charge, to any person obtaining a copy
  201. * of this software and associated documentation files (the "Software"), to deal
  202. * in the Software without restriction, including without limitation the rights
  203. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  204. * copies of the Software, and to permit persons to whom the Software is
  205. * furnished to do so, subject to the following conditions:
  206. *
  207. * The above copyright notice and this permission notice shall be included in
  208. * all copies or substantial portions of the Software.
  209. *
  210. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  211. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  212. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  213. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  214. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  215. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  216. * THE SOFTWARE.
  217. *
  218. */
  219. (function() {
  220. var Dropzone, Em, camelize, contentLoaded, detectVerticalSquash, drawImageIOSFix, noop, without,
  221. __hasProp = {}.hasOwnProperty,
  222. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  223. __slice = [].slice;
  224. Em = typeof Emitter !== "undefined" && Emitter !== null ? Emitter : require("component~emitter@1.1.2");
  225. noop = function() {};
  226. Dropzone = (function(_super) {
  227. var extend;
  228. __extends(Dropzone, _super);
  229. /*
  230. This is a list of all available events you can register on a dropzone object.
  231. You can register an event handler like this:
  232. dropzone.on("dragEnter", function() { });
  233. */
  234. Dropzone.prototype.events = ["drop", "dragstart", "dragend", "dragenter", "dragover", "dragleave", "addedfile", "removedfile", "thumbnail", "error", "errormultiple", "processing", "processingmultiple", "uploadprogress", "totaluploadprogress", "sending", "sendingmultiple", "success", "successmultiple", "canceled", "canceledmultiple", "complete", "completemultiple", "reset", "maxfilesexceeded", "maxfilesreached"];
  235. Dropzone.prototype.defaultOptions = {
  236. url: null,
  237. method: "post",
  238. withCredentials: false,
  239. parallelUploads: 2,
  240. uploadMultiple: false,
  241. maxFilesize: 256,
  242. paramName: "file",
  243. createImageThumbnails: true,
  244. maxThumbnailFilesize: 10,
  245. thumbnailWidth: 100,
  246. thumbnailHeight: 100,
  247. maxFiles: null,
  248. params: {},
  249. clickable: true,
  250. ignoreHiddenFiles: true,
  251. acceptedFiles: null,
  252. acceptedMimeTypes: null,
  253. autoProcessQueue: true,
  254. autoQueue: true,
  255. addRemoveLinks: false,
  256. previewsContainer: null,
  257. dictDefaultMessage: "Drop files here to upload",
  258. dictFallbackMessage: "Your browser does not support drag'n'drop file uploads.",
  259. dictFallbackText: "Please use the fallback form below to upload your files like in the olden days.",
  260. dictFileTooBig: "File is too big ({{filesize}}MiB). Max filesize: {{maxFilesize}}MiB.",
  261. dictInvalidFileType: "You can't upload files of this type.",
  262. dictResponseError: "Server responded with {{statusCode}} code.",
  263. dictCancelUpload: "Cancel upload",
  264. dictCancelUploadConfirmation: "Are you sure you want to cancel this upload?",
  265. dictRemoveFile: "Remove file",
  266. dictRemoveFileConfirmation: null,
  267. dictMaxFilesExceeded: "You can not upload any more files.",
  268. accept: function(file, done) {
  269. return done();
  270. },
  271. init: function() {
  272. return noop;
  273. },
  274. forceFallback: false,
  275. fallback: function() {
  276. var child, messageElement, span, _i, _len, _ref;
  277. this.element.className = "" + this.element.className + " dz-browser-not-supported";
  278. _ref = this.element.getElementsByTagName("div");
  279. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  280. child = _ref[_i];
  281. if (/(^| )dz-message($| )/.test(child.className)) {
  282. messageElement = child;
  283. child.className = "dz-message";
  284. continue;
  285. }
  286. }
  287. if (!messageElement) {
  288. messageElement = Dropzone.createElement("<div class=\"dz-message\"><span></span></div>");
  289. this.element.appendChild(messageElement);
  290. }
  291. span = messageElement.getElementsByTagName("span")[0];
  292. if (span) {
  293. span.textContent = this.options.dictFallbackMessage;
  294. }
  295. return this.element.appendChild(this.getFallbackForm());
  296. },
  297. resize: function(file) {
  298. var info, srcRatio, trgRatio;
  299. info = {
  300. srcX: 0,
  301. srcY: 0,
  302. srcWidth: file.width,
  303. srcHeight: file.height
  304. };
  305. srcRatio = file.width / file.height;
  306. trgRatio = this.options.thumbnailWidth / this.options.thumbnailHeight;
  307. if (file.height < this.options.thumbnailHeight || file.width < this.options.thumbnailWidth) {
  308. info.trgHeight = info.srcHeight;
  309. info.trgWidth = info.srcWidth;
  310. } else {
  311. if (srcRatio > trgRatio) {
  312. info.srcHeight = file.height;
  313. info.srcWidth = info.srcHeight * trgRatio;
  314. } else {
  315. info.srcWidth = file.width;
  316. info.srcHeight = info.srcWidth / trgRatio;
  317. }
  318. }
  319. info.srcX = (file.width - info.srcWidth) / 2;
  320. info.srcY = (file.height - info.srcHeight) / 2;
  321. return info;
  322. },
  323. /*
  324. Those functions register themselves to the events on init and handle all
  325. the user interface specific stuff. Overwriting them won't break the upload
  326. but can break the way it's displayed.
  327. You can overwrite them if you don't like the default behavior. If you just
  328. want to add an additional event handler, register it on the dropzone object
  329. and don't overwrite those options.
  330. */
  331. drop: function(e) {
  332. return this.element.classList.remove("dz-drag-hover");
  333. },
  334. dragstart: noop,
  335. dragend: function(e) {
  336. return this.element.classList.remove("dz-drag-hover");
  337. },
  338. dragenter: function(e) {
  339. return this.element.classList.add("dz-drag-hover");
  340. },
  341. dragover: function(e) {
  342. return this.element.classList.add("dz-drag-hover");
  343. },
  344. dragleave: function(e) {
  345. return this.element.classList.remove("dz-drag-hover");
  346. },
  347. paste: noop,
  348. reset: function() {
  349. return this.element.classList.remove("dz-started");
  350. },
  351. addedfile: function(file) {
  352. var node, removeFileEvent, removeLink, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _results;
  353. if (this.element === this.previewsContainer) {
  354. this.element.classList.add("dz-started");
  355. }
  356. file.previewElement = Dropzone.createElement(this.options.previewTemplate.trim());
  357. file.previewTemplate = file.previewElement;
  358. this.previewsContainer.appendChild(file.previewElement);
  359. _ref = file.previewElement.querySelectorAll("[data-dz-name]");
  360. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  361. node = _ref[_i];
  362. node.textContent = file.name;
  363. }
  364. _ref1 = file.previewElement.querySelectorAll("[data-dz-size]");
  365. for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
  366. node = _ref1[_j];
  367. node.innerHTML = this.filesize(file.size);
  368. }
  369. if (this.options.addRemoveLinks) {
  370. file._removeLink = Dropzone.createElement("<a class=\"dz-remove\" href=\"javascript:undefined;\" data-dz-remove>" + this.options.dictRemoveFile + "</a>");
  371. file.previewElement.appendChild(file._removeLink);
  372. }
  373. removeFileEvent = (function(_this) {
  374. return function(e) {
  375. e.preventDefault();
  376. e.stopPropagation();
  377. if (file.status === Dropzone.UPLOADING) {
  378. return Dropzone.confirm(_this.options.dictCancelUploadConfirmation, function() {
  379. return _this.removeFile(file);
  380. });
  381. } else {
  382. if (_this.options.dictRemoveFileConfirmation) {
  383. return Dropzone.confirm(_this.options.dictRemoveFileConfirmation, function() {
  384. return _this.removeFile(file);
  385. });
  386. } else {
  387. return _this.removeFile(file);
  388. }
  389. }
  390. };
  391. })(this);
  392. _ref2 = file.previewElement.querySelectorAll("[data-dz-remove]");
  393. _results = [];
  394. for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
  395. removeLink = _ref2[_k];
  396. _results.push(removeLink.addEventListener("click", removeFileEvent));
  397. }
  398. return _results;
  399. },
  400. removedfile: function(file) {
  401. var _ref;
  402. if ((_ref = file.previewElement) != null) {
  403. _ref.parentNode.removeChild(file.previewElement);
  404. }
  405. return this._updateMaxFilesReachedClass();
  406. },
  407. thumbnail: function(file, dataUrl) {
  408. var thumbnailElement, _i, _len, _ref, _results;
  409. file.previewElement.classList.remove("dz-file-preview");
  410. file.previewElement.classList.add("dz-image-preview");
  411. _ref = file.previewElement.querySelectorAll("[data-dz-thumbnail]");
  412. _results = [];
  413. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  414. thumbnailElement = _ref[_i];
  415. thumbnailElement.alt = file.name;
  416. _results.push(thumbnailElement.src = dataUrl);
  417. }
  418. return _results;
  419. },
  420. error: function(file, message) {
  421. var node, _i, _len, _ref, _results;
  422. file.previewElement.classList.add("dz-error");
  423. if (typeof message !== "String" && message.error) {
  424. message = message.error;
  425. }
  426. _ref = file.previewElement.querySelectorAll("[data-dz-errormessage]");
  427. _results = [];
  428. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  429. node = _ref[_i];
  430. _results.push(node.textContent = message);
  431. }
  432. return _results;
  433. },
  434. errormultiple: noop,
  435. processing: function(file) {
  436. file.previewElement.classList.add("dz-processing");
  437. if (file._removeLink) {
  438. return file._removeLink.textContent = this.options.dictCancelUpload;
  439. }
  440. },
  441. processingmultiple: noop,
  442. uploadprogress: function(file, progress, bytesSent) {
  443. var node, _i, _len, _ref, _results;
  444. _ref = file.previewElement.querySelectorAll("[data-dz-uploadprogress]");
  445. _results = [];
  446. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  447. node = _ref[_i];
  448. _results.push(node.style.width = "" + progress + "%");
  449. }
  450. return _results;
  451. },
  452. totaluploadprogress: noop,
  453. sending: noop,
  454. sendingmultiple: noop,
  455. success: function(file) {
  456. return file.previewElement.classList.add("dz-success");
  457. },
  458. successmultiple: noop,
  459. canceled: function(file) {
  460. return this.emit("error", file, "Upload canceled.");
  461. },
  462. canceledmultiple: noop,
  463. complete: function(file) {
  464. if (file._removeLink) {
  465. return file._removeLink.textContent = this.options.dictRemoveFile;
  466. }
  467. },
  468. completemultiple: noop,
  469. maxfilesexceeded: noop,
  470. maxfilesreached: noop,
  471. previewTemplate: "<div class=\"dz-preview dz-file-preview\">\n <div class=\"dz-details\">\n <div class=\"dz-filename\"><span data-dz-name></span></div>\n <div class=\"dz-size\" data-dz-size></div>\n <img data-dz-thumbnail />\n </div>\n <div class=\"dz-progress\"><span class=\"dz-upload\" data-dz-uploadprogress></span></div>\n <div class=\"dz-success-mark\"><span>✔</span></div>\n <div class=\"dz-error-mark\"><span>✘</span></div>\n <div class=\"dz-error-message\"><span data-dz-errormessage></span></div>\n</div>"
  472. };
  473. extend = function() {
  474. var key, object, objects, target, val, _i, _len;
  475. target = arguments[0], objects = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
  476. for (_i = 0, _len = objects.length; _i < _len; _i++) {
  477. object = objects[_i];
  478. for (key in object) {
  479. val = object[key];
  480. target[key] = val;
  481. }
  482. }
  483. return target;
  484. };
  485. function Dropzone(element, options) {
  486. var elementOptions, fallback, _ref;
  487. this.element = element;
  488. this.version = Dropzone.version;
  489. this.defaultOptions.previewTemplate = this.defaultOptions.previewTemplate.replace(/\n*/g, "");
  490. this.clickableElements = [];
  491. this.listeners = [];
  492. this.files = [];
  493. if (typeof this.element === "string") {
  494. this.element = document.querySelector(this.element);
  495. }
  496. if (!(this.element && (this.element.nodeType != null))) {
  497. throw new Error("Invalid dropzone element.");
  498. }
  499. if (this.element.dropzone) {
  500. throw new Error("Dropzone already attached.");
  501. }
  502. Dropzone.instances.push(this);
  503. this.element.dropzone = this;
  504. elementOptions = (_ref = Dropzone.optionsForElement(this.element)) != null ? _ref : {};
  505. this.options = extend({}, this.defaultOptions, elementOptions, options != null ? options : {});
  506. if (this.options.forceFallback || !Dropzone.isBrowserSupported()) {
  507. return this.options.fallback.call(this);
  508. }
  509. if (this.options.url == null) {
  510. this.options.url = this.element.getAttribute("action");
  511. }
  512. if (!this.options.url) {
  513. throw new Error("No URL provided.");
  514. }
  515. if (this.options.acceptedFiles && this.options.acceptedMimeTypes) {
  516. throw new Error("You can't provide both 'acceptedFiles' and 'acceptedMimeTypes'. 'acceptedMimeTypes' is deprecated.");
  517. }
  518. if (this.options.acceptedMimeTypes) {
  519. this.options.acceptedFiles = this.options.acceptedMimeTypes;
  520. delete this.options.acceptedMimeTypes;
  521. }
  522. this.options.method = this.options.method.toUpperCase();
  523. if ((fallback = this.getExistingFallback()) && fallback.parentNode) {
  524. fallback.parentNode.removeChild(fallback);
  525. }
  526. if (this.options.previewsContainer) {
  527. this.previewsContainer = Dropzone.getElement(this.options.previewsContainer, "previewsContainer");
  528. } else {
  529. this.previewsContainer = this.element;
  530. }
  531. if (this.options.clickable) {
  532. if (this.options.clickable === true) {
  533. this.clickableElements = [this.element];
  534. } else {
  535. this.clickableElements = Dropzone.getElements(this.options.clickable, "clickable");
  536. }
  537. }
  538. this.init();
  539. }
  540. Dropzone.prototype.getAcceptedFiles = function() {
  541. var file, _i, _len, _ref, _results;
  542. _ref = this.files;
  543. _results = [];
  544. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  545. file = _ref[_i];
  546. if (file.accepted) {
  547. _results.push(file);
  548. }
  549. }
  550. return _results;
  551. };
  552. Dropzone.prototype.getRejectedFiles = function() {
  553. var file, _i, _len, _ref, _results;
  554. _ref = this.files;
  555. _results = [];
  556. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  557. file = _ref[_i];
  558. if (!file.accepted) {
  559. _results.push(file);
  560. }
  561. }
  562. return _results;
  563. };
  564. Dropzone.prototype.getFilesWithStatus = function(status) {
  565. var file, _i, _len, _ref, _results;
  566. _ref = this.files;
  567. _results = [];
  568. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  569. file = _ref[_i];
  570. if (file.status === status) {
  571. _results.push(file);
  572. }
  573. }
  574. return _results;
  575. };
  576. Dropzone.prototype.getQueuedFiles = function() {
  577. return this.getFilesWithStatus(Dropzone.QUEUED);
  578. };
  579. Dropzone.prototype.getUploadingFiles = function() {
  580. return this.getFilesWithStatus(Dropzone.UPLOADING);
  581. };
  582. Dropzone.prototype.getActiveFiles = function() {
  583. var file, _i, _len, _ref, _results;
  584. _ref = this.files;
  585. _results = [];
  586. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  587. file = _ref[_i];
  588. if (file.status === Dropzone.UPLOADING || file.status === Dropzone.QUEUED) {
  589. _results.push(file);
  590. }
  591. }
  592. return _results;
  593. };
  594. Dropzone.prototype.init = function() {
  595. var eventName, noPropagation, setupHiddenFileInput, _i, _len, _ref, _ref1;
  596. if (this.element.tagName === "form") {
  597. this.element.setAttribute("enctype", "multipart/form-data");
  598. }
  599. if (this.element.classList.contains("dropzone") && !this.element.querySelector(".dz-message")) {
  600. this.element.appendChild(Dropzone.createElement("<div class=\"dz-default dz-message\"><span>" + this.options.dictDefaultMessage + "</span></div>"));
  601. }
  602. if (this.clickableElements.length) {
  603. setupHiddenFileInput = (function(_this) {
  604. return function() {
  605. if (_this.hiddenFileInput) {
  606. document.body.removeChild(_this.hiddenFileInput);
  607. }
  608. _this.hiddenFileInput = document.createElement("input");
  609. _this.hiddenFileInput.setAttribute("type", "file");
  610. if ((_this.options.maxFiles == null) || _this.options.maxFiles > 1) {
  611. _this.hiddenFileInput.setAttribute("multiple", "multiple");
  612. }
  613. _this.hiddenFileInput.className = "dz-hidden-input";
  614. if (_this.options.acceptedFiles != null) {
  615. _this.hiddenFileInput.setAttribute("accept", _this.options.acceptedFiles);
  616. }
  617. _this.hiddenFileInput.style.visibility = "hidden";
  618. _this.hiddenFileInput.style.position = "absolute";
  619. _this.hiddenFileInput.style.top = "0";
  620. _this.hiddenFileInput.style.left = "0";
  621. _this.hiddenFileInput.style.height = "0";
  622. _this.hiddenFileInput.style.width = "0";
  623. document.body.appendChild(_this.hiddenFileInput);
  624. return _this.hiddenFileInput.addEventListener("change", function() {
  625. var file, files, _i, _len;
  626. files = _this.hiddenFileInput.files;
  627. if (files.length) {
  628. for (_i = 0, _len = files.length; _i < _len; _i++) {
  629. file = files[_i];
  630. _this.addFile(file);
  631. }
  632. }
  633. return setupHiddenFileInput();
  634. });
  635. };
  636. })(this);
  637. setupHiddenFileInput();
  638. }
  639. this.URL = (_ref = window.URL) != null ? _ref : window.webkitURL;
  640. _ref1 = this.events;
  641. for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
  642. eventName = _ref1[_i];
  643. this.on(eventName, this.options[eventName]);
  644. }
  645. this.on("uploadprogress", (function(_this) {
  646. return function() {
  647. return _this.updateTotalUploadProgress();
  648. };
  649. })(this));
  650. this.on("removedfile", (function(_this) {
  651. return function() {
  652. return _this.updateTotalUploadProgress();
  653. };
  654. })(this));
  655. this.on("canceled", (function(_this) {
  656. return function(file) {
  657. return _this.emit("complete", file);
  658. };
  659. })(this));
  660. this.on("complete", (function(_this) {
  661. return function(file) {
  662. if (_this.getUploadingFiles().length === 0 && _this.getQueuedFiles().length === 0) {
  663. return setTimeout((function() {
  664. return _this.emit("queuecomplete");
  665. }), 0);
  666. }
  667. };
  668. })(this));
  669. noPropagation = function(e) {
  670. e.stopPropagation();
  671. if (e.preventDefault) {
  672. return e.preventDefault();
  673. } else {
  674. return e.returnValue = false;
  675. }
  676. };
  677. this.listeners = [
  678. {
  679. element: this.element,
  680. events: {
  681. "dragstart": (function(_this) {
  682. return function(e) {
  683. return _this.emit("dragstart", e);
  684. };
  685. })(this),
  686. "dragenter": (function(_this) {
  687. return function(e) {
  688. noPropagation(e);
  689. return _this.emit("dragenter", e);
  690. };
  691. })(this),
  692. "dragover": (function(_this) {
  693. return function(e) {
  694. var efct;
  695. try {
  696. efct = e.dataTransfer.effectAllowed;
  697. } catch (_error) {}
  698. e.dataTransfer.dropEffect = 'move' === efct || 'linkMove' === efct ? 'move' : 'copy';
  699. noPropagation(e);
  700. return _this.emit("dragover", e);
  701. };
  702. })(this),
  703. "dragleave": (function(_this) {
  704. return function(e) {
  705. return _this.emit("dragleave", e);
  706. };
  707. })(this),
  708. "drop": (function(_this) {
  709. return function(e) {
  710. noPropagation(e);
  711. return _this.drop(e);
  712. };
  713. })(this),
  714. "dragend": (function(_this) {
  715. return function(e) {
  716. return _this.emit("dragend", e);
  717. };
  718. })(this)
  719. }
  720. }
  721. ];
  722. this.clickableElements.forEach((function(_this) {
  723. return function(clickableElement) {
  724. return _this.listeners.push({
  725. element: clickableElement,
  726. events: {
  727. "click": function(evt) {
  728. if ((clickableElement !== _this.element) || (evt.target === _this.element || Dropzone.elementInside(evt.target, _this.element.querySelector(".dz-message")))) {
  729. return _this.hiddenFileInput.click();
  730. }
  731. }
  732. }
  733. });
  734. };
  735. })(this));
  736. this.enable();
  737. return this.options.init.call(this);
  738. };
  739. Dropzone.prototype.destroy = function() {
  740. var _ref;
  741. this.disable();
  742. this.removeAllFiles(true);
  743. if ((_ref = this.hiddenFileInput) != null ? _ref.parentNode : void 0) {
  744. this.hiddenFileInput.parentNode.removeChild(this.hiddenFileInput);
  745. this.hiddenFileInput = null;
  746. }
  747. delete this.element.dropzone;
  748. return Dropzone.instances.splice(Dropzone.instances.indexOf(this), 1);
  749. };
  750. Dropzone.prototype.updateTotalUploadProgress = function() {
  751. var activeFiles, file, totalBytes, totalBytesSent, totalUploadProgress, _i, _len, _ref;
  752. totalBytesSent = 0;
  753. totalBytes = 0;
  754. activeFiles = this.getActiveFiles();
  755. if (activeFiles.length) {
  756. _ref = this.getActiveFiles();
  757. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  758. file = _ref[_i];
  759. totalBytesSent += file.upload.bytesSent;
  760. totalBytes += file.upload.total;
  761. }
  762. totalUploadProgress = 100 * totalBytesSent / totalBytes;
  763. } else {
  764. totalUploadProgress = 100;
  765. }
  766. return this.emit("totaluploadprogress", totalUploadProgress, totalBytes, totalBytesSent);
  767. };
  768. Dropzone.prototype.getFallbackForm = function() {
  769. var existingFallback, fields, fieldsString, form;
  770. if (existingFallback = this.getExistingFallback()) {
  771. return existingFallback;
  772. }
  773. fieldsString = "<div class=\"dz-fallback\">";
  774. if (this.options.dictFallbackText) {
  775. fieldsString += "<p>" + this.options.dictFallbackText + "</p>";
  776. }
  777. fieldsString += "<input type=\"file\" name=\"" + this.options.paramName + (this.options.uploadMultiple ? "[]" : "") + "\" " + (this.options.uploadMultiple ? 'multiple="multiple"' : void 0) + " /><input type=\"submit\" value=\"Upload!\"></div>";
  778. fields = Dropzone.createElement(fieldsString);
  779. if (this.element.tagName !== "FORM") {
  780. form = Dropzone.createElement("<form action=\"" + this.options.url + "\" enctype=\"multipart/form-data\" method=\"" + this.options.method + "\"></form>");
  781. form.appendChild(fields);
  782. } else {
  783. this.element.setAttribute("enctype", "multipart/form-data");
  784. this.element.setAttribute("method", this.options.method);
  785. }
  786. return form != null ? form : fields;
  787. };
  788. Dropzone.prototype.getExistingFallback = function() {
  789. var fallback, getFallback, tagName, _i, _len, _ref;
  790. getFallback = function(elements) {
  791. var el, _i, _len;
  792. for (_i = 0, _len = elements.length; _i < _len; _i++) {
  793. el = elements[_i];
  794. if (/(^| )fallback($| )/.test(el.className)) {
  795. return el;
  796. }
  797. }
  798. };
  799. _ref = ["div", "form"];
  800. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  801. tagName = _ref[_i];
  802. if (fallback = getFallback(this.element.getElementsByTagName(tagName))) {
  803. return fallback;
  804. }
  805. }
  806. };
  807. Dropzone.prototype.setupEventListeners = function() {
  808. var elementListeners, event, listener, _i, _len, _ref, _results;
  809. _ref = this.listeners;
  810. _results = [];
  811. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  812. elementListeners = _ref[_i];
  813. _results.push((function() {
  814. var _ref1, _results1;
  815. _ref1 = elementListeners.events;
  816. _results1 = [];
  817. for (event in _ref1) {
  818. listener = _ref1[event];
  819. _results1.push(elementListeners.element.addEventListener(event, listener, false));
  820. }
  821. return _results1;
  822. })());
  823. }
  824. return _results;
  825. };
  826. Dropzone.prototype.removeEventListeners = function() {
  827. var elementListeners, event, listener, _i, _len, _ref, _results;
  828. _ref = this.listeners;
  829. _results = [];
  830. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  831. elementListeners = _ref[_i];
  832. _results.push((function() {
  833. var _ref1, _results1;
  834. _ref1 = elementListeners.events;
  835. _results1 = [];
  836. for (event in _ref1) {
  837. listener = _ref1[event];
  838. _results1.push(elementListeners.element.removeEventListener(event, listener, false));
  839. }
  840. return _results1;
  841. })());
  842. }
  843. return _results;
  844. };
  845. Dropzone.prototype.disable = function() {
  846. var file, _i, _len, _ref, _results;
  847. this.clickableElements.forEach(function(element) {
  848. return element.classList.remove("dz-clickable");
  849. });
  850. this.removeEventListeners();
  851. _ref = this.files;
  852. _results = [];
  853. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  854. file = _ref[_i];
  855. _results.push(this.cancelUpload(file));
  856. }
  857. return _results;
  858. };
  859. Dropzone.prototype.enable = function() {
  860. this.clickableElements.forEach(function(element) {
  861. return element.classList.add("dz-clickable");
  862. });
  863. return this.setupEventListeners();
  864. };
  865. Dropzone.prototype.filesize = function(size) {
  866. var string;
  867. if (size >= 1024 * 1024 * 1024 * 1024 / 10) {
  868. size = size / (1024 * 1024 * 1024 * 1024 / 10);
  869. string = "TiB";
  870. } else if (size >= 1024 * 1024 * 1024 / 10) {
  871. size = size / (1024 * 1024 * 1024 / 10);
  872. string = "GiB";
  873. } else if (size >= 1024 * 1024 / 10) {
  874. size = size / (1024 * 1024 / 10);
  875. string = "MiB";
  876. } else if (size >= 1024 / 10) {
  877. size = size / (1024 / 10);
  878. string = "KiB";
  879. } else {
  880. size = size * 10;
  881. string = "b";
  882. }
  883. return "<strong>" + (Math.round(size) / 10) + "</strong> " + string;
  884. };
  885. Dropzone.prototype._updateMaxFilesReachedClass = function() {
  886. if ((this.options.maxFiles != null) && this.getAcceptedFiles().length >= this.options.maxFiles) {
  887. if (this.getAcceptedFiles().length === this.options.maxFiles) {
  888. this.emit('maxfilesreached', this.files);
  889. }
  890. return this.element.classList.add("dz-max-files-reached");
  891. } else {
  892. return this.element.classList.remove("dz-max-files-reached");
  893. }
  894. };
  895. Dropzone.prototype.drop = function(e) {
  896. var files, items;
  897. if (!e.dataTransfer) {
  898. return;
  899. }
  900. this.emit("drop", e);
  901. files = e.dataTransfer.files;
  902. if (files.length) {
  903. items = e.dataTransfer.items;
  904. if (items && items.length && (items[0].webkitGetAsEntry != null)) {
  905. this._addFilesFromItems(items);
  906. } else {
  907. this.handleFiles(files);
  908. }
  909. }
  910. };
  911. Dropzone.prototype.paste = function(e) {
  912. var items, _ref;
  913. if ((e != null ? (_ref = e.clipboardData) != null ? _ref.items : void 0 : void 0) == null) {
  914. return;
  915. }
  916. this.emit("paste", e);
  917. items = e.clipboardData.items;
  918. if (items.length) {
  919. return this._addFilesFromItems(items);
  920. }
  921. };
  922. Dropzone.prototype.handleFiles = function(files) {
  923. var file, _i, _len, _results;
  924. _results = [];
  925. for (_i = 0, _len = files.length; _i < _len; _i++) {
  926. file = files[_i];
  927. _results.push(this.addFile(file));
  928. }
  929. return _results;
  930. };
  931. Dropzone.prototype._addFilesFromItems = function(items) {
  932. var entry, item, _i, _len, _results;
  933. _results = [];
  934. for (_i = 0, _len = items.length; _i < _len; _i++) {
  935. item = items[_i];
  936. if ((item.webkitGetAsEntry != null) && (entry = item.webkitGetAsEntry())) {
  937. if (entry.isFile) {
  938. _results.push(this.addFile(item.getAsFile()));
  939. } else if (entry.isDirectory) {
  940. _results.push(this._addFilesFromDirectory(entry, entry.name));
  941. } else {
  942. _results.push(void 0);
  943. }
  944. } else if (item.getAsFile != null) {
  945. if ((item.kind == null) || item.kind === "file") {
  946. _results.push(this.addFile(item.getAsFile()));
  947. } else {
  948. _results.push(void 0);
  949. }
  950. } else {
  951. _results.push(void 0);
  952. }
  953. }
  954. return _results;
  955. };
  956. Dropzone.prototype._addFilesFromDirectory = function(directory, path) {
  957. var dirReader, entriesReader;
  958. dirReader = directory.createReader();
  959. entriesReader = (function(_this) {
  960. return function(entries) {
  961. var entry, _i, _len;
  962. for (_i = 0, _len = entries.length; _i < _len; _i++) {
  963. entry = entries[_i];
  964. if (entry.isFile) {
  965. entry.file(function(file) {
  966. if (_this.options.ignoreHiddenFiles && file.name.substring(0, 1) === '.') {
  967. return;
  968. }
  969. file.fullPath = "" + path + "/" + file.name;
  970. return _this.addFile(file);
  971. });
  972. } else if (entry.isDirectory) {
  973. _this._addFilesFromDirectory(entry, "" + path + "/" + entry.name);
  974. }
  975. }
  976. };
  977. })(this);
  978. return dirReader.readEntries(entriesReader, function(error) {
  979. return typeof console !== "undefined" && console !== null ? typeof console.log === "function" ? console.log(error) : void 0 : void 0;
  980. });
  981. };
  982. Dropzone.prototype.accept = function(file, done) {
  983. if (file.size > this.options.maxFilesize * 1024 * 1024) {
  984. return done(this.options.dictFileTooBig.replace("{{filesize}}", Math.round(file.size / 1024 / 10.24) / 100).replace("{{maxFilesize}}", this.options.maxFilesize));
  985. } else if (!Dropzone.isValidFile(file, this.options.acceptedFiles)) {
  986. return done(this.options.dictInvalidFileType);
  987. } else if ((this.options.maxFiles != null) && this.getAcceptedFiles().length >= this.options.maxFiles) {
  988. done(this.options.dictMaxFilesExceeded.replace("{{maxFiles}}", this.options.maxFiles));
  989. return this.emit("maxfilesexceeded", file);
  990. } else {
  991. return this.options.accept.call(this, file, done);
  992. }
  993. };
  994. Dropzone.prototype.addFile = function(file) {
  995. file.upload = {
  996. progress: 0,
  997. total: file.size,
  998. bytesSent: 0
  999. };
  1000. this.files.push(file);
  1001. file.status = Dropzone.ADDED;
  1002. this.emit("addedfile", file);
  1003. this._enqueueThumbnail(file);
  1004. return this.accept(file, (function(_this) {
  1005. return function(error) {
  1006. if (error) {
  1007. file.accepted = false;
  1008. _this._errorProcessing([file], error);
  1009. } else {
  1010. file.accepted = true;
  1011. if (_this.options.autoQueue) {
  1012. _this.enqueueFile(file);
  1013. }
  1014. }
  1015. return _this._updateMaxFilesReachedClass();
  1016. };
  1017. })(this));
  1018. };
  1019. Dropzone.prototype.enqueueFiles = function(files) {
  1020. var file, _i, _len;
  1021. for (_i = 0, _len = files.length; _i < _len; _i++) {
  1022. file = files[_i];
  1023. this.enqueueFile(file);
  1024. }
  1025. return null;
  1026. };
  1027. Dropzone.prototype.enqueueFile = function(file) {
  1028. if (file.status === Dropzone.ADDED && file.accepted === true) {
  1029. file.status = Dropzone.QUEUED;
  1030. if (this.options.autoProcessQueue) {
  1031. return setTimeout(((function(_this) {
  1032. return function() {
  1033. return _this.processQueue();
  1034. };
  1035. })(this)), 0);
  1036. }
  1037. } else {
  1038. throw new Error("This file can't be queued because it has already been processed or was rejected.");
  1039. }
  1040. };
  1041. Dropzone.prototype._thumbnailQueue = [];
  1042. Dropzone.prototype._processingThumbnail = false;
  1043. Dropzone.prototype._enqueueThumbnail = function(file) {
  1044. if (this.options.createImageThumbnails && file.type.match(/image.*/) && file.size <= this.options.maxThumbnailFilesize * 1024 * 1024) {
  1045. this._thumbnailQueue.push(file);
  1046. return setTimeout(((function(_this) {
  1047. return function() {
  1048. return _this._processThumbnailQueue();
  1049. };
  1050. })(this)), 0);
  1051. }
  1052. };
  1053. Dropzone.prototype._processThumbnailQueue = function() {
  1054. if (this._processingThumbnail || this._thumbnailQueue.length === 0) {
  1055. return;
  1056. }
  1057. this._processingThumbnail = true;
  1058. return this.createThumbnail(this._thumbnailQueue.shift(), (function(_this) {
  1059. return function() {
  1060. _this._processingThumbnail = false;
  1061. return _this._processThumbnailQueue();
  1062. };
  1063. })(this));
  1064. };
  1065. Dropzone.prototype.removeFile = function(file) {
  1066. if (file.status === Dropzone.UPLOADING) {
  1067. this.cancelUpload(file);
  1068. }
  1069. this.files = without(this.files, file);
  1070. this.emit("removedfile", file);
  1071. if (this.files.length === 0) {
  1072. return this.emit("reset");
  1073. }
  1074. };
  1075. Dropzone.prototype.removeAllFiles = function(cancelIfNecessary) {
  1076. var file, _i, _len, _ref;
  1077. if (cancelIfNecessary == null) {
  1078. cancelIfNecessary = false;
  1079. }
  1080. _ref = this.files.slice();
  1081. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  1082. file = _ref[_i];
  1083. if (file.status !== Dropzone.UPLOADING || cancelIfNecessary) {
  1084. this.removeFile(file);
  1085. }
  1086. }
  1087. return null;
  1088. };
  1089. Dropzone.prototype.createThumbnail = function(file, callback) {
  1090. var fileReader;
  1091. fileReader = new FileReader;
  1092. fileReader.onload = (function(_this) {
  1093. return function() {
  1094. var img;
  1095. img = document.createElement("img");
  1096. img.onload = function() {
  1097. var canvas, ctx, resizeInfo, thumbnail, _ref, _ref1, _ref2, _ref3;
  1098. file.width = img.width;
  1099. file.height = img.height;
  1100. resizeInfo = _this.options.resize.call(_this, file);
  1101. if (resizeInfo.trgWidth == null) {
  1102. resizeInfo.trgWidth = _this.options.thumbnailWidth;
  1103. }
  1104. if (resizeInfo.trgHeight == null) {
  1105. resizeInfo.trgHeight = _this.options.thumbnailHeight;
  1106. }
  1107. canvas = document.createElement("canvas");
  1108. ctx = canvas.getContext("2d");
  1109. canvas.width = resizeInfo.trgWidth;
  1110. canvas.height = resizeInfo.trgHeight;
  1111. drawImageIOSFix(ctx, img, (_ref = resizeInfo.srcX) != null ? _ref : 0, (_ref1 = resizeInfo.srcY) != null ? _ref1 : 0, resizeInfo.srcWidth, resizeInfo.srcHeight, (_ref2 = resizeInfo.trgX) != null ? _ref2 : 0, (_ref3 = resizeInfo.trgY) != null ? _ref3 : 0, resizeInfo.trgWidth, resizeInfo.trgHeight);
  1112. thumbnail = canvas.toDataURL("image/png");
  1113. _this.emit("thumbnail", file, thumbnail);
  1114. if (callback != null) {
  1115. return callback();
  1116. }
  1117. };
  1118. return img.src = fileReader.result;
  1119. };
  1120. })(this);
  1121. return fileReader.readAsDataURL(file);
  1122. };
  1123. Dropzone.prototype.processQueue = function() {
  1124. var i, parallelUploads, processingLength, queuedFiles;
  1125. parallelUploads = this.options.parallelUploads;
  1126. processingLength = this.getUploadingFiles().length;
  1127. i = processingLength;
  1128. if (processingLength >= parallelUploads) {
  1129. return;
  1130. }
  1131. queuedFiles = this.getQueuedFiles();
  1132. if (!(queuedFiles.length > 0)) {
  1133. return;
  1134. }
  1135. if (this.options.uploadMultiple) {
  1136. return this.processFiles(queuedFiles.slice(0, parallelUploads - processingLength));
  1137. } else {
  1138. while (i < parallelUploads) {
  1139. if (!queuedFiles.length) {
  1140. return;
  1141. }
  1142. this.processFile(queuedFiles.shift());
  1143. i++;
  1144. }
  1145. }
  1146. };
  1147. Dropzone.prototype.processFile = function(file) {
  1148. return this.processFiles([file]);
  1149. };
  1150. Dropzone.prototype.processFiles = function(files) {
  1151. var file, _i, _len;
  1152. for (_i = 0, _len = files.length; _i < _len; _i++) {
  1153. file = files[_i];
  1154. file.processing = true;
  1155. file.status = Dropzone.UPLOADING;
  1156. this.emit("processing", file);
  1157. }
  1158. if (this.options.uploadMultiple) {
  1159. this.emit("processingmultiple", files);
  1160. }
  1161. return this.uploadFiles(files);
  1162. };
  1163. Dropzone.prototype._getFilesWithXhr = function(xhr) {
  1164. var file, files;
  1165. return files = (function() {
  1166. var _i, _len, _ref, _results;
  1167. _ref = this.files;
  1168. _results = [];
  1169. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  1170. file = _ref[_i];
  1171. if (file.xhr === xhr) {
  1172. _results.push(file);
  1173. }
  1174. }
  1175. return _results;
  1176. }).call(this);
  1177. };
  1178. Dropzone.prototype.cancelUpload = function(file) {
  1179. var groupedFile, groupedFiles, _i, _j, _len, _len1, _ref;
  1180. if (file.status === Dropzone.UPLOADING) {
  1181. groupedFiles = this._getFilesWithXhr(file.xhr);
  1182. for (_i = 0, _len = groupedFiles.length; _i < _len; _i++) {
  1183. groupedFile = groupedFiles[_i];
  1184. groupedFile.status = Dropzone.CANCELED;
  1185. }
  1186. file.xhr.abort();
  1187. for (_j = 0, _len1 = groupedFiles.length; _j < _len1; _j++) {
  1188. groupedFile = groupedFiles[_j];
  1189. this.emit("canceled", groupedFile);
  1190. }
  1191. if (this.options.uploadMultiple) {
  1192. this.emit("canceledmultiple", groupedFiles);
  1193. }
  1194. } else if ((_ref = file.status) === Dropzone.ADDED || _ref === Dropzone.QUEUED) {
  1195. file.status = Dropzone.CANCELED;
  1196. this.emit("canceled", file);
  1197. if (this.options.uploadMultiple) {
  1198. this.emit("canceledmultiple", [file]);
  1199. }
  1200. }
  1201. if (this.options.autoProcessQueue) {
  1202. return this.processQueue();
  1203. }
  1204. };
  1205. Dropzone.prototype.uploadFile = function(file) {
  1206. return this.uploadFiles([file]);
  1207. };
  1208. Dropzone.prototype.uploadFiles = function(files) {
  1209. var file, formData, handleError, headerName, headerValue, headers, input, inputName, inputType, key, option, progressObj, response, updateProgress, value, xhr, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2, _ref3, _ref4;
  1210. xhr = new XMLHttpRequest();
  1211. for (_i = 0, _len = files.length; _i < _len; _i++) {
  1212. file = files[_i];
  1213. file.xhr = xhr;
  1214. }
  1215. xhr.open(this.options.method, this.options.url, true);
  1216. xhr.withCredentials = !!this.options.withCredentials;
  1217. response = null;
  1218. handleError = (function(_this) {
  1219. return function() {
  1220. var _j, _len1, _results;
  1221. _results = [];
  1222. for (_j = 0, _len1 = files.length; _j < _len1; _j++) {
  1223. file = files[_j];
  1224. _results.push(_this._errorProcessing(files, response || _this.options.dictResponseError.replace("{{statusCode}}", xhr.status), xhr));
  1225. }
  1226. return _results;
  1227. };
  1228. })(this);
  1229. updateProgress = (function(_this) {
  1230. return function(e) {
  1231. var allFilesFinished, progress, _j, _k, _l, _len1, _len2, _len3, _results;
  1232. if (e != null) {
  1233. progress = 100 * e.loaded / e.total;
  1234. for (_j = 0, _len1 = files.length; _j < _len1; _j++) {
  1235. file = files[_j];
  1236. file.upload = {
  1237. progress: progress,
  1238. total: e.total,
  1239. bytesSent: e.loaded
  1240. };
  1241. }
  1242. } else {
  1243. allFilesFinished = true;
  1244. progress = 100;
  1245. for (_k = 0, _len2 = files.length; _k < _len2; _k++) {
  1246. file = files[_k];
  1247. if (!(file.upload.progress === 100 && file.upload.bytesSent === file.upload.total)) {
  1248. allFilesFinished = false;
  1249. }
  1250. file.upload.progress = progress;
  1251. file.upload.bytesSent = file.upload.total;
  1252. }
  1253. if (allFilesFinished) {
  1254. return;
  1255. }
  1256. }
  1257. _results = [];
  1258. for (_l = 0, _len3 = files.length; _l < _len3; _l++) {
  1259. file = files[_l];
  1260. _results.push(_this.emit("uploadprogress", file, progress, file.upload.bytesSent));
  1261. }
  1262. return _results;
  1263. };
  1264. })(this);
  1265. xhr.onload = (function(_this) {
  1266. return function(e) {
  1267. var _ref;
  1268. if (files[0].status === Dropzone.CANCELED) {
  1269. return;
  1270. }
  1271. if (xhr.readyState !== 4) {
  1272. return;
  1273. }
  1274. response = xhr.responseText;
  1275. if (xhr.getResponseHeader("content-type") && ~xhr.getResponseHeader("content-type").indexOf("application/json")) {
  1276. try {
  1277. response = JSON.parse(response);
  1278. } catch (_error) {
  1279. e = _error;
  1280. response = "Invalid JSON response from server.";
  1281. }
  1282. }
  1283. updateProgress();
  1284. if (!((200 <= (_ref = xhr.status) && _ref < 300))) {
  1285. return handleError();
  1286. } else {
  1287. return _this._finished(files, response, e);
  1288. }
  1289. };
  1290. })(this);
  1291. xhr.onerror = (function(_this) {
  1292. return function() {
  1293. if (files[0].status === Dropzone.CANCELED) {
  1294. return;
  1295. }
  1296. return handleError();
  1297. };
  1298. })(this);
  1299. progressObj = (_ref = xhr.upload) != null ? _ref : xhr;
  1300. progressObj.onprogress = updateProgress;
  1301. headers = {
  1302. "Accept": "application/json",
  1303. "Cache-Control": "no-cache",
  1304. "X-Requested-With": "XMLHttpRequest"
  1305. };
  1306. if (this.options.headers) {
  1307. extend(headers, this.options.headers);
  1308. }
  1309. for (headerName in headers) {
  1310. headerValue = headers[headerName];
  1311. xhr.setRequestHeader(headerName, headerValue);
  1312. }
  1313. formData = new FormData();
  1314. if (this.options.params) {
  1315. _ref1 = this.options.params;
  1316. for (key in _ref1) {
  1317. value = _ref1[key];
  1318. formData.append(key, value);
  1319. }
  1320. }
  1321. for (_j = 0, _len1 = files.length; _j < _len1; _j++) {
  1322. file = files[_j];
  1323. this.emit("sending", file, xhr, formData);
  1324. }
  1325. if (this.options.uploadMultiple) {
  1326. this.emit("sendingmultiple", files, xhr, formData);
  1327. }
  1328. if (this.element.tagName === "FORM") {
  1329. _ref2 = this.element.querySelectorAll("input, textarea, select, button");
  1330. for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
  1331. input = _ref2[_k];
  1332. inputName = input.getAttribute("name");
  1333. inputType = input.getAttribute("type");
  1334. if (input.tagName === "SELECT" && input.hasAttribute("multiple")) {
  1335. _ref3 = input.options;
  1336. for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
  1337. option = _ref3[_l];
  1338. if (option.selected) {
  1339. formData.append(inputName, option.value);
  1340. }
  1341. }
  1342. } else if (!inputType || ((_ref4 = inputType.toLowerCase()) !== "checkbox" && _ref4 !== "radio") || input.checked) {
  1343. formData.append(inputName, input.value);
  1344. }
  1345. }
  1346. }
  1347. for (_m = 0, _len4 = files.length; _m < _len4; _m++) {
  1348. file = files[_m];
  1349. formData.append("" + this.options.paramName + (this.options.uploadMultiple ? "[]" : ""), file, file.name);
  1350. }
  1351. return xhr.send(formData);
  1352. };
  1353. Dropzone.prototype._finished = function(files, responseText, e) {
  1354. var file, _i, _len;
  1355. for (_i = 0, _len = files.length; _i < _len; _i++) {
  1356. file = files[_i];
  1357. file.status = Dropzone.SUCCESS;
  1358. this.emit("success", file, responseText, e);
  1359. this.emit("complete", file);
  1360. }
  1361. if (this.options.uploadMultiple) {
  1362. this.emit("successmultiple", files, responseText, e);
  1363. this.emit("completemultiple", files);
  1364. }
  1365. if (this.options.autoProcessQueue) {
  1366. return this.processQueue();
  1367. }
  1368. };
  1369. Dropzone.prototype._errorProcessing = function(files, message, xhr) {
  1370. var file, _i, _len;
  1371. for (_i = 0, _len = files.length; _i < _len; _i++) {
  1372. file = files[_i];
  1373. file.status = Dropzone.ERROR;
  1374. this.emit("error", file, message, xhr);
  1375. this.emit("complete", file);
  1376. }
  1377. if (this.options.uploadMultiple) {
  1378. this.emit("errormultiple", files, message, xhr);
  1379. this.emit("completemultiple", files);
  1380. }
  1381. if (this.options.autoProcessQueue) {
  1382. return this.processQueue();
  1383. }
  1384. };
  1385. return Dropzone;
  1386. })(Em);
  1387. Dropzone.version = "3.8.7";
  1388. Dropzone.options = {};
  1389. Dropzone.optionsForElement = function(element) {
  1390. if (element.getAttribute("id")) {
  1391. return Dropzone.options[camelize(element.getAttribute("id"))];
  1392. } else {
  1393. return void 0;
  1394. }
  1395. };
  1396. Dropzone.instances = [];
  1397. Dropzone.forElement = function(element) {
  1398. if (typeof element === "string") {
  1399. element = document.querySelector(element);
  1400. }
  1401. if ((element != null ? element.dropzone : void 0) == null) {
  1402. 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.");
  1403. }
  1404. return element.dropzone;
  1405. };
  1406. Dropzone.autoDiscover = true;
  1407. Dropzone.discover = function() {
  1408. var checkElements, dropzone, dropzones, _i, _len, _results;
  1409. if (document.querySelectorAll) {
  1410. dropzones = document.querySelectorAll(".dropzone");
  1411. } else {
  1412. dropzones = [];
  1413. checkElements = function(elements) {
  1414. var el, _i, _len, _results;
  1415. _results = [];
  1416. for (_i = 0, _len = elements.length; _i < _len; _i++) {
  1417. el = elements[_i];
  1418. if (/(^| )dropzone($| )/.test(el.className)) {
  1419. _results.push(dropzones.push(el));
  1420. } else {
  1421. _results.push(void 0);
  1422. }
  1423. }
  1424. return _results;
  1425. };
  1426. checkElements(document.getElementsByTagName("div"));
  1427. checkElements(document.getElementsByTagName("form"));
  1428. }
  1429. _results = [];
  1430. for (_i = 0, _len = dropzones.length; _i < _len; _i++) {
  1431. dropzone = dropzones[_i];
  1432. if (Dropzone.optionsForElement(dropzone) !== false) {
  1433. _results.push(new Dropzone(dropzone));
  1434. } else {
  1435. _results.push(void 0);
  1436. }
  1437. }
  1438. return _results;
  1439. };
  1440. Dropzone.blacklistedBrowsers = [/opera.*Macintosh.*version\/12/i];
  1441. Dropzone.isBrowserSupported = function() {
  1442. var capableBrowser, regex, _i, _len, _ref;
  1443. capableBrowser = true;
  1444. if (window.File && window.FileReader && window.FileList && window.Blob && window.FormData && document.querySelector) {
  1445. if (!("classList" in document.createElement("a"))) {
  1446. capableBrowser = false;
  1447. } else {
  1448. _ref = Dropzone.blacklistedBrowsers;
  1449. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  1450. regex = _ref[_i];
  1451. if (regex.test(navigator.userAgent)) {
  1452. capableBrowser = false;
  1453. continue;
  1454. }
  1455. }
  1456. }
  1457. } else {
  1458. capableBrowser = false;
  1459. }
  1460. return capableBrowser;
  1461. };
  1462. without = function(list, rejectedItem) {
  1463. var item, _i, _len, _results;
  1464. _results = [];
  1465. for (_i = 0, _len = list.length; _i < _len; _i++) {
  1466. item = list[_i];
  1467. if (item !== rejectedItem) {
  1468. _results.push(item);
  1469. }
  1470. }
  1471. return _results;
  1472. };
  1473. camelize = function(str) {
  1474. return str.replace(/[\-_](\w)/g, function(match) {
  1475. return match.charAt(1).toUpperCase();
  1476. });
  1477. };
  1478. Dropzone.createElement = function(string) {
  1479. var div;
  1480. div = document.createElement("div");
  1481. div.innerHTML = string;
  1482. return div.childNodes[0];
  1483. };
  1484. Dropzone.elementInside = function(element, container) {
  1485. if (element === container) {
  1486. return true;
  1487. }
  1488. while (element = element.parentNode) {
  1489. if (element === container) {
  1490. return true;
  1491. }
  1492. }
  1493. return false;
  1494. };
  1495. Dropzone.getElement = function(el, name) {
  1496. var element;
  1497. if (typeof el === "string") {
  1498. element = document.querySelector(el);
  1499. } else if (el.nodeType != null) {
  1500. element = el;
  1501. }
  1502. if (element == null) {
  1503. throw new Error("Invalid `" + name + "` option provided. Please provide a CSS selector or a plain HTML element.");
  1504. }
  1505. return element;
  1506. };
  1507. Dropzone.getElements = function(els, name) {
  1508. var e, el, elements, _i, _j, _len, _len1, _ref;
  1509. if (els instanceof Array) {
  1510. elements = [];
  1511. try {
  1512. for (_i = 0, _len = els.length; _i < _len; _i++) {
  1513. el = els[_i];
  1514. elements.push(this.getElement(el, name));
  1515. }
  1516. } catch (_error) {
  1517. e = _error;
  1518. elements = null;
  1519. }
  1520. } else if (typeof els === "string") {
  1521. elements = [];
  1522. _ref = document.querySelectorAll(els);
  1523. for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
  1524. el = _ref[_j];
  1525. elements.push(el);
  1526. }
  1527. } else if (els.nodeType != null) {
  1528. elements = [els];
  1529. }
  1530. if (!((elements != null) && elements.length)) {
  1531. throw new Error("Invalid `" + name + "` option provided. Please provide a CSS selector, a plain HTML element or a list of those.");
  1532. }
  1533. return elements;
  1534. };
  1535. Dropzone.confirm = function(question, accepted, rejected) {
  1536. if (window.confirm(question)) {
  1537. return accepted();
  1538. } else if (rejected != null) {
  1539. return rejected();
  1540. }
  1541. };
  1542. Dropzone.isValidFile = function(file, acceptedFiles) {
  1543. var baseMimeType, mimeType, validType, _i, _len;
  1544. if (!acceptedFiles) {
  1545. return true;
  1546. }
  1547. acceptedFiles = acceptedFiles.split(",");
  1548. mimeType = file.type;
  1549. baseMimeType = mimeType.replace(/\/.*$/, "");
  1550. for (_i = 0, _len = acceptedFiles.length; _i < _len; _i++) {
  1551. validType = acceptedFiles[_i];
  1552. validType = validType.trim();
  1553. if (validType.charAt(0) === ".") {
  1554. if (file.name.toLowerCase().indexOf(validType.toLowerCase(), file.name.length - validType.length) !== -1) {
  1555. return true;
  1556. }
  1557. } else if (/\/\*$/.test(validType)) {
  1558. if (baseMimeType === validType.replace(/\/.*$/, "")) {
  1559. return true;
  1560. }
  1561. } else {
  1562. if (mimeType === validType) {
  1563. return true;
  1564. }
  1565. }
  1566. }
  1567. return false;
  1568. };
  1569. if (typeof jQuery !== "undefined" && jQuery !== null) {
  1570. jQuery.fn.dropzone = function(options) {
  1571. return this.each(function() {
  1572. return new Dropzone(this, options);
  1573. });
  1574. };
  1575. }
  1576. if (typeof module !== "undefined" && module !== null) {
  1577. module.exports = Dropzone;
  1578. } else {
  1579. window.Dropzone = Dropzone;
  1580. }
  1581. Dropzone.ADDED = "added";
  1582. Dropzone.QUEUED = "queued";
  1583. Dropzone.ACCEPTED = Dropzone.QUEUED;
  1584. Dropzone.UPLOADING = "uploading";
  1585. Dropzone.PROCESSING = Dropzone.UPLOADING;
  1586. Dropzone.CANCELED = "canceled";
  1587. Dropzone.ERROR = "error";
  1588. Dropzone.SUCCESS = "success";
  1589. /*
  1590. Bugfix for iOS 6 and 7
  1591. Source: http://stackoverflow.com/questions/11929099/html5-canvas-drawimage-ratio-bug-ios
  1592. based on the work of https://github.com/stomita/ios-imagefile-megapixel
  1593. */
  1594. detectVerticalSquash = function(img) {
  1595. var alpha, canvas, ctx, data, ey, ih, iw, py, ratio, sy;
  1596. iw = img.naturalWidth;
  1597. ih = img.naturalHeight;
  1598. canvas = document.createElement("canvas");
  1599. canvas.width = 1;
  1600. canvas.height = ih;
  1601. ctx = canvas.getContext("2d");
  1602. ctx.drawImage(img, 0, 0);
  1603. data = ctx.getImageData(0, 0, 1, ih).data;
  1604. sy = 0;
  1605. ey = ih;
  1606. py = ih;
  1607. while (py > sy) {
  1608. alpha = data[(py - 1) * 4 + 3];
  1609. if (alpha === 0) {
  1610. ey = py;
  1611. } else {
  1612. sy = py;
  1613. }
  1614. py = (ey + sy) >> 1;
  1615. }
  1616. ratio = py / ih;
  1617. if (ratio === 0) {
  1618. return 1;
  1619. } else {
  1620. return ratio;
  1621. }
  1622. };
  1623. drawImageIOSFix = function(ctx, img, sx, sy, sw, sh, dx, dy, dw, dh) {
  1624. var vertSquashRatio;
  1625. vertSquashRatio = detectVerticalSquash(img);
  1626. return ctx.drawImage(img, sx, sy, sw, sh, dx, dy, dw, dh / vertSquashRatio);
  1627. };
  1628. /*
  1629. * contentloaded.js
  1630. *
  1631. * Author: Diego Perini (diego.perini at gmail.com)
  1632. * Summary: cross-browser wrapper for DOMContentLoaded
  1633. * Updated: 20101020
  1634. * License: MIT
  1635. * Version: 1.2
  1636. *
  1637. * URL:
  1638. * http://javascript.nwbox.com/ContentLoaded/
  1639. * http://javascript.nwbox.com/ContentLoaded/MIT-LICENSE
  1640. */
  1641. contentLoaded = function(win, fn) {
  1642. var add, doc, done, init, poll, pre, rem, root, top;
  1643. done = false;
  1644. top = true;
  1645. doc = win.document;
  1646. root = doc.documentElement;
  1647. add = (doc.addEventListener ? "addEventListener" : "attachEvent");
  1648. rem = (doc.addEventListener ? "removeEventListener" : "detachEvent");
  1649. pre = (doc.addEventListener ? "" : "on");
  1650. init = function(e) {
  1651. if (e.type === "readystatechange" && doc.readyState !== "complete") {
  1652. return;
  1653. }
  1654. (e.type === "load" ? win : doc)[rem](pre + e.type, init, false);
  1655. if (!done && (done = true)) {
  1656. return fn.call(win, e.type || e);
  1657. }
  1658. };
  1659. poll = function() {
  1660. var e;
  1661. try {
  1662. root.doScroll("left");
  1663. } catch (_error) {
  1664. e = _error;
  1665. setTimeout(poll, 50);
  1666. return;
  1667. }
  1668. return init("poll");
  1669. };
  1670. if (doc.readyState !== "complete") {
  1671. if (doc.createEventObject && root.doScroll) {
  1672. try {
  1673. top = !win.frameElement;
  1674. } catch (_error) {}
  1675. if (top) {
  1676. poll();
  1677. }
  1678. }
  1679. doc[add](pre + "DOMContentLoaded", init, false);
  1680. doc[add](pre + "readystatechange", init, false);
  1681. return win[add](pre + "load", init, false);
  1682. }
  1683. };
  1684. Dropzone._autoDiscoverFunction = function() {
  1685. if (Dropzone.autoDiscover) {
  1686. return Dropzone.discover();
  1687. }
  1688. };
  1689. contentLoaded(window, Dropzone._autoDiscoverFunction);
  1690. }).call(this);
  1691. });
  1692. if (typeof exports == "object") {
  1693. module.exports = require("dropzone");
  1694. } else if (typeof define == "function" && define.amd) {
  1695. define([], function(){ return require("dropzone"); });
  1696. } else {
  1697. this["Dropzone"] = require("dropzone");
  1698. }
  1699. })()