Add in-app barcode scanning support (close #7)
This commit is contained in:
parent
bdb87a25bf
commit
c0f97a5707
@ -13,6 +13,14 @@
|
|||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mobile-app-show {
|
||||||
|
visibility: visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile-app-display {
|
||||||
|
display: initial;
|
||||||
|
}
|
||||||
|
|
||||||
@media screen and (max-width: 767px) {
|
@media screen and (max-width: 767px) {
|
||||||
#navbar-collapse {
|
#navbar-collapse {
|
||||||
display: none;
|
display: none;
|
||||||
|
@ -91,8 +91,25 @@ $(document).ready(function () {
|
|||||||
Hammer(document.body).on("swipeleft", function (e) {
|
Hammer(document.body).on("swipeleft", function (e) {
|
||||||
closemenu();
|
closemenu();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
window.addEventListener('message', function (event) {
|
||||||
|
if (event.data.startsWith("coderesult~|~")) {
|
||||||
|
var data = event.data.split("~|~");
|
||||||
|
var ref = data[1];
|
||||||
|
var code = data[2];
|
||||||
|
$(ref).val(code);
|
||||||
|
$(ref).trigger("input");
|
||||||
|
$(ref).trigger("change");
|
||||||
|
console.log("app: received " + event.data);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function quitapp() {
|
function quitapp() {
|
||||||
parent.postMessage('quit','*');
|
parent.postMessage('quit','*');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function scancode(refstring) {
|
||||||
|
console.log("app: sent scancode " + refstring);
|
||||||
|
parent.postMessage('scancode ' + refstring, "*");
|
||||||
|
}
|
@ -57,8 +57,9 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var scanningactive = false;
|
||||||
window.addEventListener('message', function (event) {
|
window.addEventListener('message', function (event) {
|
||||||
console.log(event.data);
|
console.log("app event: " + event.data);
|
||||||
if (event.data == "quit") {
|
if (event.data == "quit") {
|
||||||
openscreen("home");
|
openscreen("home");
|
||||||
} else if (event.data.startsWith("setcolor ")) {
|
} else if (event.data.startsWith("setcolor ")) {
|
||||||
@ -74,6 +75,36 @@
|
|||||||
} else {
|
} else {
|
||||||
StatusBar.backgroundColorByHexString(color);
|
StatusBar.backgroundColorByHexString(color);
|
||||||
}
|
}
|
||||||
|
} else if (event.data.startsWith("scancode ")) {
|
||||||
|
var callbackcode = event.data.split(" ").slice(1).join(" ");
|
||||||
|
console.log("got scancode " + callbackcode);
|
||||||
|
try {
|
||||||
|
if (scanningactive) {
|
||||||
|
console.log("Scanner already active, ignoring request.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
scanningactive = true;
|
||||||
|
cordova.plugins.barcodeScanner.scan(
|
||||||
|
function (result) {
|
||||||
|
scanningactive = false;
|
||||||
|
if (!result.cancelled) {
|
||||||
|
var iframe = document.getElementById("appframe");
|
||||||
|
iframe.contentWindow.postMessage("coderesult~|~" + callbackcode + "~|~" + result.text, "*");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function (error) {
|
||||||
|
scanningactive = false;
|
||||||
|
navigator.notification.alert("Scanning failed: " + error, null, "Error", 'Dismiss');
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"showFlipCameraButton": true,
|
||||||
|
"prompt": "Scan Code"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} catch (ex) {
|
||||||
|
scanningactive = false;
|
||||||
|
navigator.notification.alert(ex.message, null, "Error", 'Dismiss');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user