Add in-app barcode scanning support (close #7)

Framework7
Skylar Ittner 7 years ago
parent bdb87a25bf
commit c0f97a5707

@ -13,6 +13,14 @@
visibility: hidden;
}
.mobile-app-show {
visibility: visible;
}
.mobile-app-display {
display: initial;
}
@media screen and (max-width: 767px) {
#navbar-collapse {
display: none;

@ -91,8 +91,25 @@ $(document).ready(function () {
Hammer(document.body).on("swipeleft", function (e) {
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() {
parent.postMessage('quit','*');
}
function scancode(refstring) {
console.log("app: sent scancode " + refstring);
parent.postMessage('scancode ' + refstring, "*");
}

@ -56,9 +56,10 @@
openscreen("home");
});
}
var scanningactive = false;
window.addEventListener('message', function (event) {
console.log(event.data);
console.log("app event: " + event.data);
if (event.data == "quit") {
openscreen("home");
} else if (event.data.startsWith("setcolor ")) {
@ -74,9 +75,39 @@
} else {
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);
if (userinfo == null) {
getuserinfo();
}

Loading…
Cancel
Save