show cool animation on button file select
This commit is contained in:
parent
25948b007a
commit
107627f357
|
@ -13,6 +13,24 @@
|
||||||
/** @type {HTMLInputElement} */
|
/** @type {HTMLInputElement} */
|
||||||
const input_el = document.getElementById('bfile-formupload-file');
|
const input_el = document.getElementById('bfile-formupload-file');
|
||||||
|
|
||||||
|
/** @param {File} file */
|
||||||
|
async function selectFile(file) {
|
||||||
|
text.innerText = 'Processing...';
|
||||||
|
drdrop_enabled = false;
|
||||||
|
await fill_bg();
|
||||||
|
drdrop_enabled = true;
|
||||||
|
text.innerText = `Selected file: ${file.name.substring(0,16)}${file.name.length > 16 ? '...' : ''}\nYou can drop another file to replace this one`;
|
||||||
|
|
||||||
|
const transfer = new DataTransfer();
|
||||||
|
transfer.items.add(file);
|
||||||
|
input_el.files = transfer.files;
|
||||||
|
}
|
||||||
|
|
||||||
|
input_el.onchange = e => {
|
||||||
|
const file = input_el.files[0]
|
||||||
|
selectFile(file);
|
||||||
|
}
|
||||||
|
|
||||||
function drag_end() {
|
function drag_end() {
|
||||||
root_drag_rop.style.background = 'var(--header-sec-color)'
|
root_drag_rop.style.background = 'var(--header-sec-color)'
|
||||||
drag_rop.style.borderColor = '#656565';
|
drag_rop.style.borderColor = '#656565';
|
||||||
|
@ -33,17 +51,9 @@
|
||||||
|
|
||||||
if (!drdrop_enabled) return;
|
if (!drdrop_enabled) return;
|
||||||
|
|
||||||
if (e.dataTransfer.items) {
|
if (e.dataTransfer.items.length != 0) {
|
||||||
let file = e.dataTransfer.items[0].getAsFile();
|
let file = e.dataTransfer.items[0].getAsFile();
|
||||||
text.innerText = 'Processing...';
|
selectFile(file);
|
||||||
drdrop_enabled = false;
|
|
||||||
await fill_bg();
|
|
||||||
drdrop_enabled = true;
|
|
||||||
text.innerText = `Selected file: ${file.name.substring(0,16)}${file.name.length > 16 ? '...' : ''}\nYou can drop another file to replace this one`;
|
|
||||||
|
|
||||||
const transfer = new DataTransfer();
|
|
||||||
transfer.items.add(file);
|
|
||||||
input_el.files = transfer.files;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
drag_rop.addEventListener('dragover', e => {
|
drag_rop.addEventListener('dragover', e => {
|
||||||
|
|
Loading…
Reference in New Issue