-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.html
More file actions
64 lines (57 loc) · 1.61 KB
/
file.html
File metadata and controls
64 lines (57 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<style>
.form__file input {
display: none;
}
.form__file {
border: 1px dotted #000;
background: white;
color: red;
height: 42px;
padding: 0 16px;
display: flex;
align-items: center;
}
.form__files {
border: 1px dotted rgba(0, 0, 0, 0.274);
padding: 32px;
font-size: 10px;
color: rgba(0, 0, 0, 0.274);
display: none;
}
.form__files:not(:empty) {
display: block;
}
.form__file--drag {
border-color: green;
}
</style>
<script>
function handleFiles(files) {
var arr = Array.from(files);
document.querySelector('.form__files').innerHTML = arr.map(e=> e.name).join(', ');
}
function onDrop(event) {
event.preventDefault();
this.classList.addClass('.form__file--drag');
}
document.addEventListener("drop", function( event ) {
// prevent default action (open as link for some elements)
event.preventDefault();
// move dragged elem to the selected drop target
if ( event.target.className == "dropzone" ) {
// event.target.style.background = "";
// dragged.parentNode.removeChild( dragged );
// event.target.appendChild( dragged );
}
}, false);
</script>
<div class="form__control">
<label class="form__label label">
<span class="label__text">File picker</span>
<div tabindex="0" class="form__file" ondrop="onDrop(event); return false;">
<input type="file" id="avatar" multiple webkitdirectory name="avatar" accept="image/png,image/jpeg" onchange="handleFiles(this.files)" />
<span>File</span>
</div>
<div class="form__files"></div>
</label>
</div>