Sha256: 193db01683bd59239cc355e88e2e76e765868e718f748393d7f251a497cbc30d
Contents?: true
Size: 1.29 KB
Versions: 211
Compression:
Stored size: 1.29 KB
Contents
import { DirectUploadController } from "./direct_upload_controller" import { findElements, dispatchEvent, toArray } from "./helpers" const inputSelector = "input[type=file][data-direct-upload-url]:not([disabled])" export class DirectUploadsController { constructor(form) { this.form = form this.inputs = findElements(form, inputSelector).filter(input => input.files.length) } start(callback) { const controllers = this.createDirectUploadControllers() const startNextController = () => { const controller = controllers.shift() if (controller) { controller.start(error => { if (error) { callback(error) this.dispatch("end") } else { startNextController() } }) } else { callback() this.dispatch("end") } } this.dispatch("start") startNextController() } createDirectUploadControllers() { const controllers = [] this.inputs.forEach(input => { toArray(input.files).forEach(file => { const controller = new DirectUploadController(input, file) controllers.push(controller) }) }) return controllers } dispatch(name, detail = {}) { return dispatchEvent(this.form, `direct-uploads:${name}`, { detail }) } }
Version data entries
211 entries across 206 versions & 22 rubygems