|
|
|
@ -24,6 +24,8 @@ var scanBarcode = function (success, error) {
|
|
|
|
|
app.dialog.alert("You can't scan barcodes with this device.", "Sorry!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var scanningBarcode = false;
|
|
|
|
|
|
|
|
|
|
var getLocation = function (success, error) {
|
|
|
|
|
if ("geolocation" in navigator) {
|
|
|
|
|
navigator.geolocation.getCurrentPosition(function (position) {
|
|
|
|
@ -68,6 +70,7 @@ 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();
|
|
|
|
@ -83,6 +86,7 @@ function setupHTML5BarcodeScanner() {
|
|
|
|
|
selectedDeviceId = videoInputDevices[0].deviceId;
|
|
|
|
|
|
|
|
|
|
codeReader.decodeFromInputVideoDeviceContinuously(selectedDeviceId, 'barcode-viewer', (result, err) => {
|
|
|
|
|
scanningBarcode = false;
|
|
|
|
|
if (result) {
|
|
|
|
|
codeReader.reset();
|
|
|
|
|
$("#web-barcode-ui").addClass("hidden");
|
|
|
|
@ -99,10 +103,12 @@ function setupHTML5BarcodeScanner() {
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
scanningBarcode = false;
|
|
|
|
|
console.error(err);
|
|
|
|
|
});
|
|
|
|
|
$("#web-barcode-ui").on("click", function () {
|
|
|
|
|
codeReader.reset();
|
|
|
|
|
scanningBarcode = false;
|
|
|
|
|
$("#web-barcode-ui").addClass("hidden");
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
@ -111,14 +117,7 @@ function setupHTML5BarcodeScanner() {
|
|
|
|
|
function initCordova() {
|
|
|
|
|
platform_type = "cordova";
|
|
|
|
|
// Handle back button to close things
|
|
|
|
|
document.addEventListener("backbutton", function (event) {
|
|
|
|
|
// Close map sheet if it's open
|
|
|
|
|
if ($(".sheet-modal").hasClass("modal-in")) {
|
|
|
|
|
app.sheet.close();
|
|
|
|
|
} else {
|
|
|
|
|
router.back({force: true, ignoreCache: true});
|
|
|
|
|
}
|
|
|
|
|
}, false);
|
|
|
|
|
document.addEventListener("backbutton", handleBackButton, false);
|
|
|
|
|
document.addEventListener("deviceready", function () {
|
|
|
|
|
if (getStorage("wakelock") == "true") {
|
|
|
|
|
window.powerManagement.acquire(function () {
|
|
|
|
@ -144,13 +143,16 @@ function initCordova() {
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|