MCPcopy
hub / github.com/dropzone/dropzone / constructor

Method constructor

src/dropzone.js:63–177  ·  view source on GitHub ↗
(el, options)

Source from the content-addressed store, hash-verified

61 }
62
63 constructor(el, options) {
64 super();
65 let fallback, left;
66 this.element = el;
67 // For backwards compatibility since the version was in the prototype previously
68 this.version = Dropzone.version;
69
70 this.clickableElements = [];
71 this.listeners = [];
72 this.files = []; // All files
73
74 if (typeof this.element === "string") {
75 this.element = document.querySelector(this.element);
76 }
77
78 // Not checking if instance of HTMLElement or Element since IE9 is extremely weird.
79 if (!this.element || this.element.nodeType == null) {
80 throw new Error("Invalid dropzone element.");
81 }
82
83 if (this.element.dropzone) {
84 throw new Error("Dropzone already attached.");
85 }
86
87 // Now add this dropzone to the instances.
88 Dropzone.instances.push(this);
89
90 // Put the dropzone inside the element itself.
91 this.element.dropzone = this;
92
93 let elementOptions =
94 (left = Dropzone.optionsForElement(this.element)) != null ? left : {};
95
96 this.options = Dropzone.extend(
97 {},
98 defaultOptions,
99 elementOptions,
100 options != null ? options : {}
101 );
102
103 this.options.previewTemplate = this.options.previewTemplate.replace(
104 /\n*/g,
105 ""
106 );
107
108 // If the browser failed, just call the fallback and leave
109 if (this.options.forceFallback || !Dropzone.isBrowserSupported()) {
110 return this.options.fallback.call(this);
111 }
112
113 // @options.url = @element.getAttribute "action" unless @options.url?
114 if (this.options.url == null) {
115 this.options.url = this.element.getAttribute("action");
116 }
117
118 if (!this.options.url) {
119 throw new Error("No URL provided.");
120 }

Callers

nothing calls this directly

Calls 3

getExistingFallbackMethod · 0.95
initMethod · 0.95
extendMethod · 0.80

Tested by

no test coverage detected