| 442 | }; |
| 443 | |
| 444 | function Dropzone(element1, options) { |
| 445 | var elementOptions, fallback, ref; |
| 446 | this.element = element1; |
| 447 | this.version = Dropzone.version; |
| 448 | this.defaultOptions.previewTemplate = this.defaultOptions.previewTemplate.replace(/\n*/g, ""); |
| 449 | this.clickableElements = []; |
| 450 | this.listeners = []; |
| 451 | this.files = []; |
| 452 | if (typeof this.element === "string") { |
| 453 | this.element = document.querySelector(this.element); |
| 454 | } |
| 455 | if (!(this.element && (this.element.nodeType != null))) { |
| 456 | throw new Error("Invalid dropzone element."); |
| 457 | } |
| 458 | if (this.element.dropzone) { |
| 459 | throw new Error("Dropzone already attached."); |
| 460 | } |
| 461 | Dropzone.instances.push(this); |
| 462 | this.element.dropzone = this; |
| 463 | elementOptions = (ref = Dropzone.optionsForElement(this.element)) != null ? ref : {}; |
| 464 | this.options = extend({}, this.defaultOptions, elementOptions, options != null ? options : {}); |
| 465 | if (this.options.forceFallback || !Dropzone.isBrowserSupported()) { |
| 466 | return this.options.fallback.call(this); |
| 467 | } |
| 468 | if (this.options.url == null) { |
| 469 | this.options.url = this.element.getAttribute("action"); |
| 470 | } |
| 471 | if (!this.options.url) { |
| 472 | throw new Error("No URL provided."); |
| 473 | } |
| 474 | if (this.options.acceptedFiles && this.options.acceptedMimeTypes) { |
| 475 | throw new Error("You can't provide both 'acceptedFiles' and 'acceptedMimeTypes'. 'acceptedMimeTypes' is deprecated."); |
| 476 | } |
| 477 | if (this.options.acceptedMimeTypes) { |
| 478 | this.options.acceptedFiles = this.options.acceptedMimeTypes; |
| 479 | delete this.options.acceptedMimeTypes; |
| 480 | } |
| 481 | if (this.options.renameFilename != null) { |
| 482 | this.options.renameFile = (function(_this) { |
| 483 | return function(file) { |
| 484 | return _this.options.renameFilename.call(_this, file.name, file); |
| 485 | }; |
| 486 | })(this); |
| 487 | } |
| 488 | this.options.method = this.options.method.toUpperCase(); |
| 489 | if ((fallback = this.getExistingFallback()) && fallback.parentNode) { |
| 490 | fallback.parentNode.removeChild(fallback); |
| 491 | } |
| 492 | if (this.options.previewsContainer !== false) { |
| 493 | if (this.options.previewsContainer) { |
| 494 | this.previewsContainer = Dropzone.getElement(this.options.previewsContainer, "previewsContainer"); |
| 495 | } else { |
| 496 | this.previewsContainer = this.element; |
| 497 | } |
| 498 | } |
| 499 | if (this.options.clickable) { |
| 500 | if (this.options.clickable === true) { |
| 501 | this.clickableElements = [this.element]; |