-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
79 lines (62 loc) · 2.44 KB
/
script.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
76
77
78
79
(function () {
var $background = document.querySelector('main form [name="background"]');
var $backgroundAlpha = document.querySelector('main form [name="backgroundAlpha"]');
var $foreground = document.querySelector('main form [name="foreground"]');
var $foregroundAlpha = document.querySelector('main form [name="foregroundAlpha"]');
var $level = document.querySelector('main form [name="level"]');
var $section = document.querySelector('main section');
var $padding = document.querySelector('main form [name="padding"]');
var $size = document.querySelector('main form [name="size"]');
var $value = document.querySelector('main form [name="value"]');
var $qrcontainer = document.getElementById("qrImgContainer");
var qr = window.qr = new QRious({
element: document.getElementById('qrious'),
size: 250,
value: 'https://asocialfingers.com/'
});
$background.addEventListener('change', function () {
qr.background = $background.value || null;
$qrcontainer.style.background = $background.value || null;
});
$backgroundAlpha.addEventListener('change', function () {
qr.backgroundAlpha = $backgroundAlpha.value || null;
});
$foreground.addEventListener('change', function () {
qr.foreground = $foreground.value || null;
});
$foregroundAlpha.addEventListener('change', function () {
qr.foregroundAlpha = $foregroundAlpha.value || null;
});
$level.addEventListener('change', function () {
qr.level = $level.value;
});
$padding.addEventListener('change', function () {
if ($padding.validity.valid) {
qr.padding = $padding.value !== '' ? $padding.value : null;
}
});
$size.addEventListener('change', function () {
if (!$size.validity.valid) {
return;
}
qr.size = $size.value || null;
$section.style.minWidth = qr.size + 'px';
});
$value.value = '';
$value.addEventListener('input', function () {
qr.value = $value.value;
});
})();
document.getElementById("download").addEventListener("click", function() {
var element = document.getElementById("qrImgContainer");
html2canvas(element, {
onrendered: function(canvas) {
var imageData = canvas.toDataURL("image/png");
var downloadLink = document.createElement("a");
downloadLink.href = imageData;
var datetime = new Date().toISOString().replace(/[-:.]/g, "");
downloadLink.download = "qr-code-generator-aSocial_Fingers-" + datetime + ".png";
downloadLink.click();
}
});
});