-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
46 lines (37 loc) · 1.15 KB
/
app.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
const qrText = document.getElementById('qr-text');
const sizes = document.getElementById('sizes');
const generatebtn = document.getElementById('generatebtn');
const downlodebtn = document.getElementById('downlodebtn');
const qrContainer = document.querySelector('.qr-body')
let size = sizes.value;
generatebtn.addEventListener('click',(e)=>{
e.preventDefault();
isEmptyInput();
});
sizes.addEventListener('change',(e)=>{
size = e.target.value;
isEmptyInput();
});
downlodebtn.addEventListener('click', ()=>{
let img = document.querySelector('.qr-body img');
if(img !== null){
let imgAtrr = img.getAttribute('src');
downlodebtn.setAttribute("href", imgAtrr);
}
else{
downlodebtn.setAttribute("href", `${document.querySelector('canvas').toDataURL()}`);
}
});
function isEmptyInput() {
qrText.value.length > 0 ? generateQRCode() : alert("Enter the text or URL to generate your QR code");
}
function generateQRCode(){
qrContainer.innerHTML = "";
new QRCode(qrContainer, {
text:qrText.value,
height:size,
width:size,
colorLight:"#fff",
colorDark:"#000",
});
}