Adds a toolbar button for inserting file download links. Supports file upload and/or picking from a predefined file list. Tracks added and removed file links when states is enabled.
Select text or place the caret, click File in the toolbar (after Link), and upload a file or pick one from the list.
<script src="/assets/redactor/redactor.js"></script>
<script src="/assets/redactor/plugins/file-link/file-link.js"></script>
The plugin is active only when upload and/or select is set.
const app = Redactor('#entry', {
plugins: ['fileLink'],
fileLink: {
upload: '/upload',
select: '/files/list.json'
}
});
string | false)
falsestring | object | false)
falseboolean)
truetrue, adds the button to the context toolbar as well.boolean)
truetrue, tracks file links via data-file for diff reporting.string | false)
falseboolean)
truestring)
'file'object | false)
falsestring)
Static select list:
Redactor('#entry', {
plugins: ['fileLink'],
fileLink: {
select: {
sample: {
title: 'Sample PDF',
url: '/files/sample.pdf',
name: 'sample.pdf',
size: '120 KB'
}
}
}
});
Example of full JSON:
{
"specs": {
"title": "Product specs",
"name": "product-specs.docx",
"url": "/url-to/sample-specs.docx",
"id": "specs",
"size": "340Kb"
}
}
Each key is an entry id.
title (or name) is shown in the list; url is used for the link href; size is shown as a shortcut label; id is stored in data-file when present.en: {
fileLink: {
file: 'File',
upload: 'Upload',
title: 'Link text',
select: 'Select',
placeholder: 'Drag to upload a file<br>or click to select'
}
}
Eitted after a file link is inserted via upload.
Payload: { item, element, source }
Emitted after a file link is inserted from the select list.
Payload: { item, element, source }
Emitted when an upload fails.
Payload: { response }
app.on('filelink:upload', ({ item, element }) => {
console.log('Uploaded', item.name);
});
app.on('filelink:upload:error', ({ response }) => {
console.error('Upload failed', response);
});
Returns file links removed since tracking started (when states is enabled).
const removed = app.fileLink.getRemovedFiles();
Returns the link diff object from tracked refs (when states is enabled).
const diff = app.fileLink.getDiff();