Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion packages/fluent-editor/src/modules/file/modules/file-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ export class FileModule {

if (fileDom) {
event.preventDefault()
// 在只读模式下不显示 file-bar
// 在只读模式下直接下载文件
if (!this.quill.isEnabled()) {
this.downloadFile(fileDom)
return
}
if (this.fileBar) {
Expand All @@ -37,4 +38,20 @@ export class FileModule {
this.fileBar = null
}
}

downloadFile(fileDom: HTMLElement) {
const fileName = fileDom.dataset.title || ''
const fileDownloadUrl = fileDom.getAttribute('href') || ''
if (fileDownloadUrl) {
const a = document.createElement('a')
a.href = fileDownloadUrl
a.target = '_blank'
a.id = 'exppub'
a.download = fileName
document.body.appendChild(a)
const alink = document.getElementById('exppub')
alink?.click()
alink?.parentNode?.removeChild(a)
}
}
}