Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/custom filename #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ document.body.appendChild(pond.element);
The functionality will become active after uploading a file.

## Configuration
To customize the file name (to the right of the download icon) you can add a metadata to the filepond file object. Example:
```js
file.setMetadata('filename', 'test.png')
```


The label of the download icon can be adjusted as follows:
```js
Expand Down
21 changes: 19 additions & 2 deletions dist/filepond-plugin-get-file.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ const registerDownloadComponent = (
allowDownloadByUrl
) => {
const info = el.querySelector('.filepond--file-info-main'),
downloadIcon = getDownloadIcon(labelButtonDownload);
downloadIcon = getDownloadIcon(labelButtonDownload),
filenameElement = getFilenameElement(item);

info.prepend(downloadIcon);
info.replaceChildren(downloadIcon, filenameElement);
downloadIcon.addEventListener('click', () =>
downloadFile(item, allowDownloadByUrl)
);
Expand All @@ -34,6 +35,22 @@ const getDownloadIcon = (labelButtonDownload) => {
return icon;
};

/**
* Generates the filename element
*/

const getFilenameElement = (item) => {
const element = document.createElement('span');
const filename = item.getMetadata('filename')
? item.getMetadata('filename')
: item.filename;
element.className = 'filepond--file-name';

element.title = filename;
element.innerHTML = filename;
return element;
};

/**
* Triggers the actual download of the uploaded file
*/
Expand Down
2 changes: 1 addition & 1 deletion dist/filepond-plugin-get-file.esm.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions dist/filepond-plugin-get-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
allowDownloadByUrl
) => {
const info = el.querySelector('.filepond--file-info-main'),
downloadIcon = getDownloadIcon(labelButtonDownload);
info.prepend(downloadIcon);
downloadIcon = getDownloadIcon(labelButtonDownload),
filenameElement = getFilenameElement(item);
info.replaceChildren(downloadIcon, filenameElement);
downloadIcon.addEventListener('click', () =>
downloadFile(item, allowDownloadByUrl)
);
Expand All @@ -43,6 +44,20 @@
icon.title = labelButtonDownload;
return icon;
};
/**
* Generates the filename element
*/

const getFilenameElement = (item) => {
const element = document.createElement('span');
const filename = item.getMetadata('filename')
? item.getMetadata('filename')
: item.filename;
element.className = 'filepond--file-name';
element.title = filename;
element.innerHTML = filename;
return element;
};
/**
* Triggers the actual download of the uploaded file
*/
Expand Down
2 changes: 1 addition & 1 deletion dist/filepond-plugin-get-file.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions src/js/components/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
*/
export const registerDownloadComponent = (item, el, labelButtonDownload, allowDownloadByUrl) => {
const info = el.querySelector('.filepond--file-info-main'),
downloadIcon = getDownloadIcon(labelButtonDownload);
downloadIcon = getDownloadIcon(labelButtonDownload),
filenameElement = getFilenameElement(item);

info.prepend(downloadIcon);
info.replaceChildren(downloadIcon, filenameElement);
downloadIcon.addEventListener("click", () => downloadFile(item, allowDownloadByUrl));
}

Expand All @@ -19,6 +20,20 @@ export const getDownloadIcon = (labelButtonDownload) => {
return icon;
}

/**
* Generates the filename element
*/

const getFilenameElement = (item) => {
const element = document.createElement('span');
const filename = item.getMetadata('filename') ? item.getMetadata('filename') : item.filename
element.className = 'filepond--file-name';

element.title = filename;
element.innerHTML = filename;
return element;
};

/**
* Triggers the actual download of the uploaded file
*/
Expand Down