mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-05-10 04:37:29 +08:00
Fix paste upload handler
This commit is contained in:
@@ -162,27 +162,32 @@ export function createVditor(editorId, options = {}) {
|
|||||||
input,
|
input,
|
||||||
after
|
after
|
||||||
})
|
})
|
||||||
const container = document.getElementById(editorId)
|
const pasteHandler = async (e) => {
|
||||||
if (container) {
|
const items = e.clipboardData && e.clipboardData.items
|
||||||
container.addEventListener('paste', async (e) => {
|
if (!items) return
|
||||||
const items = e.clipboardData && e.clipboardData.items
|
const files = []
|
||||||
if (!items) return
|
for (let i = 0; i < items.length; i++) {
|
||||||
const files = []
|
const item = items[i]
|
||||||
for (let i = 0; i < items.length; i++) {
|
if (item.kind === 'file') {
|
||||||
const item = items[i]
|
const file = item.getAsFile()
|
||||||
if (item.kind === 'file') {
|
if (file) files.push(file)
|
||||||
const file = item.getAsFile()
|
|
||||||
if (file) files.push(file)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (files.length > 0) {
|
}
|
||||||
e.preventDefault()
|
if (files.length > 0) {
|
||||||
const err = await vditor.options.upload.handler(files)
|
e.preventDefault()
|
||||||
if (typeof err === 'string') {
|
const err = await vditor.options.upload.handler(files)
|
||||||
vditor.tip(err)
|
if (typeof err === 'string') {
|
||||||
}
|
vditor.tip(err)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const elements = []
|
||||||
|
if (vditor.wysiwyg) elements.push(vditor.wysiwyg.element)
|
||||||
|
if (vditor.ir) elements.push(vditor.ir.element)
|
||||||
|
if (vditor.sv) elements.push(vditor.sv.element)
|
||||||
|
elements.forEach(el => {
|
||||||
|
el.addEventListener('paste', pasteHandler)
|
||||||
|
})
|
||||||
return vditor
|
return vditor
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user