1
0
mirror of http://git.whoc.org.uk/git/password-manager.git synced 2025-01-10 23:10:04 +01:00
password-manager-mirror/frontend/gamma/js/JQTouch/extensions/jqt.location.js
Clipperz 644891059e Added JQTouch and Zepto libraries
JQTouch and Zepto are tentatively used for the mobile version of Clipperz.
No final commitment has been made, though.
2013-01-09 10:03:53 +01:00

51 lines
1.6 KiB
JavaScript

(function($) {
if ($.jQTouch)
{
$.jQTouch.addExtension(function Location(){
var latitude, longitude, callback, callback2;
function updateLocation(fn, fn2) {
if (navigator.geolocation)
{
callback = fn;
callback2 = fn2;
navigator.geolocation.getCurrentPosition(savePosition, failResponse);
return true;
} else {
console.log('Device not capable of geo-location.');
fn(false);
return false;
}
}
function failResponse(error){
if (callback2) {
callback2(error);
}
}
function savePosition(position) {
latitude = position.coords.latitude;
longitude = position.coords.longitude;
if (callback) {
callback(getLocation());
}
}
function getLocation() {
if (latitude && longitude) {
return {
latitude: latitude,
longitude: longitude
};
} else {
console.log('No location available. Try calling updateLocation() first.');
return false;
}
}
return {
updateLocation: updateLocation,
getLocation: getLocation
};
});
}
})($);