| 836 |
jpm |
1 |
/*+--------------------------------------------------------------------------------------------------------+*/
|
|
|
2 |
// PARAMÊTRES et CONSTANTES
|
| 941 |
jpm |
3 |
// Mettre à true pour afficher les messages de débogage
|
| 950 |
jpm |
4 |
var DEBUG = false;
|
| 980 |
jpm |
5 |
var communeImageUrl = 'http://www.tela-botanica.org/commun/icones/carto/commune.png';
|
|
|
6 |
var pointImageUrl = 'http://www.tela-botanica.org/commun/icones/carto/point2.png';
|
|
|
7 |
var groupeImageUrlTpl = 'http://localhost/cel-jrest/CelWidgetMap/icone-groupe?type={type}&nbre={nbre}'
|
| 836 |
jpm |
8 |
var pointsOrigine = null;
|
|
|
9 |
var boundsOrigine = null;
|
|
|
10 |
var markerClusterer = null;
|
|
|
11 |
var map = null;
|
|
|
12 |
var infoBulle = new google.maps.InfoWindow();
|
| 980 |
jpm |
13 |
var stations = null;
|
| 836 |
jpm |
14 |
var pointClique = null;
|
| 980 |
jpm |
15 |
var carteCentre = new google.maps.LatLng(25, 10);
|
| 836 |
jpm |
16 |
var carteOptions = {
|
| 980 |
jpm |
17 |
zoom: 3,
|
|
|
18 |
center:carteCentre,
|
| 836 |
jpm |
19 |
mapTypeId: google.maps.MapTypeId.ROADMAP,
|
|
|
20 |
mapTypeControlOptions: {
|
|
|
21 |
mapTypeIds: ['OSM',
|
|
|
22 |
google.maps.MapTypeId.ROADMAP,
|
|
|
23 |
google.maps.MapTypeId.HYBRID,
|
|
|
24 |
google.maps.MapTypeId.SATELLITE,
|
|
|
25 |
google.maps.MapTypeId.TERRAIN]
|
|
|
26 |
}
|
|
|
27 |
};
|
|
|
28 |
var osmMapType = new google.maps.ImageMapType({
|
|
|
29 |
getTileUrl: function(coord, zoom) {
|
|
|
30 |
return "http://tile.openstreetmap.org/" +
|
|
|
31 |
zoom + "/" + coord.x + "/" + coord.y + ".png";
|
|
|
32 |
},
|
|
|
33 |
tileSize: new google.maps.Size(256, 256),
|
|
|
34 |
isPng: true,
|
|
|
35 |
alt: "OpenStreetMap",
|
|
|
36 |
name: "OSM",
|
|
|
37 |
maxZoom: 19
|
|
|
38 |
});
|
| 980 |
jpm |
39 |
var ctaLayer = null;
|
| 915 |
jpm |
40 |
var pagineur = {'limite':50, 'start':0, 'total':0, 'stationId':null, 'format':'tableau'};
|
|
|
41 |
var station = {'commune':'', 'obsNbre':0};
|
|
|
42 |
var obsStation = new Array();
|
|
|
43 |
var obsPage = new Array();
|
| 939 |
jpm |
44 |
var taxonsCarte = new Array();
|
| 980 |
jpm |
45 |
var mgr = null;
|
|
|
46 |
var marqueursCache = new Array();
|
|
|
47 |
var zonesCache = new Array();
|
| 836 |
jpm |
48 |
/*+--------------------------------------------------------------------------------------------------------+*/
|
|
|
49 |
// INITIALISATION DU CODE
|
|
|
50 |
|
|
|
51 |
//Déclenchement d'actions quand JQuery et le document HTML sont OK
|
|
|
52 |
$(document).ready(function() {
|
|
|
53 |
initialiserWidget();
|
|
|
54 |
});
|
|
|
55 |
|
|
|
56 |
function initialiserWidget() {
|
| 980 |
jpm |
57 |
definirTailleTitre();
|
| 836 |
jpm |
58 |
initialiserAffichageCarte();
|
|
|
59 |
initialiserAffichagePanneauLateral();
|
|
|
60 |
initialiserCarte();
|
| 980 |
jpm |
61 |
initialiserGestionnaireMarqueurs()
|
| 836 |
jpm |
62 |
initialiserInfoBulle();
|
| 941 |
jpm |
63 |
initialiserFormulaireContact();
|
| 836 |
jpm |
64 |
chargerLimitesCommunales();
|
|
|
65 |
rafraichirCarte();
|
|
|
66 |
}
|
|
|
67 |
|
| 915 |
jpm |
68 |
/*+--------------------------------------------------------------------------------------------------------+*/
|
|
|
69 |
// AFFICHAGE GÉNÉRAL
|
|
|
70 |
|
| 980 |
jpm |
71 |
function afficherTitreCarte() {
|
|
|
72 |
if (stations != null && taxonsCarte.length > 0) {
|
|
|
73 |
var obsNbre = stations.stats.observations.formaterNombre();
|
|
|
74 |
var plteNbre = taxonsCarte.length.formaterNombre();
|
|
|
75 |
var communeNbre = stations.stats.communes.formaterNombre();
|
|
|
76 |
|
|
|
77 |
var titre = obsNbre+' observation';
|
|
|
78 |
titre += (obsNbre > 1) ? 's' : '' ;
|
|
|
79 |
|
|
|
80 |
if (nt == '*') {
|
|
|
81 |
titre += ' de '+plteNbre+' plante';
|
|
|
82 |
titre += (plteNbre > 1) ? 's' : '' ;
|
|
|
83 |
} else {
|
|
|
84 |
if (taxonsCarte[0]) {
|
|
|
85 |
var taxon = taxonsCarte[0];
|
|
|
86 |
titre += ' pour '+taxon.nom;
|
|
|
87 |
}
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
titre += ' sur '+communeNbre+' commune';
|
|
|
91 |
titre += (communeNbre > 1) ? 's' : '' ;
|
|
|
92 |
|
|
|
93 |
$('#carte-titre-infos').text(titre);
|
|
|
94 |
}
|
| 836 |
jpm |
95 |
}
|
|
|
96 |
|
| 980 |
jpm |
97 |
function definirTailleTitre() {
|
|
|
98 |
var largeurViewPort = $(window).width();
|
|
|
99 |
var taille = null;
|
|
|
100 |
if (largeurViewPort < 400) {
|
|
|
101 |
taille = '0.8';
|
|
|
102 |
} else if (largeurViewPort >= 400 && largeurViewPort < 800) {
|
|
|
103 |
taille = '1.0';
|
|
|
104 |
} else if (largeurViewPort >= 800) {
|
|
|
105 |
taille = '1.6';
|
|
|
106 |
}
|
|
|
107 |
$("#carte-titre").css('font-size', taille+'em');
|
|
|
108 |
}
|
|
|
109 |
|
| 915 |
jpm |
110 |
/*+--------------------------------------------------------------------------------------------------------+*/
|
|
|
111 |
// CARTE
|
|
|
112 |
|
| 836 |
jpm |
113 |
function initialiserAffichageCarte() {
|
|
|
114 |
$('#carte').height($(window).height() - 35);
|
|
|
115 |
$('#carte').width($(window).width() - 24);
|
| 980 |
jpm |
116 |
|
| 836 |
jpm |
117 |
if (nt != '*') {
|
|
|
118 |
$('#carte').css('left', 0);
|
|
|
119 |
}
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
function initialiserCarte() {
|
|
|
123 |
map = new google.maps.Map(document.getElementById('carte'), carteOptions);
|
|
|
124 |
// Ajout de la couche OSM à la carte
|
|
|
125 |
map.mapTypes.set('OSM', osmMapType);
|
|
|
126 |
}
|
|
|
127 |
|
| 980 |
jpm |
128 |
function initialiserGestionnaireMarqueurs() {
|
|
|
129 |
mgr = new MarkerManager(map);
|
|
|
130 |
}
|
| 836 |
jpm |
131 |
|
|
|
132 |
function chargerLimitesCommunales() {
|
|
|
133 |
if (urlsLimitesCommunales != null) {
|
|
|
134 |
for (urlId in urlsLimitesCommunales) {
|
|
|
135 |
var url = urlsLimitesCommunales[urlId];
|
|
|
136 |
ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: true});
|
|
|
137 |
ctaLayer.setMap(map);
|
|
|
138 |
}
|
|
|
139 |
}
|
|
|
140 |
}
|
| 980 |
jpm |
141 |
var listener = null;
|
|
|
142 |
var timer = null;
|
|
|
143 |
function rafraichirCarte() {
|
|
|
144 |
|
|
|
145 |
listener = google.maps.event.addListener(map, 'bounds_changed', function(){
|
|
|
146 |
|
|
|
147 |
if(timer != null) {
|
|
|
148 |
window.clearTimeout(timer);
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
timer = window.setTimeout(function() {
|
|
|
152 |
var zoom = map.getZoom();
|
|
|
153 |
var NELatLng = map.getBounds().getNorthEast().lat()+'|'+map.getBounds().getNorthEast().lng();
|
|
|
154 |
var SWLatLng = map.getBounds().getSouthWest().lat()+'|'+map.getBounds().getSouthWest().lng();
|
|
|
155 |
chargerMarqueurs(zoom, NELatLng, SWLatLng);
|
|
|
156 |
}, 300);
|
|
|
157 |
});
|
|
|
158 |
}
|
| 836 |
jpm |
159 |
|
| 980 |
jpm |
160 |
function collecterBorduresEtChargerMarqueurs() {
|
|
|
161 |
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
var premierChargement = true;
|
|
|
165 |
var marqueurs = new Array();
|
|
|
166 |
function chargerMarqueurs(zoom, NELatLng, SWLatLng) {
|
|
|
167 |
google.maps.event.removeListener(listener);
|
|
|
168 |
var url = stationsUrl+
|
|
|
169 |
'&zoom='+zoom+
|
|
|
170 |
'&ne='+NELatLng+
|
|
|
171 |
'&sw='+SWLatLng;
|
|
|
172 |
|
|
|
173 |
$.getJSON(url, function(data) {
|
|
|
174 |
|
|
|
175 |
$.each(marqueurs, function(index, marqueur) {
|
|
|
176 |
marqueur.setMap(null);
|
|
|
177 |
});
|
|
|
178 |
marqueurs = new Array();
|
|
|
179 |
|
|
|
180 |
stations = data;
|
|
|
181 |
afficherTitreCarte();
|
|
|
182 |
/*if(premierChargement) {
|
|
|
183 |
var bounds = new google.maps.LatLngBounds();
|
|
|
184 |
}*/
|
|
|
185 |
|
|
|
186 |
$.each(stations.points, function (index, station) {
|
|
|
187 |
|
|
|
188 |
/*if(premierChargement) {
|
|
|
189 |
var maLatLng = null;
|
|
|
190 |
maLatLng = new google.maps.LatLng(station['lat'], station['lng']);
|
|
|
191 |
bounds.extend(maLatLng);
|
|
|
192 |
}*/
|
|
|
193 |
|
|
|
194 |
if(station != null) {
|
|
|
195 |
marqueurs.push(creerMarqueur(station));
|
|
|
196 |
}
|
|
|
197 |
});
|
|
|
198 |
|
|
|
199 |
/*if(premierChargement) {
|
|
|
200 |
map.fitBounds(bounds);
|
|
|
201 |
premierChargement = false;
|
|
|
202 |
}*/
|
|
|
203 |
rafraichirCarte();
|
|
|
204 |
});
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
function creerMarqueur(station) {
|
|
|
208 |
var titre = station['nbreMarqueur'];
|
|
|
209 |
var icone = attribuerImageMarqueur(station['id'], station['nbreMarqueur']);
|
|
|
210 |
var latLng = new google.maps.LatLng(station['lat'], station['lng']);
|
|
|
211 |
var marqueur = new google.maps.Marker({
|
|
|
212 |
position: latLng,
|
|
|
213 |
icon: icone,
|
|
|
214 |
title: ''+titre,
|
|
|
215 |
map: map,
|
|
|
216 |
stationInfos: station
|
|
|
217 |
});
|
|
|
218 |
attribuerListenerClick(marqueur, station['id']);
|
|
|
219 |
marqueur.setMap(map);
|
|
|
220 |
return marqueur;
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
function rafraichirCarteSauv() {
|
|
|
224 |
|
| 836 |
jpm |
225 |
var points = [];
|
|
|
226 |
var bounds = new google.maps.LatLngBounds();
|
| 980 |
jpm |
227 |
for (var i = 0; i < stations.points.length; ++i) {
|
|
|
228 |
var point = stations.points[i];
|
|
|
229 |
var maLatLng = new google.maps.LatLng(point.lat, point.lng);
|
|
|
230 |
var stationImage = attribuerImageMarqueur(point.id);
|
| 836 |
jpm |
231 |
var point = new google.maps.Marker({
|
|
|
232 |
position: maLatLng,
|
|
|
233 |
map: map,
|
| 980 |
jpm |
234 |
icon: stationImage,
|
|
|
235 |
stationInfos: point
|
| 836 |
jpm |
236 |
});
|
|
|
237 |
bounds.extend(maLatLng);
|
| 980 |
jpm |
238 |
google.maps.event.addListener(point, 'click', surClickMarqueur);
|
| 836 |
jpm |
239 |
points.push(point);
|
|
|
240 |
}
|
|
|
241 |
|
|
|
242 |
if (pointsOrigine == null && boundsOrigine == null) {
|
|
|
243 |
pointsOrigine = points;
|
|
|
244 |
boundsOrigine = bounds;
|
|
|
245 |
}
|
|
|
246 |
|
|
|
247 |
executerMarkerClusterer(points, bounds);
|
|
|
248 |
}
|
|
|
249 |
|
| 980 |
jpm |
250 |
function attribuerImageMarqueur(id, nbreMarqueur) {
|
|
|
251 |
var marqueurImage = null;
|
|
|
252 |
if (etreMarqueurCommune(id)) {
|
|
|
253 |
marqueurImage = new google.maps.MarkerImage(communeImageUrl, new google.maps.Size(24, 32));
|
|
|
254 |
} else if (etreMarqueurStation(id)) {
|
|
|
255 |
marqueurImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(16, 16));
|
|
|
256 |
} else if (etreMarqueurGroupe(id)) {
|
|
|
257 |
var type = 0;
|
|
|
258 |
var largeur = 0;
|
|
|
259 |
var hauteur = 0;
|
|
|
260 |
if (nbreMarqueur != null) {
|
|
|
261 |
if (nbreMarqueur >= 2 && nbreMarqueur < 100 ) {
|
|
|
262 |
type = '1';
|
|
|
263 |
largeur = 53;
|
|
|
264 |
hauteur = 52;
|
|
|
265 |
} else if (nbreMarqueur >= 100 && nbreMarqueur < 1000 ) {
|
|
|
266 |
type = '2';
|
|
|
267 |
largeur = 56;
|
|
|
268 |
hauteur = 55;
|
|
|
269 |
} else if (nbreMarqueur >= 1000 && nbreMarqueur < 10000 ) {
|
|
|
270 |
type = '3';
|
|
|
271 |
largeur = 66;
|
|
|
272 |
hauteur = 65;
|
|
|
273 |
} else if (nbreMarqueur >= 10000 && nbreMarqueur < 20000 ) {
|
|
|
274 |
type = '4';
|
|
|
275 |
largeur = 78;
|
|
|
276 |
hauteur = 77;
|
|
|
277 |
} else if (nbreMarqueur >= 20000) {
|
|
|
278 |
type = '5';
|
|
|
279 |
largeur = 66;
|
|
|
280 |
hauteur = 65;
|
|
|
281 |
}
|
|
|
282 |
}
|
|
|
283 |
groupeImageUrl = groupeImageUrlTpl.replace(/\{type\}/, type);
|
|
|
284 |
groupeImageUrl = groupeImageUrl.replace(/\{nbre\}/, nbreMarqueur);
|
|
|
285 |
marqueurImage = new google.maps.MarkerImage(groupeImageUrl, new google.maps.Size(largeur, hauteur));
|
|
|
286 |
}
|
|
|
287 |
return marqueurImage
|
|
|
288 |
}
|
|
|
289 |
|
|
|
290 |
function attribuerListenerClick(marqueur, id) {
|
|
|
291 |
if (etreMarqueurCommune(id) || etreMarqueurStation(id)) {
|
|
|
292 |
google.maps.event.addListener(marqueur, 'click', surClickMarqueur);
|
|
|
293 |
} else if (etreMarqueurGroupe(id)) {
|
|
|
294 |
google.maps.event.addListener(marqueur, 'click', surClickGroupe);
|
|
|
295 |
}
|
|
|
296 |
}
|
|
|
297 |
|
|
|
298 |
function surClickMarqueur() {
|
|
|
299 |
pointClique = this;
|
|
|
300 |
infoBulle.open(map, this);
|
|
|
301 |
//centrerInfoBulle();
|
|
|
302 |
actualiserPagineur();
|
|
|
303 |
afficherInfoBulle();
|
|
|
304 |
chargerObs(0, 0);
|
|
|
305 |
}
|
|
|
306 |
|
|
|
307 |
function surClickGroupe() {
|
|
|
308 |
map.setCenter(this.getPosition());
|
|
|
309 |
var nouveauZoom = map.getZoom() + 2;
|
|
|
310 |
map.setZoom(nouveauZoom);
|
|
|
311 |
mgr.clearMarkers();
|
|
|
312 |
}
|
|
|
313 |
|
|
|
314 |
function etreMarqueurGroupe(id) {
|
|
|
315 |
var groupe = false;
|
|
|
316 |
var motif = /^GROUPE/;
|
|
|
317 |
if (motif.test(id)) {
|
|
|
318 |
groupe = true;
|
|
|
319 |
}
|
|
|
320 |
return groupe;
|
|
|
321 |
}
|
|
|
322 |
|
|
|
323 |
function etreMarqueurCommune(id) {
|
|
|
324 |
var commune = false;
|
|
|
325 |
var motif = /^COMMUNE:/;
|
|
|
326 |
if (motif.test(id)) {
|
|
|
327 |
commune = true;
|
|
|
328 |
}
|
|
|
329 |
return commune;
|
|
|
330 |
}
|
|
|
331 |
|
|
|
332 |
function etreMarqueurStation(id) {
|
|
|
333 |
var station = false;
|
|
|
334 |
var motif = /^STATION:/;
|
|
|
335 |
if (motif.test(id)) {
|
|
|
336 |
station = true;
|
|
|
337 |
}
|
|
|
338 |
return station;
|
|
|
339 |
}
|
|
|
340 |
|
|
|
341 |
function deplacerCarteSurPointClique() {
|
| 915 |
jpm |
342 |
map.panTo(pointClique.position);
|
|
|
343 |
}
|
|
|
344 |
|
|
|
345 |
function executerMarkerClusterer(points, bounds) {
|
|
|
346 |
if (markerClusterer) {
|
|
|
347 |
markerClusterer.clearMarkers();
|
| 836 |
jpm |
348 |
}
|
| 980 |
jpm |
349 |
markerClusterer = new MarkerClusterer(map, points, {gridSize: 50, maxZoom: 18});
|
| 915 |
jpm |
350 |
map.fitBounds(bounds);
|
|
|
351 |
}
|
|
|
352 |
|
|
|
353 |
/*+--------------------------------------------------------------------------------------------------------+*/
|
|
|
354 |
// INFO BULLE
|
|
|
355 |
|
|
|
356 |
function initialiserInfoBulle() {
|
|
|
357 |
google.maps.event.addListener(infoBulle, 'domready', initialiserContenuInfoBulle);
|
| 980 |
jpm |
358 |
google.maps.event.addListener(infoBulle, 'closeclick', surFermetureInfoBulle);
|
|
|
359 |
google.maps.event.addListener(infoBulle, 'content_changed', definirLargeurInfoBulle);
|
| 915 |
jpm |
360 |
}
|
|
|
361 |
|
| 980 |
jpm |
362 |
function surFermetureInfoBulle() {
|
|
|
363 |
//deplacerCarteSurPointClique();
|
|
|
364 |
}
|
|
|
365 |
|
|
|
366 |
function centrerInfoBulle() {
|
|
|
367 |
var limites = map.getBounds();
|
|
|
368 |
var centre = limites.getCenter();
|
|
|
369 |
var nordEst = limites.getNorthEast();
|
|
|
370 |
var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
|
|
|
371 |
map.panTo(centreSudLatLng);
|
|
|
372 |
}
|
|
|
373 |
|
| 915 |
jpm |
374 |
function afficherInfoBulle() {
|
|
|
375 |
var obsHtml = $("#tpl-obs").html();
|
| 980 |
jpm |
376 |
var largeur = definirLargeurInfoBulle();
|
|
|
377 |
obsHtml = obsHtml.replace(/\{largeur\}/, largeur);
|
| 915 |
jpm |
378 |
infoBulle.setContent(obsHtml);
|
|
|
379 |
}
|
|
|
380 |
|
| 980 |
jpm |
381 |
function definirLargeurInfoBulle() {
|
|
|
382 |
var largeurViewPort = $(window).width();
|
|
|
383 |
var lageurInfoBulle = null;
|
|
|
384 |
if (largeurViewPort < 800) {
|
|
|
385 |
largeurInfoBulle = 400;
|
|
|
386 |
} else if (largeurViewPort >= 800 && largeurViewPort < 1200) {
|
|
|
387 |
largeurInfoBulle = 500;
|
|
|
388 |
} else if (largeurViewPort >= 1200) {
|
|
|
389 |
largeurInfoBulle = 600;
|
|
|
390 |
}
|
|
|
391 |
return largeurInfoBulle;
|
|
|
392 |
}
|
|
|
393 |
|
| 915 |
jpm |
394 |
function afficherMessageChargement(element) {
|
|
|
395 |
if ($('#chargement').get() == '') {
|
|
|
396 |
$('#tpl-chargement').tmpl().appendTo(element);
|
|
|
397 |
}
|
|
|
398 |
}
|
|
|
399 |
|
|
|
400 |
function supprimerMessageChargement() {
|
|
|
401 |
$('#chargement').remove();
|
|
|
402 |
}
|
|
|
403 |
|
|
|
404 |
function chargerObs(depart, total) {
|
| 939 |
jpm |
405 |
if (depart == 0 || depart < total) {
|
| 915 |
jpm |
406 |
var limite = 300;
|
|
|
407 |
if (depart == 0) {
|
|
|
408 |
obsStation = new Array();
|
|
|
409 |
}
|
| 950 |
jpm |
410 |
//console.log("Chargement de "+depart+" à "+(depart+limite));
|
| 939 |
jpm |
411 |
var urlObs = observationsUrl+'&start={start}&limit='+limite;
|
| 980 |
jpm |
412 |
urlObs = urlObs.replace(/\{stationId\}/g, pointClique.stationInfos.id);
|
| 939 |
jpm |
413 |
urlObs = urlObs.replace(/\{nt\}/g, nt);
|
| 915 |
jpm |
414 |
urlObs = urlObs.replace(/\{start\}/g, depart);
|
|
|
415 |
|
|
|
416 |
$.getJSON(urlObs, function(observations){
|
|
|
417 |
obsStation = obsStation.concat(observations.observations);
|
| 980 |
jpm |
418 |
chargerObs(depart+limite, pointClique.stationInfos.nbre);
|
| 915 |
jpm |
419 |
});
|
|
|
420 |
} else {
|
|
|
421 |
if (pagineur.limite < total) {
|
|
|
422 |
afficherPagination();
|
| 980 |
jpm |
423 |
surClicPagePagination(0, null);
|
| 915 |
jpm |
424 |
} else {
|
|
|
425 |
surClicPagePagination(0, null);
|
| 939 |
jpm |
426 |
selectionnerOnglet("#obs-vue-"+pagineur.format);
|
| 915 |
jpm |
427 |
}
|
|
|
428 |
}
|
|
|
429 |
}
|
|
|
430 |
|
| 939 |
jpm |
431 |
function actualiserPagineur() {
|
| 980 |
jpm |
432 |
pagineur.stationId = pointClique.stationInfos.id;
|
|
|
433 |
pagineur.total = pointClique.stationInfos.nbre;
|
| 939 |
jpm |
434 |
if (pagineur.total > 4) {
|
|
|
435 |
pagineur.format = 'tableau';
|
|
|
436 |
} else {
|
|
|
437 |
pagineur.format = 'liste';
|
|
|
438 |
}
|
|
|
439 |
}
|
|
|
440 |
|
| 915 |
jpm |
441 |
function afficherPagination(observations) {
|
|
|
442 |
$(".navigation").pagination(pagineur.total, {
|
|
|
443 |
items_per_page:pagineur.limite,
|
|
|
444 |
callback:surClicPagePagination,
|
|
|
445 |
next_text:'Suivant',
|
|
|
446 |
prev_text:'Précédent',
|
|
|
447 |
prev_show_always:false,
|
|
|
448 |
num_edge_entries:1,
|
| 953 |
jpm |
449 |
num_display_entries:4,
|
| 915 |
jpm |
450 |
load_first_page:true
|
|
|
451 |
});
|
|
|
452 |
}
|
|
|
453 |
|
|
|
454 |
function surClicPagePagination(pageIndex, paginationConteneur) {
|
|
|
455 |
var index = pageIndex * pagineur.limite;
|
|
|
456 |
var indexMax = index + pagineur.limite;
|
|
|
457 |
pagineur.depart = index;
|
|
|
458 |
obsPage = new Array();
|
|
|
459 |
for(index; index < indexMax; index++) {
|
|
|
460 |
obsPage.push(obsStation[index]);
|
|
|
461 |
}
|
|
|
462 |
|
|
|
463 |
supprimerMessageChargement();
|
|
|
464 |
mettreAJourObservations();
|
|
|
465 |
return false;
|
|
|
466 |
}
|
|
|
467 |
|
|
|
468 |
function mettreAJourObservations() {
|
|
|
469 |
$("#obs-"+pagineur.format+"-lignes").empty();
|
|
|
470 |
$("#obs-vue-"+pagineur.format).css('display', 'block');
|
|
|
471 |
$(".obs-conteneur").css('counter-reset', 'item '+pagineur.depart);
|
|
|
472 |
$("#tpl-obs-"+pagineur.format).tmpl(obsPage).appendTo("#obs-"+pagineur.format+"-lignes");
|
|
|
473 |
|
|
|
474 |
// Actualisation de Fancybox
|
| 941 |
jpm |
475 |
ajouterFomulaireContact("a.contact");
|
| 915 |
jpm |
476 |
if (pagineur.format == 'liste') {
|
| 836 |
jpm |
477 |
ajouterGaleriePhoto("a.cel-img");
|
|
|
478 |
}
|
|
|
479 |
}
|
|
|
480 |
|
| 980 |
jpm |
481 |
function afficherTitreInfoBulle() {
|
|
|
482 |
var titre = '';
|
|
|
483 |
titre += pointClique.stationInfos.nbre+' observation';
|
|
|
484 |
titre += (pointClique.stationInfos.nbre > 1) ? 's': '' ;
|
|
|
485 |
titre += ' pour ';
|
|
|
486 |
if (etreMarqueurCommune(pointClique.stationInfos.id)) {
|
|
|
487 |
nomStation = 'la commune : ';
|
|
|
488 |
} else {
|
|
|
489 |
nomStation = 'la station : ';
|
|
|
490 |
}
|
|
|
491 |
titre += pointClique.stationInfos.nom;
|
|
|
492 |
$("#obs-station-titre").text(titre);
|
| 915 |
jpm |
493 |
}
|
|
|
494 |
|
|
|
495 |
function initialiserContenuInfoBulle() {
|
| 980 |
jpm |
496 |
afficherTitreInfoBulle();
|
|
|
497 |
afficherMessageChargement('#observations');
|
|
|
498 |
cacherContenuOnglets();
|
| 915 |
jpm |
499 |
afficherOnglets();
|
|
|
500 |
ajouterTableauTriable("#obs-tableau");
|
|
|
501 |
afficherTextStationId();
|
|
|
502 |
corrigerLargeurInfoWindow();
|
|
|
503 |
}
|
|
|
504 |
|
| 980 |
jpm |
505 |
function cacherContenuOnglets() {
|
|
|
506 |
$("#obs-vue-tableau").css("display", "none");
|
|
|
507 |
$("#obs-vue-liste").css("display", "none");
|
|
|
508 |
}
|
|
|
509 |
|
| 915 |
jpm |
510 |
function afficherOnglets() {
|
|
|
511 |
var $tabs = $('#obs').tabs();
|
|
|
512 |
$('#obs').bind('tabsselect', function(event, ui) {
|
|
|
513 |
if (ui.panel.id == 'obs-vue-tableau') {
|
|
|
514 |
surClicAffichageTableau();
|
|
|
515 |
} else if (ui.panel.id == 'obs-vue-liste') {
|
|
|
516 |
surClicAffichageListe();
|
|
|
517 |
}
|
|
|
518 |
});
|
| 980 |
jpm |
519 |
if (pointClique.stationInfos.nbre > 4) {
|
|
|
520 |
$tabs.tabs('select', "#obs-vue-tableau");
|
|
|
521 |
} else {
|
|
|
522 |
$tabs.tabs('select', "#obs-vue-liste");
|
|
|
523 |
}
|
|
|
524 |
|
| 915 |
jpm |
525 |
}
|
|
|
526 |
|
| 939 |
jpm |
527 |
function selectionnerOnglet(onglet) {
|
| 980 |
jpm |
528 |
$(onglet).css('display', 'block');
|
| 939 |
jpm |
529 |
$('#obs').tabs('select', onglet);
|
|
|
530 |
}
|
|
|
531 |
|
| 915 |
jpm |
532 |
function afficherTextStationId() {
|
| 980 |
jpm |
533 |
$('#obs-station-id').text(pointClique.stationInfos.id);
|
| 915 |
jpm |
534 |
}
|
|
|
535 |
|
|
|
536 |
function corrigerLargeurInfoWindow() {
|
| 953 |
jpm |
537 |
$("#info-bulle").width($("#info-bulle").width() - 17);
|
| 915 |
jpm |
538 |
}
|
|
|
539 |
|
|
|
540 |
function surClicAffichageTableau(event) {
|
|
|
541 |
pagineur.format = 'tableau';
|
|
|
542 |
mettreAJourObservations();
|
|
|
543 |
mettreAJourTableauTriable("#obs-tableau");
|
|
|
544 |
}
|
|
|
545 |
|
|
|
546 |
function surClicAffichageListe(event) {
|
|
|
547 |
pagineur.format = 'liste';
|
|
|
548 |
mettreAJourObservations();
|
|
|
549 |
ajouterGaleriePhoto("a.cel-img");
|
|
|
550 |
}
|
|
|
551 |
|
| 836 |
jpm |
552 |
function ajouterTableauTriable(element) {
|
|
|
553 |
// add parser through the tablesorter addParser method
|
|
|
554 |
$.tablesorter.addParser({
|
|
|
555 |
// Définition d'un id unique pour ce parsseur
|
|
|
556 |
id: 'date_cel',
|
|
|
557 |
is: function(s) {
|
| 915 |
jpm |
558 |
// doit retourner false si le parsseur n'est pas autodétecté
|
|
|
559 |
return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s);
|
| 836 |
jpm |
560 |
},
|
| 915 |
jpm |
561 |
format: function(date) {
|
| 836 |
jpm |
562 |
// Transformation date jj/mm/aaaa en aaaa/mm/jj
|
| 915 |
jpm |
563 |
date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3/$2/$1");
|
| 836 |
jpm |
564 |
// Remplace la date par un nombre de millisecondes pour trier numériquement
|
| 915 |
jpm |
565 |
return $.tablesorter.formatFloat(new Date(date).getTime());
|
| 836 |
jpm |
566 |
},
|
|
|
567 |
// set type, either numeric or text
|
|
|
568 |
type: 'numeric'
|
|
|
569 |
});
|
|
|
570 |
$(element).tablesorter({
|
|
|
571 |
headers: {
|
| 915 |
jpm |
572 |
1: {
|
|
|
573 |
sorter:'date_cel'
|
|
|
574 |
}
|
|
|
575 |
}
|
|
|
576 |
});
|
| 836 |
jpm |
577 |
}
|
|
|
578 |
|
| 915 |
jpm |
579 |
function mettreAJourTableauTriable(element) {
|
|
|
580 |
$(element).trigger('update');
|
|
|
581 |
}
|
|
|
582 |
|
| 836 |
jpm |
583 |
function ajouterGaleriePhoto(element) {
|
|
|
584 |
$(element).fancybox({
|
| 915 |
jpm |
585 |
transitionIn:'elastic',
|
|
|
586 |
transitionOut:'elastic',
|
|
|
587 |
speedIn :600,
|
|
|
588 |
speedOut:200,
|
|
|
589 |
overlayShow:true,
|
|
|
590 |
titleShow:true,
|
|
|
591 |
titlePosition:'inside',
|
|
|
592 |
titleFormat:function (titre, currentArray, currentIndex, currentOpts) {
|
|
|
593 |
var motif = /urn:lsid:tela-botanica[.]org:cel:img([0-9]+)$/;
|
|
|
594 |
motif.exec(titre);
|
|
|
595 |
var id = RegExp.$1;
|
|
|
596 |
var info = $('#cel-info-'+id).clone().html();
|
|
|
597 |
var tpl =
|
|
|
598 |
'<div class="cel-legende">'+
|
|
|
599 |
'<p class="cel-legende-vei">'+'Image n°' + (currentIndex + 1) + ' sur ' + currentArray.length +'<\/p>'+
|
|
|
600 |
(titre && titre.length ? '<p>'+info+'<\/p>' : '' )+
|
|
|
601 |
'<\/div>';
|
|
|
602 |
return tpl;
|
| 836 |
jpm |
603 |
}
|
| 915 |
jpm |
604 |
}).live('click', function(e) {
|
|
|
605 |
if (e.stopPropagation) {
|
|
|
606 |
e.stopPropagation();
|
|
|
607 |
}
|
|
|
608 |
return false;
|
|
|
609 |
});
|
| 836 |
jpm |
610 |
}
|
|
|
611 |
|
| 941 |
jpm |
612 |
function ajouterFomulaireContact(element) {
|
|
|
613 |
$(element).fancybox({
|
|
|
614 |
transitionIn:'elastic',
|
|
|
615 |
transitionOut:'elastic',
|
|
|
616 |
speedIn :600,
|
|
|
617 |
speedOut:200,
|
|
|
618 |
scrolling: 'no',
|
|
|
619 |
titleShow: false,
|
|
|
620 |
onStart: function(selectedArray, selectedIndex, selectedOpts) {
|
|
|
621 |
var element = selectedArray[selectedIndex];
|
|
|
622 |
|
|
|
623 |
var motif = / contributeur-([0-9]+)$/;
|
|
|
624 |
motif.exec($(element).attr('class'));
|
|
|
625 |
var id = RegExp.$1;
|
| 950 |
jpm |
626 |
//console.log('Destinataire id : '+id);
|
| 941 |
jpm |
627 |
$("#fc_destinataire_id").attr('value', id);
|
|
|
628 |
|
|
|
629 |
var motif = / obs-([0-9]+) /;
|
|
|
630 |
motif.exec($(element).attr('class'));
|
|
|
631 |
var id = RegExp.$1;
|
| 950 |
jpm |
632 |
//console.log('Obs id : '+id);
|
| 941 |
jpm |
633 |
chargerInfoObsPourMessage(id);
|
|
|
634 |
},
|
|
|
635 |
onCleanup: function() {
|
| 950 |
jpm |
636 |
//console.log('Avant fermeture fancybox');
|
| 941 |
jpm |
637 |
$("#fc_destinataire_id").attr('value', '');
|
|
|
638 |
$("#fc_sujet").attr('value', '');
|
|
|
639 |
$("#fc_message").text('');
|
|
|
640 |
},
|
|
|
641 |
onClosed: function(e) {
|
| 950 |
jpm |
642 |
//console.log('Fermeture fancybox');
|
| 941 |
jpm |
643 |
if (e.stopPropagation) {
|
|
|
644 |
e.stopPropagation();
|
|
|
645 |
}
|
|
|
646 |
return false;
|
|
|
647 |
}
|
|
|
648 |
});
|
|
|
649 |
}
|
|
|
650 |
|
|
|
651 |
function chargerInfoObsPourMessage(idObs) {
|
| 980 |
jpm |
652 |
var nomSci = jQuery.trim($(".cel-obs-"+idObs+" .nom-sci:eq(0)").text());
|
|
|
653 |
var date = jQuery.trim($(".cel-obs-"+idObs+" .date:eq(0)").text());
|
|
|
654 |
var lieu = jQuery.trim($(".cel-obs-"+idObs+" .lieu:eq(0)").text());
|
| 953 |
jpm |
655 |
var sujet = "Observation #"+idObs+" de "+nomSci;
|
|
|
656 |
var message = "\n\n\n\n\n\n\n\n--\nConcerne l'observation de \""+nomSci+'" du "'+date+'" au lieu "'+lieu+'".';
|
| 941 |
jpm |
657 |
$("#fc_sujet").attr('value', sujet);
|
|
|
658 |
$("#fc_message").text(message);
|
|
|
659 |
}
|
|
|
660 |
|
|
|
661 |
function initialiserFormulaireContact() {
|
| 950 |
jpm |
662 |
//console.log('Initialisation du form contact');
|
| 941 |
jpm |
663 |
$("#form-contact").validate({
|
|
|
664 |
rules: {
|
|
|
665 |
fc_sujet : "required",
|
|
|
666 |
fc_message : "required",
|
| 953 |
jpm |
667 |
fc_utilisateur_courriel : {
|
|
|
668 |
required : true,
|
|
|
669 |
email : true}
|
| 941 |
jpm |
670 |
}
|
|
|
671 |
});
|
|
|
672 |
$("#form-contact").bind("submit", envoyerCourriel);
|
| 950 |
jpm |
673 |
$("#fc_annuler").bind("click", function() {$.fancybox.close();});
|
| 941 |
jpm |
674 |
|
|
|
675 |
}
|
|
|
676 |
|
|
|
677 |
function envoyerCourriel() {
|
| 950 |
jpm |
678 |
//console.log('Formulaire soumis');
|
| 941 |
jpm |
679 |
if ($("#form-contact").valid()) {
|
| 950 |
jpm |
680 |
//console.log('Formulaire valide');
|
| 941 |
jpm |
681 |
//$.fancybox.showActivity();
|
|
|
682 |
var destinataireId = $("#fc_destinataire_id").attr('value');
|
|
|
683 |
var urlMessage = "http://www.tela-botanica.org/service:annuaire:Utilisateur/"+destinataireId+"/message"
|
|
|
684 |
var erreurMsg = "";
|
|
|
685 |
var donnees = new Array();
|
|
|
686 |
$.each($(this).serializeArray(), function (index, champ) {
|
|
|
687 |
var cle = champ.name;
|
|
|
688 |
cle = cle.replace(/^fc_/, '');
|
| 953 |
jpm |
689 |
|
| 980 |
jpm |
690 |
if (cle == 'sujet') {
|
| 953 |
jpm |
691 |
champ.value += " - Carnet en ligne - Tela Botanica";
|
|
|
692 |
}
|
|
|
693 |
if (cle == 'message') {
|
|
|
694 |
champ.value += "\n--\n"+
|
| 980 |
jpm |
695 |
"Ce message vous est envoyé par l'intermédiaire du widget carto "+
|
| 953 |
jpm |
696 |
"du Carnet en Ligne du réseau Tela Botanica.\n"+
|
|
|
697 |
"http://www.tela-botanica.org/widget:cel:carto";
|
|
|
698 |
}
|
|
|
699 |
|
| 941 |
jpm |
700 |
donnees[index] = {'name':cle,'value':champ.value};
|
|
|
701 |
});
|
|
|
702 |
$.ajax({
|
|
|
703 |
type : "POST",
|
|
|
704 |
cache : false,
|
|
|
705 |
url : urlMessage,
|
|
|
706 |
data : donnees,
|
|
|
707 |
beforeSend : function() {
|
|
|
708 |
$(".msg").remove();
|
|
|
709 |
},
|
|
|
710 |
success : function(data) {
|
|
|
711 |
$("#fc-zone-dialogue").append('<pre class="msg info">'+data.message+'</pre>');
|
|
|
712 |
},
|
|
|
713 |
error : function(jqXHR, textStatus, errorThrown) {
|
|
|
714 |
erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
|
|
|
715 |
reponse = jQuery.parseJSON(jqXHR.responseText);
|
|
|
716 |
if (reponse != null) {
|
|
|
717 |
$.each(reponse, function (cle, valeur) {
|
|
|
718 |
erreurMsg += valeur + "\n";
|
|
|
719 |
});
|
|
|
720 |
}
|
|
|
721 |
},
|
|
|
722 |
complete : function(jqXHR, textStatus) {
|
|
|
723 |
var debugMsg = '';
|
|
|
724 |
if (jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
|
|
|
725 |
debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
|
|
|
726 |
if (debugInfos != null) {
|
|
|
727 |
$.each(debugInfos, function (cle, valeur) {
|
|
|
728 |
debugMsg += valeur + "\n";
|
|
|
729 |
});
|
|
|
730 |
}
|
|
|
731 |
}
|
|
|
732 |
if (erreurMsg != '') {
|
|
|
733 |
$("#fc-zone-dialogue").append('<p class="msg">'+
|
|
|
734 |
'Une erreur est survenue lors de la transmission de votre message.'+'<br />'+
|
|
|
735 |
'Vous pouvez signaler le disfonctionnement à <a href="'+
|
|
|
736 |
'mailto:cel@tela-botanica.org'+'?'+
|
| 980 |
jpm |
737 |
'subject=Disfonctionnement du widget carto'+
|
| 941 |
jpm |
738 |
"&body="+erreurMsg+"\nDébogage :\n"+debugMsg+
|
|
|
739 |
'">cel@tela-botanica.org</a>.'+
|
|
|
740 |
'</p>');
|
|
|
741 |
}
|
|
|
742 |
if (DEBUG) {
|
|
|
743 |
console.log('Débogage : '+debugMsg);
|
|
|
744 |
}
|
| 950 |
jpm |
745 |
//console.log('Débogage : '+debugMsg);
|
|
|
746 |
//console.log('Erreur : '+erreurMsg);
|
| 941 |
jpm |
747 |
}
|
|
|
748 |
});
|
|
|
749 |
}
|
|
|
750 |
return false;
|
|
|
751 |
}
|
| 915 |
jpm |
752 |
/*+--------------------------------------------------------------------------------------------------------+*/
|
|
|
753 |
// PANNEAU LATÉRAL
|
| 836 |
jpm |
754 |
|
| 915 |
jpm |
755 |
function initialiserAffichagePanneauLateral() {
|
|
|
756 |
$('#panneau-lateral').height($(window).height() - 35);
|
| 841 |
jpm |
757 |
|
| 915 |
jpm |
758 |
if (nt == '*') {
|
|
|
759 |
$('#pl-ouverture').bind('click', afficherPanneauLateral);
|
|
|
760 |
$('#pl-fermeture').bind('click', cacherPanneauLateral);
|
| 836 |
jpm |
761 |
}
|
| 939 |
jpm |
762 |
chargerTaxons(0, 0);
|
| 836 |
jpm |
763 |
}
|
|
|
764 |
|
| 939 |
jpm |
765 |
function chargerTaxons(depart, total) {
|
|
|
766 |
if (depart == 0 || depart < total) {
|
|
|
767 |
var limite = 7000;
|
| 950 |
jpm |
768 |
//console.log("Chargement des taxons de "+depart+" à "+(depart+limite));
|
| 939 |
jpm |
769 |
var urlTax = taxonsUrl+'&start={start}&limit='+limite;
|
|
|
770 |
urlTax = urlTax.replace(/\{start\}/g, depart);
|
|
|
771 |
$.getJSON(urlTax, function(infos) {
|
|
|
772 |
taxonsCarte = taxonsCarte.concat(infos.taxons);
|
| 950 |
jpm |
773 |
//console.log("Nbre taxons :"+taxonsCarte.length);
|
| 939 |
jpm |
774 |
chargerTaxons(depart+limite, infos.total);
|
|
|
775 |
});
|
|
|
776 |
} else {
|
|
|
777 |
if (nt == '*') {
|
|
|
778 |
afficherTaxons();
|
|
|
779 |
}
|
| 980 |
jpm |
780 |
afficherTitreCarte();
|
| 939 |
jpm |
781 |
}
|
|
|
782 |
}
|
|
|
783 |
|
|
|
784 |
function afficherTaxons() {
|
| 980 |
jpm |
785 |
$(".plantes-nbre").text(taxonsCarte.length);
|
| 939 |
jpm |
786 |
$("#tpl-taxons-liste").tmpl({'taxons':taxonsCarte}).appendTo("#pl-corps");
|
|
|
787 |
$('.taxon').live('click', filtrerParTaxon);
|
|
|
788 |
}
|
|
|
789 |
|
|
|
790 |
|
| 915 |
jpm |
791 |
function afficherPanneauLateral() {
|
| 836 |
jpm |
792 |
$('#panneau-lateral').width(300);
|
|
|
793 |
$('#pl-contenu').css('display', 'block');
|
|
|
794 |
$('#pl-ouverture').css('display', 'none');
|
|
|
795 |
$('#pl-fermeture').css('display', 'block');
|
|
|
796 |
$('#carte').css('left', '300px');
|
|
|
797 |
|
|
|
798 |
google.maps.event.trigger(map, 'resize');
|
|
|
799 |
};
|
|
|
800 |
|
| 915 |
jpm |
801 |
function cacherPanneauLateral() {
|
| 836 |
jpm |
802 |
$('#panneau-lateral').width(24);
|
|
|
803 |
$('#pl-contenu').css('display', 'none');
|
|
|
804 |
$('#pl-ouverture').css('display', 'block');
|
|
|
805 |
$('#pl-fermeture').css('display', 'none');
|
|
|
806 |
$('#carte').css('left', '24px');
|
|
|
807 |
|
|
|
808 |
google.maps.event.trigger(map, 'resize');
|
|
|
809 |
};
|
|
|
810 |
|
|
|
811 |
function filtrerParTaxon() {
|
|
|
812 |
var ntAFiltrer = $('.nt', this).text();
|
|
|
813 |
infoBulle.close();
|
|
|
814 |
$('#taxon-'+nt).removeClass('taxon-actif');
|
|
|
815 |
if (nt == ntAFiltrer) {
|
|
|
816 |
nt = '*';
|
|
|
817 |
executerMarkerClusterer(pointsOrigine, boundsOrigine);
|
|
|
818 |
} else {
|
| 980 |
jpm |
819 |
var url = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+ntAFiltrer);
|
| 939 |
jpm |
820 |
$.getJSON(url, function (stationsFiltrees) {
|
|
|
821 |
stations = stationsFiltrees;
|
| 836 |
jpm |
822 |
nt = ntAFiltrer;
|
|
|
823 |
$('#taxon-'+nt).addClass('taxon-actif');
|
|
|
824 |
rafraichirCarte();
|
|
|
825 |
});
|
|
|
826 |
}
|
|
|
827 |
};
|
|
|
828 |
|
| 915 |
jpm |
829 |
/*+--------------------------------------------------------------------------------------------------------+*/
|
|
|
830 |
// FONCTIONS UTILITAIRES
|
|
|
831 |
|
| 980 |
jpm |
832 |
function ouvrirPopUp(element, nomPopUp, event) {
|
|
|
833 |
var options =
|
|
|
834 |
'width=650,'+
|
|
|
835 |
'height=600,'+
|
|
|
836 |
'scrollbars=yes,'+
|
|
|
837 |
'directories=no,'+
|
|
|
838 |
'location=no,'+
|
|
|
839 |
'menubar=no,'+
|
|
|
840 |
'status=no,'+
|
|
|
841 |
'toolbar=no';
|
|
|
842 |
var popUp = window.open(element.href, nomPopUp, options);
|
|
|
843 |
if (window.focus) {
|
|
|
844 |
popUp.focus();
|
|
|
845 |
}
|
|
|
846 |
return arreter(event);
|
|
|
847 |
};
|
|
|
848 |
|
|
|
849 |
function ouvrirNouvelleFenetre(element, event) {
|
|
|
850 |
window.open(element.href);
|
|
|
851 |
return arreter(event);
|
|
|
852 |
}
|
|
|
853 |
|
| 915 |
jpm |
854 |
function arreter(event) {
|
|
|
855 |
if (event.stopPropagation) {
|
|
|
856 |
event.stopPropagation();
|
|
|
857 |
} else if (window.event) {
|
|
|
858 |
window.event.cancelBubble = true;
|
|
|
859 |
}
|
| 980 |
jpm |
860 |
if (event.preventDefault) {
|
|
|
861 |
event.preventDefault();
|
|
|
862 |
}
|
|
|
863 |
event.returnValue = false;
|
| 915 |
jpm |
864 |
return false;
|
|
|
865 |
}
|
|
|
866 |
|
| 836 |
jpm |
867 |
/**
|
|
|
868 |
* +-------------------------------------+
|
|
|
869 |
* Number.prototype.formaterNombre
|
|
|
870 |
* +-------------------------------------+
|
|
|
871 |
* Params (facultatifs):
|
|
|
872 |
* - Int decimales: nombre de decimales (exemple: 2)
|
|
|
873 |
* - String signe: le signe precedent les decimales (exemple: "," ou ".")
|
|
|
874 |
* - String separateurMilliers: comme son nom l'indique
|
|
|
875 |
* Returns:
|
|
|
876 |
* - String chaine formatee
|
|
|
877 |
* @author ::mastahbenus::
|
|
|
878 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> : ajout détection auto entier/flotant
|
|
|
879 |
* @souce http://www.javascriptfr.com/codes/FORMATER-NOMBRE-FACON-NUMBER-FORMAT-PHP_40060.aspx
|
|
|
880 |
*/
|
|
|
881 |
Number.prototype.formaterNombre = function (decimales, signe, separateurMilliers) {
|
|
|
882 |
var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
|
|
|
883 |
|
|
|
884 |
function is_int(nbre) {
|
|
|
885 |
nbre = nbre.replace(',', '.');
|
|
|
886 |
return !(parseFloat(nbre)-parseInt(nbre) > 0);
|
|
|
887 |
}
|
|
|
888 |
|
|
|
889 |
if (decimales == undefined) {
|
|
|
890 |
if (is_int(_sNombre)) {
|
|
|
891 |
decimales = 0;
|
|
|
892 |
} else {
|
|
|
893 |
decimales = 2;
|
|
|
894 |
}
|
|
|
895 |
}
|
|
|
896 |
if (signe == undefined) {
|
|
|
897 |
if (is_int(_sNombre)) {
|
|
|
898 |
signe = '';
|
|
|
899 |
} else {
|
|
|
900 |
signe = '.';
|
|
|
901 |
}
|
|
|
902 |
}
|
|
|
903 |
if (separateurMilliers == undefined) {
|
|
|
904 |
separateurMilliers = ' ';
|
|
|
905 |
}
|
|
|
906 |
|
|
|
907 |
function separeMilliers (sNombre) {
|
|
|
908 |
var sRetour = "";
|
|
|
909 |
while (sNombre.length % 3 != 0) {
|
|
|
910 |
sNombre = "0"+sNombre;
|
|
|
911 |
}
|
|
|
912 |
for (i = 0; i < sNombre.length; i += 3) {
|
|
|
913 |
if (i == sNombre.length-1) separateurMilliers = '';
|
|
|
914 |
sRetour += sNombre.substr(i, 3) + separateurMilliers;
|
|
|
915 |
}
|
|
|
916 |
while (sRetour.substr(0, 1) == "0") {
|
|
|
917 |
sRetour = sRetour.substr(1);
|
|
|
918 |
}
|
|
|
919 |
return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
|
|
|
920 |
}
|
|
|
921 |
|
|
|
922 |
if (_sNombre.indexOf('.') == -1) {
|
|
|
923 |
for (i = 0; i < decimales; i++) {
|
|
|
924 |
_sDecimales += "0";
|
|
|
925 |
}
|
|
|
926 |
_sRetour = separeMilliers(_sNombre) + signe + _sDecimales;
|
|
|
927 |
} else {
|
|
|
928 |
var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
|
|
|
929 |
if (sDecimalesTmp.length > decimales) {
|
|
|
930 |
var nDecimalesManquantes = sDecimalesTmp.length - decimales;
|
|
|
931 |
var nDiv = 1;
|
|
|
932 |
for (i = 0; i < nDecimalesManquantes; i++) {
|
|
|
933 |
nDiv *= 10;
|
|
|
934 |
}
|
|
|
935 |
_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
|
|
|
936 |
}
|
|
|
937 |
_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
|
|
|
938 |
}
|
|
|
939 |
return _sRetour;
|
| 915 |
jpm |
940 |
}
|
|
|
941 |
|
|
|
942 |
function debug(objet) {
|
|
|
943 |
var msg = '';
|
|
|
944 |
if (objet != null) {
|
|
|
945 |
$.each(objet, function (cle, valeur) {
|
|
|
946 |
msg += cle+":"+valeur + "\n";
|
|
|
947 |
});
|
|
|
948 |
} else {
|
|
|
949 |
msg = "La variable vaut null.";
|
|
|
950 |
}
|
|
|
951 |
console.log(msg);
|
| 836 |
jpm |
952 |
}
|