mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-25 03:08:34 +00:00
54 lines
1.3 KiB
JavaScript
54 lines
1.3 KiB
JavaScript
import Plugin from './Plugin'
|
|
|
|
/**
|
|
* Spinner
|
|
*
|
|
*/
|
|
export default class Spinner extends Plugin {
|
|
constructor (core, opts) {
|
|
super(core, opts)
|
|
this.type = 'progressindicator'
|
|
this.id = 'Spinner'
|
|
this.title = 'Spinner'
|
|
|
|
// set default options
|
|
const defaultOptions = {}
|
|
|
|
// merge default options with the ones set by user
|
|
this.opts = Object.assign({}, defaultOptions, opts)
|
|
}
|
|
|
|
setProgress (percentage) {
|
|
if (percentage !== 100) {
|
|
this.spinnerEl.classList.add('is-spinning')
|
|
} else {
|
|
this.spinnerEl.classList.remove('is-spinning')
|
|
}
|
|
}
|
|
|
|
initSpinner () {
|
|
const spinnerContainer = document.querySelector(this.target)
|
|
spinnerContainer.innerHTML = '<div class="UppySpinner"></div>'
|
|
this.spinnerEl = document.querySelector(`${this.target} .UppySpinner`)
|
|
}
|
|
|
|
initEvents () {
|
|
this.core.emitter.on('upload-progress', (data) => {
|
|
const percentage = data.percentage
|
|
const plugin = data.plugin
|
|
this.core.log(
|
|
`progress is: ${percentage}, set by ${plugin.constructor.name}`
|
|
)
|
|
this.setProgress(percentage)
|
|
})
|
|
}
|
|
|
|
install () {
|
|
const caller = this
|
|
this.target = this.getTarget(this.opts.target, caller)
|
|
|
|
this.initSpinner()
|
|
this.initEvents()
|
|
return
|
|
}
|
|
}
|