()
| 219 | // The function that gets called when Dropzone is initialized. You |
| 220 | // can (and should) setup event listeners inside this function. |
| 221 | init() { |
| 222 | // In case it isn't set already |
| 223 | if (this.element.tagName === "form") { |
| 224 | this.element.setAttribute("enctype", "multipart/form-data"); |
| 225 | } |
| 226 | |
| 227 | if ( |
| 228 | this.element.classList.contains("dropzone") && |
| 229 | !this.element.querySelector(".dz-message") |
| 230 | ) { |
| 231 | this.element.appendChild( |
| 232 | Dropzone.createElement( |
| 233 | `<div class="dz-default dz-message"><button class="dz-button" type="button">${this.options.dictDefaultMessage}</button></div>` |
| 234 | ) |
| 235 | ); |
| 236 | } |
| 237 | |
| 238 | if (this.clickableElements.length) { |
| 239 | let setupHiddenFileInput = () => { |
| 240 | if (this.hiddenFileInput) { |
| 241 | this.hiddenFileInput.parentNode.removeChild(this.hiddenFileInput); |
| 242 | } |
| 243 | this.hiddenFileInput = document.createElement("input"); |
| 244 | this.hiddenFileInput.setAttribute("type", "file"); |
| 245 | if (this.options.maxFiles === null || this.options.maxFiles > 1) { |
| 246 | this.hiddenFileInput.setAttribute("multiple", "multiple"); |
| 247 | } |
| 248 | this.hiddenFileInput.className = "dz-hidden-input"; |
| 249 | |
| 250 | if (this.options.acceptedFiles !== null) { |
| 251 | this.hiddenFileInput.setAttribute( |
| 252 | "accept", |
| 253 | this.options.acceptedFiles |
| 254 | ); |
| 255 | } |
| 256 | if (this.options.capture !== null) { |
| 257 | this.hiddenFileInput.setAttribute("capture", this.options.capture); |
| 258 | } |
| 259 | |
| 260 | // Making sure that no one can "tab" into this field. |
| 261 | this.hiddenFileInput.setAttribute("tabindex", "-1"); |
| 262 | |
| 263 | // Not setting `display="none"` because some browsers don't accept clicks |
| 264 | // on elements that aren't displayed. |
| 265 | this.hiddenFileInput.style.visibility = "hidden"; |
| 266 | this.hiddenFileInput.style.position = "absolute"; |
| 267 | this.hiddenFileInput.style.top = "0"; |
| 268 | this.hiddenFileInput.style.left = "0"; |
| 269 | this.hiddenFileInput.style.height = "0"; |
| 270 | this.hiddenFileInput.style.width = "0"; |
| 271 | Dropzone.getElement( |
| 272 | this.options.hiddenInputContainer, |
| 273 | "hiddenInputContainer" |
| 274 | ).appendChild(this.hiddenFileInput); |
| 275 | this.hiddenFileInput.addEventListener("change", () => { |
| 276 | let { files } = this.hiddenFileInput; |
| 277 | if (files.length) { |
| 278 | for (let file of files) { |
no test coverage detected