Subversion Repositories eFlore/Applications.cel

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1244 jpm 1
//+----------------------------------------------------------------------------------------------------------+
2
// Initialisation de Jquery mobile
3
$(document).bind("mobileinit", function(){
4
  $.mobile.defaultPageTransition = "fade";
5
});
6
 
7
//+----------------------------------------------------------------------------------------------------------+
8
// Géolocalisation
9
var gps = navigator.geolocation;
10
 
11
$(document).ready(function() {
12
	$('#geolocaliser').on('click', geolocaliser);
13
});
14
 
15
function geolocaliser(event) {
16
	if (gps) {
17
	    navigator.geolocation.getCurrentPosition(surSuccesGeoloc, surErreurGeoloc);
18
	} else {
19
	    var erreur = {code:'0', message:'Géolocalisation non supportée par le navigateur'};
20
	    surErreurGeoloc(erreur);
21
	}
22
 
23
	event.stopPropagation();
24
	event.preventDefault();
25
}
26
function surSuccesGeoloc(position){
27
	if (position){
28
        var lat = position.coords.latitude;
29
        var lng = position.coords.longitude;
30
        $('#lat').val(lat);
31
        $('#lng').val(lng);
32
    }
33
}
34
function surErreurGeoloc(error){
35
	alert("Echec de la géolocalisation, code: " + error.code + " message: "+ error.message);
36
}
37
//+----------------------------------------------------------------------------------------------------------+
38
// Local Storage
39
var bdd = window.localStorage;
40
bdd.clear();
41
$(document).ready(function() {
42
	$('#sauver-obs').on('click', ajouterObs);
43
	$('body').on('pageshow', '#liste', chargerListeObs);
44
});
45
 
46
function ajouterObs(event) {
47
	var obs = {num:0, date:'', lat:'', lng:'', nom:''};
48
	obs.num = (bdd.length + 1);
49
	obs.date = $('#date').val();
50
	obs.lat = $('#lat').val();
51
	obs.lng = $('#lng').val();
52
	obs.nom = $('#nom').val();
53
 
54
	var cle = 'obs'+obs.num;
55
	var val = JSON.stringify(obs);
56
	bdd.setItem(cle, val);
57
 
58
	alert(bdd.getItem(cle));
59
	event.stopPropagation();
60
	event.preventDefault();
61
}
62
 
63
function chargerListeObs() {
64
	$('#liste-obs').empty();
65
	var nbre = bdd.length;
66
	for (var i = 0; i < nbre; i++) {
67
		var cle = 'obs'+(i+1);
68
		var obs = JSON.parse(bdd.getItem(cle));
69
		$('#liste-obs').append('<li>'+
70
			'<a href="#'+cle+'">'+
71
			'<strong>'+obs.nom+'</strong> observé le '+obs.date+' à lat : '+obs.lat+' lng : '+obs.lng+'</li>'+
72
			'</a>'
73
		);
74
	}
75
	$('#liste-obs').listview('refresh');
76
}
77
 
78
 
79
//+----------------------------------------------------------------------------------------------------------+
80
// Manifest Cache
81
var appCache = window.applicationCache;
82
 
83
$(document).ready(function() {
84
	appCache.addEventListener('updateready', function() {
85
		alert('Mise à jour :'+appCache.status);
86
	});
87
	if (appCache.status === appCache.UPDATEREADY) {
88
		surMiseAJourCache();
89
	}
90
});
91
 
92
function surMiseAJourCache() {
93
	// Browser downloaded a new app cache.
94
    // Swap it in and reload the page to get the new hotness.
95
	appCache.swapCache();
96
    if (confirm('A new version of this site is available. Load it?')) {
97
      window.location.reload();
98
    }
99
}