Skip to content
Snippets Groups Projects
dropzone.js 92.3 KiB
Newer Older
  • Learn to ignore specific revisions
  • 42loop's avatar
    42loop committed
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
    /*
     *
     * More info at [www.dropzonejs.com](http://www.dropzonejs.com)
     *
     * Copyright (c) 2012, Matias Meno
     *
     * Permission is hereby granted, free of charge, to any person obtaining a copy
     * of this software and associated documentation files (the "Software"), to deal
     * in the Software without restriction, including without limitation the rights
     * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     * copies of the Software, and to permit persons to whom the Software is
     * furnished to do so, subject to the following conditions:
     *
     * The above copyright notice and this permission notice shall be included in
     * all copies or substantial portions of the Software.
     *
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     * THE SOFTWARE.
     *
     */
    
    
    // The Emitter class provides the ability to call `.on()` on Dropzone to listen
    // to events.
    // It is strongly based on component's emitter class, and I removed the
    // functionality because of the dependency hell with different frameworks.
    class Emitter {
      // Add an event listener for given event
      on(event, fn) {
        this._callbacks = this._callbacks || {};
        // Create namespace for this event
        if (!this._callbacks[event]) {
          this._callbacks[event] = [];
        }
        this._callbacks[event].push(fn);
        return this;
      }
    
    
      emit(event, ...args) {
        this._callbacks = this._callbacks || {};
        let callbacks = this._callbacks[event];
    
        if (callbacks) {
          for (let callback of callbacks) {
            callback.apply(this, args);
          }
        }
    
        return this;
      }
    
      // Remove event listener for given event. If fn is not provided, all event
      // listeners for that event will be removed. If neither is provided, all
      // event listeners will be removed.
      off(event, fn) {
        if (!this._callbacks || (arguments.length === 0)) {
          this._callbacks = {};
          return this;
        }
    
        // specific event
        let callbacks = this._callbacks[event];
        if (!callbacks) {
          return this;
        }
    
        // remove all handlers
        if (arguments.length === 1) {
          delete this._callbacks[event];
          return this;
        }
    
        // remove specific handler
        for (let i = 0; i < callbacks.length; i++) {
          let callback = callbacks[i];
          if (callback === fn) {
            callbacks.splice(i, 1);
            break;
          }
        }
    
        return this;
      }
    }
    
    class Dropzone extends Emitter {
      static initClass() {
    
        // Exposing the emitter class, mainly for tests
        this.prototype.Emitter = Emitter;
    
        /*
         This is a list of all available events you can register on a dropzone object.
    
         You can register an event handler like this:
    
         dropzone.on("dragEnter", function() { });
    
         */
        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"
        ];
    
    
        this.prototype.defaultOptions = {
          /**
           * Has to be specified on elements other than form (or when the form
           * doesn't have an `action` attribute). You can also
           * provide a function that will be called with `files` and
           * must return the url (since `v3.12.0`)
           */
          url: null,
    
          /**
           * Can be changed to `"put"` if necessary. You can also provide a function
           * that will be called with `files` and must return the method (since `v3.12.0`).
           */
          method: "post",
    
          /**
           * Will be set on the XHRequest.
           */
          withCredentials: false,
    
          /**
           * The timeout for the XHR requests in milliseconds (since `v4.4.0`).
           */
          timeout: 30000,
    
          /**
           * How many file uploads to process in parallel (See the
           * Enqueuing file uploads documentation section for more info)
           */
          parallelUploads: 2,
    
          /**
           * Whether to send multiple files in one request. If
           * this it set to true, then the fallback file input element will
           * have the `multiple` attribute as well. This option will
           * also trigger additional events (like `processingmultiple`). See the events
           * documentation section for more information.
           */
          uploadMultiple: false,
    
          /**
           * Whether you want files to be uploaded in chunks to your server. This can't be
           * used in combination with `uploadMultiple`.
           *
           * See [chunksUploaded](#config-chunksUploaded) for the callback to finalise an upload.
           */
          chunking: false,
    
          /**
           * If `chunking` is enabled, this defines whether **every** file should be chunked,
           * even if the file size is below chunkSize. This means, that the additional chunk
           * form data will be submitted and the `chunksUploaded` callback will be invoked.
           */
          forceChunking: false,
    
          /**
           * If `chunking` is `true`, then this defines the chunk size in bytes.
           */
          chunkSize: 2000000,
    
          /**
           * If `true`, the individual chunks of a file are being uploaded simultaneously.
           */
          parallelChunkUploads: false,
    
          /**
           * Whether a chunk should be retried if it fails.
           */
          retryChunks: false,
    
          /**
           * If `retryChunks` is true, how many times should it be retried.
           */
          retryChunksLimit: 3,
    
          /**
           * If not `null` defines how many files this Dropzone handles. If it exceeds,
           * the event `maxfilesexceeded` will be called. The dropzone element gets the
           * class `dz-max-files-reached` accordingly so you can provide visual feedback.
           */
          maxFilesize: 256,
    
          /**
           * The name of the file param that gets transferred.
           * **NOTE**: If you have the option  `uploadMultiple` set to `true`, then
           * Dropzone will append `[]` to the name.
           */
          paramName: "file",
    
          /**
           * Whether thumbnails for images should be generated
           */
          createImageThumbnails: true,
    
          /**
           * In MB. When the filename exceeds this limit, the thumbnail will not be generated.
           */
          maxThumbnailFilesize: 10,
    
          /**
           * If `null`, the ratio of the image will be used to calculate it.
           */
          thumbnailWidth: 120,
    
          /**
           * The same as `thumbnailWidth`. If both are null, images will not be resized.
           */
          thumbnailHeight: 120,
    
          /**
           * How the images should be scaled down in case both, `thumbnailWidth` and `thumbnailHeight` are provided.
           * Can be either `contain` or `crop`.
           */
          thumbnailMethod: 'crop',
    
          /**
           * If set, images will be resized to these dimensions before being **uploaded**.
           * If only one, `resizeWidth` **or** `resizeHeight` is provided, the original aspect
           * ratio of the file will be preserved.
           *
           * The `options.transformFile` function uses these options, so if the `transformFile` function
           * is overridden, these options don't do anything.
           */
          resizeWidth: null,
    
          /**
           * See `resizeWidth`.
           */
          resizeHeight: null,
    
          /**
           * The mime type of the resized image (before it gets uploaded to the server).
           * If `null` the original mime type will be used. To force jpeg, for example, use `image/jpeg`.
           * See `resizeWidth` for more information.
           */
          resizeMimeType: null,
    
          /**
           * The quality of the resized images. See `resizeWidth`.
           */
          resizeQuality: 0.8,
    
          /**
           * How the images should be scaled down in case both, `resizeWidth` and `resizeHeight` are provided.
           * Can be either `contain` or `crop`.
           */
          resizeMethod: 'contain',
    
          /**
           * The base that is used to calculate the filesize. You can change this to
           * 1024 if you would rather display kibibytes, mebibytes, etc...
           * 1024 is technically incorrect, because `1024 bytes` are `1 kibibyte` not `1 kilobyte`.
           * You can change this to `1024` if you don't care about validity.
           */
          filesizeBase: 1000,
    
          /**
           * Can be used to limit the maximum number of files that will be handled by this Dropzone
           */
          maxFiles: null,
    
          /**
           * An optional object to send additional headers to the server. Eg:
           * `{ "My-Awesome-Header": "header value" }`
           */
          headers: null,
    
          /**
           * If `true`, the dropzone element itself will be clickable, if `false`
           * nothing will be clickable.
           *
           * You can also pass an HTML element, a CSS selector (for multiple elements)
           * or an array of those. In that case, all of those elements will trigger an
           * upload when clicked.
           */
          clickable: true,
    
          /**
           * Whether hidden files in directories should be ignored.
           */
          ignoreHiddenFiles: true,
    
    
          /**
           * The default implementation of `accept` checks the file's mime type or
           * extension against this list. This is a comma separated list of mime
           * types or file extensions.
           *
           * Eg.: `image/*,application/pdf,.psd`
           *
           * If the Dropzone is `clickable` this option will also be used as
           * [`accept`](https://developer.mozilla.org/en-US/docs/HTML/Element/input#attr-accept)
           * parameter on the hidden file input as well.
           */
          acceptedFiles: null,
    
          /**
           * **Deprecated!**
           * Use acceptedFiles instead.
           */
          acceptedMimeTypes: null,
    
          /**
           * If false, files will be added to the queue but the queue will not be
           * processed automatically.
           * This can be useful if you need some additional user input before sending
           * files (or if you want want all files sent at once).
           * If you're ready to send the file simply call `myDropzone.processQueue()`.
           *
           * See the [enqueuing file uploads](#enqueuing-file-uploads) documentation
           * section for more information.
           */
          autoProcessQueue: true,
    
          /**
           * If false, files added to the dropzone will not be queued by default.
           * You'll have to call `enqueueFile(file)` manually.
           */
          autoQueue: true,
    
          /**
           * If `true`, this will add a link to every file preview to remove or cancel (if
           * already uploading) the file. The `dictCancelUpload`, `dictCancelUploadConfirmation`
           * and `dictRemoveFile` options are used for the wording.
           */
          addRemoveLinks: false,
    
          /**
           * Defines where to display the file previews – if `null` the
           * Dropzone element itself is used. Can be a plain `HTMLElement` or a CSS
           * selector. The element should have the `dropzone-previews` class so
           * the previews are displayed properly.
           */
          previewsContainer: null,
    
          /**
           * This is the element the hidden input field (which is used when clicking on the
           * dropzone to trigger file selection) will be appended to. This might
           * be important in case you use frameworks to switch the content of your page.
           *
           * Can be a selector string, or an element directly.
           */
          hiddenInputContainer: "body",
    
          /**
           * If null, no capture type will be specified
           * If camera, mobile devices will skip the file selection and choose camera
           * If microphone, mobile devices will skip the file selection and choose the microphone
           * If camcorder, mobile devices will skip the file selection and choose the camera in video mode
           * On apple devices multiple must be set to false.  AcceptedFiles may need to
           * be set to an appropriate mime type (e.g. "image/*", "audio/*", or "video/*").
           */
          capture: null,
    
          /**
           * **Deprecated**. Use `renameFile` instead.
           */
          renameFilename: null,
    
          /**
           * A function that is invoked before the file is uploaded to the server and renames the file.
           * This function gets the `File` as argument and can use the `file.name`. The actual name of the
           * file that gets used during the upload can be accessed through `file.upload.filename`.
           */
          renameFile: null,
    
          /**
           * If `true` the fallback will be forced. This is very useful to test your server
           * implementations first and make sure that everything works as
           * expected without dropzone if you experience problems, and to test
           * how your fallbacks will look.
           */
          forceFallback: false,
    
          /**
           * The text used before any files are dropped.
           */
          dictDefaultMessage: "Drop files here to upload",
    
          /**
           * The text that replaces the default message text it the browser is not supported.
           */
          dictFallbackMessage: "Your browser does not support drag'n'drop file uploads.",
    
          /**
           * The text that will be added before the fallback form.
           * If you provide a  fallback element yourself, or if this option is `null` this will
           * be ignored.
           */
          dictFallbackText: "Please use the fallback form below to upload your files like in the olden days.",
    
          /**
           * If the filesize is too big.
           * `{{filesize}}` and `{{maxFilesize}}` will be replaced with the respective configuration values.
           */
          dictFileTooBig: "File is too big ({{filesize}}MiB). Max filesize: {{maxFilesize}}MiB.",
    
          /**
           * If the file doesn't match the file type.
           */
          dictInvalidFileType: "You can't upload files of this type.",
    
          /**
           * If the server response was invalid.
           * `{{statusCode}}` will be replaced with the servers status code.
           */
          dictResponseError: "Server responded with {{statusCode}} code.",
    
          /**
           * If `addRemoveLinks` is true, the text to be used for the cancel upload link.
           */
          dictCancelUpload: "Cancel upload",
    
          /**
           * The text that is displayed if an upload was manually canceled
           */
          dictUploadCanceled: "Upload canceled.",
    
          /**
           * If `addRemoveLinks` is true, the text to be used for confirmation when cancelling upload.
           */
          dictCancelUploadConfirmation: "Are you sure you want to cancel this upload?",
    
          /**
           * If `addRemoveLinks` is true, the text to be used to remove a file.
           */
          dictRemoveFile: "Remove file",
    
          /**
           * If this is not null, then the user will be prompted before removing a file.
           */
          dictRemoveFileConfirmation: null,
    
          /**
           * Displayed if `maxFiles` is st and exceeded.
           * The string `{{maxFiles}}` will be replaced by the configuration value.
           */
          dictMaxFilesExceeded: "You can not upload any more files.",
    
          /**
           * Allows you to translate the different units. Starting with `tb` for terabytes and going down to
           * `b` for bytes.
           */
          dictFileSizeUnits: { tb: "TB", gb: "GB", mb: "MB", kb: "KB", b: "b" },
          /**
           * Called when dropzone initialized
           * You can add event listeners here
           */
          init() { },
    
          /**
           * Can be an **object** of additional parameters to transfer to the server, **or** a `Function`
           * that gets invoked with the `files`, `xhr` and, if it's a chunked upload, `chunk` arguments. In case
           * of a function, this needs to return a map.
           *
           * The default implementation does nothing for normal uploads, but adds relevant information for
           * chunked uploads.
           *
           * This is the same as adding hidden input fields in the form element.
           */
          params(files, xhr, chunk) {
            if (chunk) {
              return {
                dzuuid: chunk.file.upload.uuid,
                dzchunkindex: chunk.index,
                dztotalfilesize: chunk.file.size,
                dzchunksize: this.options.chunkSize,
                dztotalchunkcount: chunk.file.upload.totalChunkCount,
                dzchunkbyteoffset: chunk.index * this.options.chunkSize
              };
            }
          },
    
          /**
           * A function that gets a [file](https://developer.mozilla.org/en-US/docs/DOM/File)
           * and a `done` function as parameters.
           *
           * If the done function is invoked without arguments, the file is "accepted" and will
           * be processed. If you pass an error message, the file is rejected, and the error
           * message will be displayed.
           * This function will not be called if the file is too big or doesn't match the mime types.
           */
          accept(file, done) {
            return done();
          },
    
          /**
           * The callback that will be invoked when all chunks have been uploaded for a file.
           * It gets the file for which the chunks have been uploaded as the first parameter,
           * and the `done` function as second. `done()` needs to be invoked when everything
           * needed to finish the upload process is done.
           */
          chunksUploaded: function (file, done) { done(); },
    
          /**
           * Gets called when the browser is not supported.
           * The default implementation shows the fallback input field and adds
           * a text.
           */
          fallback() {
            // This code should pass in IE7... :(
            let messageElement;
            this.element.className = `${this.element.className} dz-browser-not-supported`;
    
            for (let child of this.element.getElementsByTagName("div")) {
              if (/(^| )dz-message($| )/.test(child.className)) {
                messageElement = child;
                child.className = "dz-message"; // Removes the 'dz-default' class
                break;
              }
            }
            if (!messageElement) {
              messageElement = Dropzone.createElement("<div class=\"dz-message\"><span></span></div>");
              this.element.appendChild(messageElement);
            }
    
            let span = messageElement.getElementsByTagName("span")[0];
            if (span) {
              if (span.textContent != null) {
                span.textContent = this.options.dictFallbackMessage;
              } else if (span.innerText != null) {
                span.innerText = this.options.dictFallbackMessage;
              }
            }
    
            return this.element.appendChild(this.getFallbackForm());
          },
    
    
          /**
           * Gets called to calculate the thumbnail dimensions.
           *
           * It gets `file`, `width` and `height` (both may be `null`) as parameters and must return an object containing:
           *
           *  - `srcWidth` & `srcHeight` (required)
           *  - `trgWidth` & `trgHeight` (required)
           *  - `srcX` & `srcY` (optional, default `0`)
           *  - `trgX` & `trgY` (optional, default `0`)
           *
           * Those values are going to be used by `ctx.drawImage()`.
           */
          resize(file, width, height, resizeMethod) {
            let info = {
              srcX: 0,
              srcY: 0,
              srcWidth: file.width,
              srcHeight: file.height
            };
    
            let srcRatio = file.width / file.height;
    
            // Automatically calculate dimensions if not specified
            if ((width == null) && (height == null)) {
              width = info.srcWidth;
              height = info.srcHeight;
            } else if ((width == null)) {
              width = height * srcRatio;
            } else if ((height == null)) {
              height = width / srcRatio;
            }
    
            // Make sure images aren't upscaled
            width = Math.min(width, info.srcWidth);
            height = Math.min(height, info.srcHeight);
    
            let trgRatio = width / height;
    
            if ((info.srcWidth > width) || (info.srcHeight > height)) {
              // Image is bigger and needs rescaling
              if (resizeMethod === 'crop') {
                if (srcRatio > trgRatio) {
                  info.srcHeight = file.height;
                  info.srcWidth = info.srcHeight * trgRatio;
                } else {
                  info.srcWidth = file.width;
                  info.srcHeight = info.srcWidth / trgRatio;
                }
              } else if (resizeMethod === 'contain') {
                // Method 'contain'
                if (srcRatio > trgRatio) {
                  height = width / srcRatio;
                } else {
                  width = height * srcRatio;
                }
              } else {
                throw new Error(`Unknown resizeMethod '${resizeMethod}'`);
              }
            }
    
            info.srcX = (file.width - info.srcWidth) / 2;
            info.srcY = (file.height - info.srcHeight) / 2;
    
            info.trgWidth = width;
            info.trgHeight = height;
    
            return info;
          },
    
          /**
           * Can be used to transform the file (for example, resize an image if necessary).
           *
           * The default implementation uses `resizeWidth` and `resizeHeight` (if provided) and resizes
           * images according to those dimensions.
           *
           * Gets the `file` as the first parameter, and a `done()` function as the second, that needs
           * to be invoked with the file when the transformation is done.
           */
          transformFile(file, done) {
            if ((this.options.resizeWidth || this.options.resizeHeight) && file.type.match(/image.*/)) {
              return this.resizeImage(file, this.options.resizeWidth, this.options.resizeHeight, this.options.resizeMethod, done);
            } else {
              return done(file);
            }
          },
    
    
          /**
           * A string that contains the template used for each dropped
           * file. Change it to fulfill your needs but make sure to properly
           * provide all elements.
           *
           * If you want to use an actual HTML element instead of providing a String
           * as a config option, you could create a div with the id `tpl`,
           * put the template inside it and provide the element like this:
           *
           *     document
           *       .querySelector('#tpl')
           *       .innerHTML
           *
           */
          previewTemplate: `\
    <div class="dz-preview dz-file-preview">
      <div class="dz-image"><img data-dz-thumbnail /></div>
      <div class="dz-details">
        <div class="dz-size"><span data-dz-size></span></div>
        <div class="dz-filename"><span data-dz-name></span></div>
      </div>
      <div class="dz-progress"><span class="dz-upload" data-dz-uploadprogress></span></div>
      <div class="dz-error-message"><span data-dz-errormessage></span></div>
      <div class="dz-success-mark">
        <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">
          <title>Check</title>
          <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
            <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>
          </g>
        </svg>
      </div>
      <div class="dz-error-mark">
        <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">
          <title>Error</title>
          <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
            <g stroke="#747474" stroke-opacity="0.198794158" fill="#FFFFFF" fill-opacity="0.816519475">
              <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>
            </g>
          </g>
        </svg>
      </div>
    </div>\
    `,
    
          // END OPTIONS
          // (Required by the dropzone documentation parser)
    
    
          /*
           Those functions register themselves to the events on init and handle all
           the user interface specific stuff. Overwriting them won't break the upload
           but can break the way it's displayed.
           You can overwrite them if you don't like the default behavior. If you just
           want to add an additional event handler, register it on the dropzone object
           and don't overwrite those options.
           */
    
    
    
    
          // Those are self explanatory and simply concern the DragnDrop.
          drop(e) {
            return this.element.classList.remove("dz-drag-hover");
          },
          dragstart(e) {
          },
          dragend(e) {
            return this.element.classList.remove("dz-drag-hover");
          },
          dragenter(e) {
            return this.element.classList.add("dz-drag-hover");
          },
          dragover(e) {
            return this.element.classList.add("dz-drag-hover");
          },
          dragleave(e) {
            return this.element.classList.remove("dz-drag-hover");
          },
    
          paste(e) {
          },
    
          // Called whenever there are no files left in the dropzone anymore, and the
          // dropzone should be displayed as if in the initial state.
          reset() {
            return this.element.classList.remove("dz-started");
          },
    
          // Called when a file is added to the queue
          // Receives `file`
          addedfile(file) {
            if (this.element === this.previewsContainer) {
              this.element.classList.add("dz-started");
            }
    
            if (this.previewsContainer) {
              file.previewElement = Dropzone.createElement(this.options.previewTemplate.trim());
              file.previewTemplate = file.previewElement; // Backwards compatibility
    
              this.previewsContainer.appendChild(file.previewElement);
              for (var node of file.previewElement.querySelectorAll("[data-dz-name]")) {
                node.textContent = file.name;
              }
              for (node of file.previewElement.querySelectorAll("[data-dz-size]")) {
                node.innerHTML = this.filesize(file.size);
              }
    
              if (this.options.addRemoveLinks) {
                file._removeLink = Dropzone.createElement(`<a class="dz-remove" href="javascript:undefined;" data-dz-remove>${this.options.dictRemoveFile}</a>`);
                file.previewElement.appendChild(file._removeLink);
              }
    
              let removeFileEvent = e => {
                e.preventDefault();
                e.stopPropagation();
                if (file.status === Dropzone.UPLOADING) {
                  return Dropzone.confirm(this.options.dictCancelUploadConfirmation, () => this.removeFile(file));
                } else {
                  if (this.options.dictRemoveFileConfirmation) {
                    return Dropzone.confirm(this.options.dictRemoveFileConfirmation, () => this.removeFile(file));
                  } else {
                    return this.removeFile(file);
                  }
                }
              };
    
              for (let removeLink of file.previewElement.querySelectorAll("[data-dz-remove]")) {
                removeLink.addEventListener("click", removeFileEvent);
              }
            }
          },
    
    
          // Called whenever a file is removed.
          removedfile(file) {
            if (file.previewElement != null && file.previewElement.parentNode != null) {
              file.previewElement.parentNode.removeChild(file.previewElement);
            }
            return this._updateMaxFilesReachedClass();
          },
    
          // Called when a thumbnail has been generated
          // Receives `file` and `dataUrl`
          thumbnail(file, dataUrl) {
            if (file.previewElement) {
              file.previewElement.classList.remove("dz-file-preview");
              for (let thumbnailElement of file.previewElement.querySelectorAll("[data-dz-thumbnail]")) {
                thumbnailElement.alt = file.name;
                thumbnailElement.src = dataUrl;
              }
    
              return setTimeout((() => file.previewElement.classList.add("dz-image-preview")), 1);
            }
          },
    
          // Called whenever an error occurs
          // Receives `file` and `message`
          error(file, message) {
            if (file.previewElement) {
              file.previewElement.classList.add("dz-error");
              if ((typeof message !== "String") && message.error) {
                message = message.error;
              }
              for (let node of file.previewElement.querySelectorAll("[data-dz-errormessage]")) {
                node.textContent = message;
              }
            }
          },
    
          errormultiple() {
          },
    
          // Called when a file gets processed. Since there is a cue, not all added
          // files are processed immediately.
          // Receives `file`
          processing(file) {
            if (file.previewElement) {
              file.previewElement.classList.add("dz-processing");
              if (file._removeLink) {
                return file._removeLink.innerHTML = this.options.dictCancelUpload;
              }
            }
          },
    
          processingmultiple() {
          },
    
          // Called whenever the upload progress gets updated.
          // Receives `file`, `progress` (percentage 0-100) and `bytesSent`.
          // To get the total number of bytes of the file, use `file.size`
          uploadprogress(file, progress, bytesSent) {
            if (file.previewElement) {
              for (let node of file.previewElement.querySelectorAll("[data-dz-uploadprogress]")) {
                node.nodeName === 'PROGRESS' ?
                  (node.value = progress)
                  :
                  (node.style.width = `${progress}%`)
              }
            }
          },
    
          // Called whenever the total upload progress gets updated.
          // Called with totalUploadProgress (0-100), totalBytes and totalBytesSent
          totaluploadprogress() {
          },
    
          // Called just before the file is sent. Gets the `xhr` object as second
          // parameter, so you can modify it (for example to add a CSRF token) and a
          // `formData` object to add additional information.
          sending() {
          },
    
          sendingmultiple() { },
    
          // When the complete upload is finished and successful
          // Receives `file`
          success(file) {
            if (file.previewElement) {
              return file.previewElement.classList.add("dz-success");
            }
          },
    
          successmultiple() { },
    
          // When the upload is canceled.
          canceled(file) {
            return this.emit("error", file, this.options.dictUploadCanceled);
          },
    
          canceledmultiple() { },
    
          // When the upload is finished, either with success or an error.
          // Receives `file`
          complete(file) {
            if (file._removeLink) {
              file._removeLink.innerHTML = this.options.dictRemoveFile;
            }
            if (file.previewElement) {
              return file.previewElement.classList.add("dz-complete");
            }
          },
    
          completemultiple() { },
    
          maxfilesexceeded() { },
    
          maxfilesreached() { },
    
          queuecomplete() { },
    
          addedfiles() { }
        };
    
    
        this.prototype._thumbnailQueue = [];
        this.prototype._processingThumbnail = false;
      }
    
      // global utility
      static extend(target, ...objects) {
        for (let object of objects) {
          for (let key in object) {
            let val = object[key];
            target[key] = val;
          }
        }
        return target;
      }
    
      constructor(el, options) {
        super();
        let fallback, left;
        this.element = el;
        // For backwards compatibility since the version was in the prototype previously
        this.version = Dropzone.version;
    
        this.defaultOptions.previewTemplate = this.defaultOptions.previewTemplate.replace(/\n*/g, "");
    
        this.clickableElements = [];
        this.listeners = [];
        this.files = []; // All files
    
        if (typeof this.element === "string") {
          this.element = document.querySelector(this.element);
        }
    
        // Not checking if instance of HTMLElement or Element since IE9 is extremely weird.
        if (!this.element || (this.element.nodeType == null)) {
          throw new Error("Invalid dropzone element.");
        }
    
        if (this.element.dropzone) {
          throw new Error("Dropzone already attached.");
        }
    
        // Now add this dropzone to the instances.
        Dropzone.instances.push(this);
    
        // Put the dropzone inside the element itself.
        this.element.dropzone = this;
    
        let elementOptions = (left = Dropzone.optionsForElement(this.element)) != null ? left : {};
    
        this.options = Dropzone.extend({}, this.defaultOptions, elementOptions, options != null ? options : {});
    
        // If the browser failed, just call the fallback and leave
        if (this.options.forceFallback || !Dropzone.isBrowserSupported()) {
          return this.options.fallback.call(this);
        }
    
        // @options.url = @element.getAttribute "action" unless @options.url?
        if (this.options.url == null) {
          this.options.url = this.element.getAttribute("action");
        }
    
        if (!this.options.url) {
          throw new Error("No URL provided.");
        }
    
        if (this.options.acceptedFiles && this.options.acceptedMimeTypes) {
          throw new Error("You can't provide both 'acceptedFiles' and 'acceptedMimeTypes'. 'acceptedMimeTypes' is deprecated.");
        }
    
        if (this.options.uploadMultiple && this.options.chunking) {
          throw new Error('You cannot set both: uploadMultiple and chunking.');
        }
    
        // Backwards compatibility
        if (this.options.acceptedMimeTypes) {
          this.options.acceptedFiles = this.options.acceptedMimeTypes;
          delete this.options.acceptedMimeTypes;
        }
    
        // Backwards compatibility
        if (this.options.renameFilename != null) {
          this.options.renameFile = file => this.options.renameFilename.call(this, file.name, file);
        }
    
        this.options.method = this.options.method.toUpperCase();
    
        if ((fallback = this.getExistingFallback()) && fallback.parentNode) {
          // Remove the fallback
          fallback.parentNode.removeChild(fallback);
        }
    
        // Display previews in the previewsContainer element or the Dropzone element unless explicitly set to false
        if (this.options.previewsContainer !== false) {