|
|
|
@ -27,8 +27,61 @@ var openSystemBrowser = function (url) {
|
|
|
|
|
window.open(url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var scanBarcode = function (success, error) {
|
|
|
|
|
app.dialog.alert("You can't scan barcodes with this device.", "Sorry!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var scanningBarcode = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function setupHTML5BarcodeScanner() {
|
|
|
|
|
$("body").append('<script src="node_modules/@zxing/library/umd/index.min.js"></script>');
|
|
|
|
|
|
|
|
|
|
scanBarcode = function (success, error) {
|
|
|
|
|
scanningBarcode = true;
|
|
|
|
|
$("#web-barcode-ui").removeClass("hidden");
|
|
|
|
|
// Stolen from https://zxing-js.github.io/library/examples/multi-camera/
|
|
|
|
|
const codeReader = new ZXing.BrowserMultiFormatReader();
|
|
|
|
|
console.log("Info", 'ZXing code reader initialized');
|
|
|
|
|
codeReader.getVideoInputDevices()
|
|
|
|
|
.then((videoInputDevices) => {
|
|
|
|
|
if (videoInputDevices.length == 0) {
|
|
|
|
|
codeReader.reset();
|
|
|
|
|
$("#web-barcode-ui").addClass("hidden");
|
|
|
|
|
error("A camera is required to scan barcodes.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
selectedDeviceId = videoInputDevices[0].deviceId;
|
|
|
|
|
|
|
|
|
|
codeReader.decodeFromInputVideoDeviceContinuously(selectedDeviceId, 'barcode-viewer', (result, err) => {
|
|
|
|
|
scanningBarcode = false;
|
|
|
|
|
if (result) {
|
|
|
|
|
codeReader.reset();
|
|
|
|
|
$("#web-barcode-ui").addClass("hidden");
|
|
|
|
|
success(result.text);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (err && !(err instanceof ZXing.NotFoundException)) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
codeReader.reset();
|
|
|
|
|
$("#web-barcode-ui").addClass("hidden");
|
|
|
|
|
error(err);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
scanningBarcode = false;
|
|
|
|
|
console.error(err);
|
|
|
|
|
});
|
|
|
|
|
$("#web-barcode-ui").on("click", function () {
|
|
|
|
|
codeReader.reset();
|
|
|
|
|
scanningBarcode = false;
|
|
|
|
|
$("#web-barcode-ui").addClass("hidden");
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var getLocation = function (success, error) {
|
|
|
|
|
if ("geolocation" in navigator) {
|
|
|
|
|
navigator.geolocation.getCurrentPosition(function (position) {
|
|
|
|
@ -103,6 +156,36 @@ function initCordova() {
|
|
|
|
|
window.open(url, '_system', '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof device != "undefined" && device.platform != "browser") {
|
|
|
|
|
scanBarcode = function (success, error) {
|
|
|
|
|
scanningBarcode = true;
|
|
|
|
|
cordova.plugins.barcodeScanner.scan(
|
|
|
|
|
function (result) {
|
|
|
|
|
scanningBarcode = false;
|
|
|
|
|
if (!result.cancelled) {
|
|
|
|
|
success(result.text);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
function (err) {
|
|
|
|
|
scanningBarcode = false;
|
|
|
|
|
if (typeof error == "function") {
|
|
|
|
|
error(err);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
showTorchButton: true,
|
|
|
|
|
showFlipCameraButton: true,
|
|
|
|
|
prompt: "Scan barcode",
|
|
|
|
|
resultDisplayDuration: 0,
|
|
|
|
|
disableSuccessBeep: true,
|
|
|
|
|
formats: "QR_CODE,DATA_MATRIX,CODE_39,CODE_93,CODE_128,CODABAR,PDF_417,AZTEC,MAXICODE"
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
setupHTML5BarcodeScanner();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle geo: urls
|
|
|
|
|
$("#app").on("click", ".geolink", function (evt) {
|
|
|
|
|
window.open($(this).attr("href"), "_system");
|
|
|
|
@ -145,6 +228,8 @@ function initNW() {
|
|
|
|
|
require('nw.gui').Shell.openExternal(url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setupHTML5BarcodeScanner();
|
|
|
|
|
|
|
|
|
|
// Handle geo: urls
|
|
|
|
|
$("#app").on("click", ".geolink", function (evt) {
|
|
|
|
|
require('nw.gui').Shell.openExternal($(this).attr("href"));
|
|
|
|
@ -163,6 +248,8 @@ function initBrowser() {
|
|
|
|
|
window.open(url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setupHTML5BarcodeScanner();
|
|
|
|
|
|
|
|
|
|
$("#app").on("click", ".geolink", function (evt) {
|
|
|
|
|
window.open($(this).attr("href"), "_blank");
|
|
|
|
|
evt.preventDefault();
|
|
|
|
|