Skip to content

Instantly share code, notes, and snippets.

// Go to a folder where you want to create your project
// Then enter the following command:
monaca create projectname
// Choose JavaScript from the list and press Enter
// After that, choose the Framework7 Core Tab View from the list and press Enter again
// If the installation process is finished, your project is ready to go
#panel-header {
text-align: left !important;
width: 100%;
}
.card-bg {
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
}
let db = null;
let useDatabaseApi = false;
// Firebase configuration and initialization
const initFirebase = () => {
// You can copy-paste the whole firebase Config function from the
// Firebase Project Preview Settings, after you set up the project
const firebaseConfig = {
apiKey: "PUT_YOUR_KEY_HERE",
authDomain: "YOUR_AUTH_DOMAIN",
// Add new items to the Shop List
function addNewShopToFirebase(jsonObject) {
db.collection('shops').add({
'name': jsonObject.name,
'telephone': jsonObject.telephone,
'address': jsonObject.address,
'location': jsonObject.location
});
}
// Gives back the current location & adds a marker to the map
// onSuccess callback accepts a Position object, which contains the current coordinates
// onError callback receives a PositionError object
function currentLocation(map) {
navigator.geolocation.getCurrentPosition(function (position) {
onSuccess(map, position);
document.getElementById("shop-location").value = position.coords.latitude + " " + position.coords.longitude;
}, onError);
}
// Set options for camera
function setOptions(srcType) {
const options = {
quality: 50,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: srcType,
encodingType: Camera.EncodingType.JPEG,
mediaType: Camera.MediaType.PICTURE,
allowEdit: false,
correctOrientation: true,
function scanBarcode() {
cordova.plugins.barcodeScanner.scan(
function (result) {
document.getElementById("product-code").value = result.text;
getProductInfoWithYahoo(result.text);
},
function (error) {
alert("Scanning failed: " + error);
},
{
const getProductInfoWithYahoo = (barcode) => {
try {
cordova.plugin.http.get('https://shopping.yahooapis.jp/ShoppingWebService/V3/itemSearch', {
appid: yahooApiKey,
jan_code: barcode
}, {}, function (response) {
const data = JSON.parse(response.data);
if (data && data.hits && data.hits.length) {
document.getElementById("product-name").value = data.hits[0].name;
document.getElementById("product-price").value = "¥" + data.hits[0].price;
let map = null;
//For the edit-shop page, the map needs a different name
if (!map) map = L.map('newShopMap', {doubleClickZoom: false}).locate({setView: true, maxZoom: 12});
map.setView([35.40, 139.50], 12);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
let onSuccess = function (map, p) {
L.marker([p.coords.latitude, p.coords.longitude])
.addTo(map)
.bindPopup("Your current location.")
.openPopup();
map.setView([p.coords.latitude, p.coords.longitude], 14);
};