Adds some primitive error handling
parent
9a5d01899b
commit
59a4fda701
|
|
@ -47,7 +47,9 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
<p id="errors" style="color:Tomato;"></p>
|
||||||
<p>Try your QR Code: <div id="qrcode"></div></p>
|
<p>Try your QR Code: <div id="qrcode"></div></p>
|
||||||
|
|
||||||
<p>Click <button id="upload" class="btn btn-primary">Upload</button></p>
|
<p>Click <button id="upload" class="btn btn-primary">Upload</button></p>
|
||||||
|
|
||||||
<script src="../../core/lib/customize.js"></script>
|
<script src="../../core/lib/customize.js"></script>
|
||||||
|
|
@ -95,6 +97,7 @@
|
||||||
return qrstring;
|
return qrstring;
|
||||||
}
|
}
|
||||||
function refreshQRCode(){
|
function refreshQRCode(){
|
||||||
|
document.getElementById("errors").innerText="";
|
||||||
qrcode.clear(); // clear the code.
|
qrcode.clear(); // clear the code.
|
||||||
var qrText = "";
|
var qrText = "";
|
||||||
if(document.getElementById("useWIFI").checked){
|
if(document.getElementById("useWIFI").checked){
|
||||||
|
|
@ -109,10 +112,17 @@
|
||||||
}
|
}
|
||||||
qrcode._htOption.text = qrText;
|
qrcode._htOption.text = qrText;
|
||||||
qrcode._htOption.correctLevel = parseInt(document.getElementById("correction").value);
|
qrcode._htOption.correctLevel = parseInt(document.getElementById("correction").value);
|
||||||
qrcode.makeCode(qrText);
|
try {
|
||||||
|
qrcode.makeCode(qrText);
|
||||||
|
} catch (error) {
|
||||||
|
document.getElementById("errors").innerText="Error: QR could not be created.";
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
|
||||||
var integerScale = Math.max(Math.floor(targetSize / (qrcode._oQRCode.moduleCount + 1)),1);
|
var integerScale = Math.max(Math.floor(targetSize / (qrcode._oQRCode.moduleCount + 1)),1);
|
||||||
|
|
||||||
|
if (integerScale == 1) document.getElementById("errors").innerText = "Warning, QR will probably be too small to properly scan. Try less data or less error correction.";
|
||||||
|
|
||||||
finalSizeQr = integerScale * (qrcode._oQRCode.moduleCount + 1);
|
finalSizeQr = integerScale * (qrcode._oQRCode.moduleCount + 1);
|
||||||
finalSizeCanvas = finalSizeQr - 1;
|
finalSizeCanvas = finalSizeQr - 1;
|
||||||
|
|
||||||
|
|
@ -121,8 +131,12 @@
|
||||||
|
|
||||||
document.getElementsByTagName("canvas")[0].width = finalSizeCanvas;
|
document.getElementsByTagName("canvas")[0].width = finalSizeCanvas;
|
||||||
document.getElementsByTagName("canvas")[0].height = finalSizeCanvas;
|
document.getElementsByTagName("canvas")[0].height = finalSizeCanvas;
|
||||||
|
try {
|
||||||
qrcode.makeCode(qrText);
|
qrcode.makeCode(qrText);
|
||||||
|
} catch (error) {
|
||||||
|
document.getElementById("errors").innerText="Error: QR could not be created.";
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var qrcode;
|
var qrcode;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue