/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ // Wait for the deviceready event before using any of Cordova's device APIs. // See https://cordova.apache.org/docs/en/latest/cordova/events/events.html#deviceready document.addEventListener('deviceready', onDeviceReady, false); function onDeviceReady() { // Cordova is now initialized. Have fun! console.log('Running cordova-' + cordova.platformId + '@' + cordova.version); document.getElementById("takePicture").addEventListener("click", (e) => { navigator.camera.getPicture(sucessCallbackImage,errorCallbackImage,{ quality: 50, destinationType: Camera.DestinationType.DATA_URL }) }); document.getElementById("getPosition").addEventListener("click", (e) => { navigator.geolocation.watchPosition(sucessCallbackPos,errorCallbackPos,{}) }); var networkState = navigator.connection.type; document.getElementById("getCon").addEventListener("click", (e) => { let con = navigator.connection.type; if(con == "none") { errorCallbackCon(); } else { sucessCallbackCon(); } }); document.addEventListener("offline", decoNet, false); } function sucessCallbackImage(imageData) { //alert("Zipp is best princess !"); var image = document.getElementById('imgToReplace') ; image.src = "data:image/jpeg;base64," + imageData; } function errorCallbackImage() { alert("prout"); } function sucessCallbackPos(position) { alert('Latitude: ' + position.coords.latitude + '\n' + 'Longitude: ' + position.coords.longitude + '\n' + 'Altitude: ' + position.coords.altitude + '\n' + 'Timestamp: ' + new Date(position.timestamp) + '\n'); } function errorCallbackPos() { alert("proutPos"); } function sucessCallbackCon() { alert("Equestria.social reachable !"); let btn = document.getElementById('getCon'); btn.innerHTML = "Equestria.social Online"; btn.classList.remove("btn-info"); btn.classList.add("btn-success"); } function errorCallbackCon() { alert("Equestria.social unreachable !"); let btn = document.getElementById('getCon'); btn.innerHTML = "Equestria.social Offline"; btn.classList.remove("btn-info"); btn.classList.remove("btn-success"); btn.classList.add("btn-danger"); } function decoNet() { alert("Equestria.social : lost connexion"); let btn = document.getElementById('getCon'); btn.innerHTML = "Equestria.social Offline (Lost Connexion)"; btn.classList.remove("btn-info"); btn.classList.remove("btn-success"); btn.classList.add("btn-danger"); }