Updated JavaScript demo code to show no canvas if QR Code generation failed.
This commit is contained in:
parent
c55751e7bd
commit
1d27211497
|
@ -38,6 +38,11 @@ function redrawQrCode() {
|
||||||
return qrcodegen.QrCode.Ecc.LOW;
|
return qrcodegen.QrCode.Ecc.LOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset canvas in case of early termination
|
||||||
|
var canvas = document.getElementById("qrcode-canvas");
|
||||||
|
canvas.width = 0;
|
||||||
|
canvas.height = 0;
|
||||||
|
|
||||||
// Get form inputs and compute QR Code
|
// Get form inputs and compute QR Code
|
||||||
var ecl = getInputErrorCorrectionLevel();
|
var ecl = getInputErrorCorrectionLevel();
|
||||||
var text = document.getElementById("text-input").value;
|
var text = document.getElementById("text-input").value;
|
||||||
|
@ -55,12 +60,9 @@ function redrawQrCode() {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Draw QR Code onto canvas
|
// Draw QR Code onto canvas
|
||||||
var canvas = document.getElementById("qrcode-canvas");
|
|
||||||
var width = (qr.getSize() + border * 2) * scale;
|
var width = (qr.getSize() + border * 2) * scale;
|
||||||
if (canvas.width != width) {
|
|
||||||
canvas.width = width;
|
canvas.width = width;
|
||||||
canvas.height = width;
|
canvas.height = width;
|
||||||
}
|
|
||||||
var ctx = canvas.getContext("2d");
|
var ctx = canvas.getContext("2d");
|
||||||
for (var y = -border; y < qr.getSize() + border; y++) {
|
for (var y = -border; y < qr.getSize() + border; y++) {
|
||||||
for (var x = -border; x < qr.getSize() + border; x++) {
|
for (var x = -border; x < qr.getSize() + border; x++) {
|
||||||
|
|
Loading…
Reference in New Issue