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

Framework7
Skylar Ittner 7 years ago
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, "*");
} }

@ -56,9 +56,10 @@
openscreen("home"); openscreen("home");
}); });
} }
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,9 +75,39 @@
} 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);
if (userinfo == null) { if (userinfo == null) {
getuserinfo(); getuserinfo();
} }

Loading…
Cancel
Save