-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.js
40 lines (35 loc) · 861 Bytes
/
code.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
'use strict'
function refreshCodes(element)
{
if (element.target.value === "")
element.target.value = "Hi";
const bcids = [
"qrcode", "code128", "code16k", "code49", "azteccode", "azteccodecompact",
"codeone", "datamatrix", "datamatrixrectangular", "datamatrixrectangularextension", "dotcode"
];
let canvas = document.createElement("canvas");
let options = {
text: element.target.value,
scale: 3.5,
includetext: true,
textalign: "center"
};
for (let i in bcids)
{
options.bcid = bcids[i];
try {
bwipjs.toCanvas(canvas, options);
$(`img-${i}`).src = canvas.toDataURL("image/png");
} catch (e) {
console.error(e);
}
}
}
function codeMain()
{
let textBox = $("code-text-box");
textBox.addEventListener("change", refreshCodes);
textBox.value = "Hello, World!";
refreshCodes({ target: textBox });
}
codeMain();