-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
75 lines (61 loc) · 2.46 KB
/
main.js
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
65
66
67
68
69
70
71
72
73
74
75
var dropzone = document.getElementById("dropzone")
var fileChooser = document.getElementById("fileinput")
var imgSrc = ""
dropzone.ondrop = function (e) {
e.preventDefault()
this.className = 'dropzone'
if (e.dataTransfer.files.length == 1) {
document.getElementById("upload").innerText = e.dataTransfer.files[0].name
const dT = new DataTransfer()
dT.items.add(e.dataTransfer.files[0])
document.getElementById("fileinput").files = dT.files
const reader = new FileReader()
reader.addEventListener("load", function () {
document.getElementById("dropzone").style.display = "none"
document.getElementById("previewimage").style.display = "block"
document.getElementById("gonext").style.display = "block"
document.getElementById("previewimage").setAttribute( "src", this.result )
imgSrc = this.result
});
reader.readAsDataURL(e.dataTransfer.files[0])
} else {
console.log('You can upload only one image.')
alert('You can upload only one image.')
}
}
dropzone.ondragover = function () {
this.className = 'dropzone dragover'
return false
}
dropzone.ondragleave = function () {
this.className = 'dropzone'
return false
}
dropzone.onclick = function () {
fileChooser.click()
}
fileChooser.onchange = function (e) {
if (this.files.length == 1) {
document.getElementById("upload").innerText = this.files[0].name
const dT = new DataTransfer()
dT.items.add(this.files[0])
const reader = new FileReader()
reader.addEventListener("load", function () {
document.getElementById("dropzone").style.display = "none"
document.getElementById("previewimage").style.display = "block"
document.getElementById("gonext").style.display = "block"
document.getElementById("previewimage").setAttribute( "src", this.result )
imgSrc = this.result
});
reader.readAsDataURL(this.files[0])
} else {
console.log('You can upload only one image.')
alert('You can upload only one image.')
}
}
document.getElementById("drawToCanvas").addEventListener("click", function () {
document.getElementById("uploadSection").style.display = "none"
document.getElementById("canvasSection").style.display = "block"
var canvasArea = document.getElementById('canvasArea')
const cropper = new Cropper(canvasArea, imgSrc)
})