mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-24 18:58:57 +00:00
http://stackoverflow.com/questions/25140723/constructor-name-is-undefine d-in-internet-explorer
73 lines
1.8 KiB
JavaScript
73 lines
1.8 KiB
JavaScript
import yo from 'yo-yo'
|
||
import Utils from '../core/Utils'
|
||
|
||
/**
|
||
* Boilerplate that all Plugins share - and should not be used
|
||
* directly. It also shows which methods final plugins should implement/override,
|
||
* this deciding on structure.
|
||
*
|
||
* @param {object} main Uppy core object
|
||
* @param {object} object with plugin options
|
||
* @return {array | string} files or success/fail message
|
||
*/
|
||
export default class Plugin {
|
||
|
||
constructor (core, opts) {
|
||
this.core = core
|
||
this.opts = opts
|
||
this.type = 'none'
|
||
// this.name = this.constructor.name
|
||
}
|
||
|
||
update () {
|
||
if (typeof this.el === 'undefined') {
|
||
return
|
||
}
|
||
|
||
const newEl = this.render(this.core.state)
|
||
yo.update(this.el, newEl)
|
||
}
|
||
|
||
/**
|
||
* Check if supplied `target` is a `string` or an `object`.
|
||
* If it’s an object — target is a plugin, and we search `plugins`
|
||
* for a plugin with same name and return its target.
|
||
*
|
||
* @param {String|Object} target
|
||
*
|
||
*/
|
||
getTarget (target, caller, el, render) {
|
||
const callerPluginName = Utils.getFnName(caller.constructor)
|
||
|
||
if (typeof target === 'string') {
|
||
this.core.log(`Installing ${callerPluginName} to ${target}`)
|
||
|
||
// clear everything inside the target selector
|
||
// if (replaceTargetContent) {
|
||
// document.querySelector(target).innerHTML = ''
|
||
// }
|
||
document.querySelector(target).appendChild(el)
|
||
|
||
return target
|
||
} else {
|
||
const targetPluginName = Utils.getFnName(target)
|
||
this.core.log(`Installing ${callerPluginName} to ${targetPluginName}`)
|
||
let targetPlugin = this.core.getPlugin(targetPluginName)
|
||
let selectorTarget = targetPlugin.addTarget(caller, render)
|
||
|
||
return selectorTarget
|
||
}
|
||
}
|
||
|
||
focus () {
|
||
return
|
||
}
|
||
|
||
install () {
|
||
return
|
||
}
|
||
|
||
run () {
|
||
return
|
||
}
|
||
}
|