PageSourceSearch

https://kevinstaut.com/assets/components/kevin/v002/js/ks-agenda.js

js kevinstaut.com collected 2026-10-02 22:20:16 UTC 18,100 bytes, 642 lines download raw bytes

1/**
2 * Kevin Staut - official website - Agenda
3 *
4 * v 002
5 *
6 * last-édit : 2015-07-30
7 */
8var agenda = {};
9
10var infosCarte = {};
11
12
13
14
15/************************
16 *        Listing
17 ************************/
18
19 	kevin.ouvre_agenda_listing = function() {
20 		$('#agenda_listing').removeClass('ferme');
21 		if (agenda.moisListeSelection!==null) {
22			$('#agenda_liste').mCustomScrollbar('scrollTo', agenda.moisListeSelection);
23 		} else {
24			$('#agenda_liste').mCustomScrollbar('scrollTo', '#mois_' + agenda.anneeActuelle + '_' + agenda.moisActuel);
25 		}
26		agenda.ferme_ongletInfos();
27 	};
28
29 	kevin.ferme_agenda_listing = function() {
30		$('#agenda_listing').addClass('ferme');
31 	};
32
33
34
35
36	agenda.dateActuelle = new Date();
37    agenda.moisActuel = agenda.dateActuelle.getMonth()+1;
38    if (agenda.moisActuel<10) {
39    	agenda.moisActuel = '0' + agenda.moisActuel;
40    }
41    agenda.anneeActuelle = agenda.dateActuelle.getFullYear();
42
43
44
45/************************
46 *    Navigation carte
47 ************************/
48
49
50	agenda.init = function() {
51		agenda.zoomActuel =  1;
52		agenda.decalageX =  0;
53		agenda.decalageY = 0;
54		agenda.facteur = 1;
55		agenda.centrageCarte();
56
57		agenda.moisListeSelection = null;
58	};
59
60
61	agenda.centrageCarte = function() {
62		agenda.posXcarte = ($(window).width() - $('#carte_agenda').width()) /2 ;
63		agenda.posYcarte = ($('#section_3 .fp-tableCell').height() - $('#carte_agenda').height()) /2 ;
64		$('#carte_agenda').css({
65			'left': agenda.posXcarte+'px',
66			'top':  agenda.posYcarte+'px'
67		});
68		if (agenda.zoomActuel==1 && $('#carte_agenda').width()< $(window).width() ) {
69			agenda.zoomActuel = 2;
70			agenda.zoom();
71        }
72    };
73
74
75	agenda.zoom = function() {
76		switch(agenda.zoomActuel){
77			case 1: agenda.facteur = 0.5;		break;
78			case 2: agenda.facteur = 1;			break;
79			case 3: agenda.facteur = 2;		break;
80			case 4: agenda.facteur = 2;		break;
81			case 5: agenda.facteur = 4;		break;
82			case 6: agenda.facteur = 6;		break;
83		}
84		agenda.largeurCarte = 1000 * agenda.facteur;
85		agenda.hauteurCarte = 600 * agenda.facteur;
86		$('#carte_agenda').css({
87			'width': agenda.largeurCarte+'px',
88			'height':  agenda.hauteurCarte+'px',
89			'backgroundSize' : agenda.largeurCarte+'px '+agenda.hauteurCarte+'px'
90		});
91		agenda.centrageCarte();
92	};
93
94
95	agenda.btn_carte_moins = function() {
96		if (agenda.zoomActuel>1) {
97			agenda.zoomActuel -= 1;
98        }
99        agenda.zoom();
100	};
101
102
103	agenda.btn_carte_plus = function() {
104		if (agenda.zoomActuel<6) {
105			agenda.zoomActuel += 1;
106        }
107        agenda.zoom();
108	};
109
110
111	agenda.btn_carte_haut = function() {
112		agenda.posYcarte += $(window).height() / 4;
113		if (agenda.posYcarte>0) {
114			agenda.posYcarte = 0;
115        }
116        $('#carte_agenda').animate({
117			'top': agenda.posYcarte+'px'
118		});
119	};
120
121
122	agenda.btn_carte_bas = function() {
123		agenda.posYcarte -= $(window).height() / 4;
124		var maxTop = $('#zone_agenda').height() - $('#carte_agenda').height();
125		if (agenda.posYcarte<maxTop) {
126			agenda.posYcarte = maxTop;
127        }
128        $('#carte_agenda').animate({
129			'top': agenda.posYcarte+'px'
130		});
131
132	};
133
134
135	agenda.btn_carte_gauche = function() {
136		agenda.posXcarte += $(window).width() / 4;
137		if (agenda.posXcarte>0) {
138			agenda.posXcarte = 0;
139        }
140        $('#carte_agenda').animate({
141			'left': agenda.posXcarte+'px'
142		});
143
144	};
145
146
147	agenda.btn_carte_droite = function() {
148		agenda.posXcarte -= $(window).width() / 4;
149		var maxLeft = $('#zone_agenda').width() - $('#carte_agenda').width();
150		if (agenda.posXcarte<maxLeft) {
151			agenda.posXcarte = maxLeft;
152        }
153        $('#carte_agenda').animate({
154			'left': agenda.posXcarte+'px'
155		});
156
157	};
158
159
160
161
162
163	/**
164	 * afficheEvenementCarte 		Affiche un evenement sur la carte
165	 * 								quand on le sélectionne dans la liste
166	 *
167	 * @param  {int} event_id 		le id de l'évènement
168	 * @return
169	 */
170	agenda.afficheEvenementCarte = function(event_id) {
171		$('.agenda_evenement').css('opacity', '.45');
172		$('#agenda_evenement_'+event_id).css('opacity', '1');
173		$('#carte_events .evenement').hide();
174		$('#evt'+event_id).show();
175		// agenda.afficheInfosEvent('evt'+event_id);
176
177	};
178
179
180/**
181 * afficheEvenementsCarteMois    Affiche les évenement d'un mois sur la carte
182 *                                quand on le sélectionne un mois dans la liste
183 *s
184 * @return
185 * @param mois
186 */
187	agenda.afficheEvenementsCarteMois = function(mois) {
188		agenda.ferme_ongletInfos();
189		$('#carte_events .evenement').hide();
190		$(mois).parent('.mois').find('.agenda_evenement').each(function() {
191			$(this).css('opacity', '1');
192			var id = $(this).attr('id').substring(17);
193			$('#evt'+id).show();console.log('#evt'+id);
194		});
195
196
197	};
198
199
200
201
202
203
204
205
206	agenda.afficheInfosEvent = function(event_id) {
207		var infos = agenda.get_infosEvent(event_id);
208		$('#agenda_onglet_infos .pays').css('backgroundImage', 'url(assets/components/kevin/templates/images/drapeaux/flags-iso/flat/32/'+infos.evenement_pays.toUpperCase()+'.png)');
209		$('#agenda_onglet_infos .ville').html(infos.evenement_ville);
210		$('#agenda_onglet_infos .epreuve').html(infos.evenement_titre);
211		$('#agenda_onglet_infos .url').html('<a href="'+infos.evenement_lien+'" target="_blank">WWW</a>');
212		$('#agenda_onglet_infos .date').html( $('#agenda_evenement_'+infos.id +' .agenda_event_date').html()    );
213		TweenMax.to($('#agenda_onglet_infos'), 0.9, {top:0} );
214
215		// masquage de la météo
216		// et ajustement de la position de la ligne infos
217		if (event_id.substring(3)==agenda.today) {
218			$('#agenda_onglet_infos').find('.meteo').css('display', 'inline-block');
219			$('#agenda_onglet_infos').find('.temp').css('display', 'inline-block');
220			$('#agenda_onglet_infos').find('.heure').css('display', 'inline-block');
221			$('#agenda_onglet_infos').find('.zone').css('marginTop', '-20px');
222		} else {
223			$('#agenda_onglet_infos').find('.meteo').css('display', 'none');
224			$('#agenda_onglet_infos').find('.temp').css('display', 'none');
225			$('#agenda_onglet_infos').find('.heure').css('display', 'none');
226			$('#agenda_onglet_infos').find('.zone').css('marginTop', '25px');
227		}
228		kevin.ferme_agenda_listing();
229	};
230
231
232
233
234	agenda.get_infosEvent = function(event_id) {
235		var nb = agenda.liste_events.length;
236		for (var i = 0; i < nb; i++) {
237			if (event_id.substring(3) == agenda.liste_events[i].id) {
238				return agenda.liste_events[i];
239			}
240        }
241    };
242
243
244
245/************************
246 *    Navigation carte
247 ************************/
248
249
250
251	agenda.ferme_ongletInfos = function() {
252		TweenMax.to($('#agenda_onglet_infos'), 0.9, {top:-100} );
253	};
254
255
256
257
258	agenda.filtreEvents = function(quand) {
259		agenda.ferme_ongletInfos();
260		var now = new Date().getTime();
261		if (quand=='futur') {
262			$('#carte_agenda .evenement').hide();
263			$('#carte_agenda .evenement').each(function() {
264				if ($(this).find('.date_debut_tri').html()*1000 >= now) {
265					$(this).show();
266				}
267			});
268		} else if (quand=='present') {
269			$('#carte_agenda .evenement').hide();
270			$('#carte_agenda .evenement').each(function() {
271				if ($(this).find('.date_debut_tri').html()*1000 < now) {
272					if (now <= $(this).find('.date_fin_tri').html()*1000) {
273						$(this).show();
274					}
275				}
276			});
277		} else if (quand=='passe') {
278			$('#carte_agenda .evenement').hide();
279			$('#carte_agenda .evenement').each(function() {
280				if ($(this).find('.date_debut_tri').html()*1000 < now) {
281					if ($(this).find('.date_fin_tri').html()*1000 < now) {
282						$(this).show();
283					}
284				}
285			});
286		} else if (quand=='important') {
287			$('#carte_agenda .evenement').hide();
288			$('#carte_agenda .evenement').each(function() {
289				if ($(this).hasClass('finale-1')) {
290					$(this).show();
291				}
292			});
293		} else if (quand=='jump5') {
294			$('#carte_agenda .evenement').hide();
295			$('#carte_agenda .evenement').each(function() {
296				if ($(this).hasClass('evt2')) {
297					$(this).show();
298				}
299			});
300		} else if (quand=='voyage') {
301			$('#carte_agenda .evenement').hide();
302			$('#carte_agenda .evenement').each(function() {
303				if ($(this).hasClass('evt1')) {
304					$(this).show();
305				}
306			});
307		} else if (quand=='all') {
308			$('#carte_agenda .evenement').hide();
309			$('#carte_agenda .evenement').each(function() {
310				if ($(this).hasClass('evt0')) {
311					$(this).show();
312				}
313			});
314		}
315
316	};
317
318
319
320	agenda.afficheInfosTiroir = function(event_id) {
321		$('.mois').removeClass('actif');
322		$.each($('.agenda_evenement'), function() {
323			if ($(this).attr('id').substring(17)==event_id.substring(3)) {
324				$(this).parents('.mois').addClass('actif');
325				$('.agenda_evenement').css('opacity', '.45');
326				$(this).css('opacity', '1');
327				agenda.moisListeSelection = $(this).parents('.mois');
328				$('#agenda_liste').mCustomScrollbar('scrollTo', $(this).parents('.mois'));
329			}
330		});
331		// kevin.ouvre_agenda_listing();
332	};
333
334
335
336
337
338    agenda.chargeContenuAgenda = function() {
339        $.ajax({
340            method: "GET",
341            data: {
342                a: 'liste_agenda'
343            },
344            url: "index.php?id=89"
345        })
346            .complete(function (msg) {
347                $('#carte_events').html(msg.responseText);
348                agenda.chargeContenuAgendaJson();
349            });
350    };
351
352
353    agenda.chargeContenuAgendaJson = function() {
354        $.ajax({
355            method: "GET",
356            data: {
357                a: 'liste_agendaJSON'
358            },
359            url: "index.php?id=89",
360            dataType: 'json'
361
362        }).complete(function(data) {
363            agenda.liste_events = eval(data.responseText);
364        	agenda.initContenuAgenda();
365        });
366    };
367
368
369
370    agenda.calculPictoMeteo = function(id_picto) {
371    	var X = 0;
372    	var Y = 0;
373    	switch (id_picto) {
374			// jour
375			case '01d': Y = 0; 		X = 0; break; 	// clear sky
376			case '02d': Y = -60; 	X = 0; break; 	// few clouds
377			case '03d': Y = -120; 	X = 0; break; 	// scattered clouds
378			case '04d': Y = -180; 	X = 0; break; 	// broken clouds
379			case '09d': Y = -240; 	X = 0; break; 	// shower rain
380			case '10d': Y = -300; 	X = 0; break; 	// rain
381			case '11d': Y = -360; 	X = 0; break; 	// thunderstorm
382			case '13d': Y = -420; 	X = 0; break; 	// snow
383			case '50d': Y = -480; 	X = 0; break; 	// mist
384			// nuit
385			case '01n': Y = 0; 	 	X = -60; break;
386			case '02n': Y = -60;  	X = -60; break;
387			case '03n': Y = -120; 	X = -60; break;
388			case '04n': Y = -180; 	X = -60; break;
389			case '09n': Y = -240; 	X = -60; break;
390			case '10n': Y = -300; 	X = -60; break;
391			case '11n': Y = -360; 	X = -60; break;
392			case '13n': Y = -420; 	X = -60; break;
393			case '50n': Y = -480; 	X = -60; break;
394    	}
395    	return {x: X, y: Y};
396    };
397
398
399    agenda.calculTime = function(offset) {
400
401	    // create Date object for current location
402	    d = new Date();
403
404	    // convert to msec
405	    // add local time zone offset
406	    // get UTC time in msec
407	    utc = d.getTime() + (d.getTimezoneOffset() * 60000);
408
409	    // create new Date object for different city
410	    // using supplied offset
411	    nd = new Date(utc + (3600000*offset));
412
413	    // return time as a string
414	    return nd;
415
416	};
417
418
419
420
421
422
423
424    agenda.initContenuAgenda = function() {
425
426        var now = new Date().getTime();
427
428        // scroll liste
429        $('#agenda_liste').mCustomScrollbar({
430            scrollButtons: {
431                enable: true,
432                scrollAmount: 120
433            },
434            mouseWheel: {
435                enable: true,
436                preventDefault: true,
437                scrollAmount: 60
438            },
439            theme: 'rounded'
440        });
441
442        //carte
443        agenda.zoomActuel =  1;
444        agenda.decalageX =  0;
445        agenda.decalageY = 0;
446        agenda.facteur = 1;
447        agenda.centrageCarte();
448
449
450        $('.agenda_titre_mois').click(function() {
451            $('.mois').removeClass('actif');
452            $(this).parent().addClass('actif');
453            $('.agenda_evenement').css('opacity', '1');
454			$('#agenda_liste').mCustomScrollbar('scrollTo', $(this).parent() );
455        });
456
457        // positionnement de la liste à la date du jour
458        $('.mois').removeClass('actif');
459        $('#mois_'+agenda.anneeActuelle+'_'+agenda.moisActuel).addClass('actif');
460		$('#agenda_liste').mCustomScrollbar('scrollTo', '#mois_' + agenda.anneeActuelle + '_' + agenda.moisActuel);
461
462
463
464        // affichage des évènement sur la carte à l'arrivée sur la page
465        $('#carte_agenda .evenement').each(function() {
466
467            var bpy = $(this).css('backgroundPosition').split(' ')[1];
468            var bpx = $(this).css('backgroundPosition').split(' ')[0];
469
470            // futur
471            if ($(this).find('.date_debut_tri').html()*1000 >= now) {
472
473                $(this).css('backgroundPosition', '-40px '+ bpy);
474
475                // pour les évenement important (JO, finales…)
476	            if ($(this).hasClass('finale-1')) {
477	            	if ($(this).hasClass('evt0')) {
478	            		$(this).css('backgroundPosition', '-40px -720px');
479						$('#agenda_evenement_'+$(this).attr('id').substring(3)).find('.agenda_event_type').css('backgroundPosition', '-40px -720px');
480	            	} else if ($(this).hasClass('evt1')) {
481	            		$(this).css('backgroundPosition', '-40px -880px');
482	            	} else if ($(this).hasClass('evt2')) {
483	            		$(this).css('backgroundPosition', '-40px -920px');
484	            	}
485	            }
486
487            } else {
488
489                // en cours
490                if ( now-86400 <= $(this).find('.date_fin_tri').html()*1000  ) {
491                    $(this).css('backgroundPosition', '0 '+bpy);
492                    $(this).css('zIndex', '99');
493                    $('#agenda_evenement_'+$(this).attr('id').substring(3)).find('.agenda_event_type').css('backgroundPosition', '0 '+bpy);
494
495	                // pour les évenement important (JO, finales…)
496		            if ($(this).hasClass('finale-1')) {
497		            	if ($(this).hasClass('evt0')) {
498		            		$(this).css('backgroundPosition', ' 0 -720px');
499		            		$('#agenda_evenement_'+$(this).attr('id').substring(3)).find('.agenda_event_type').css('backgroundPosition', '0 -720px');
500		            	} else if ($(this).hasClass('evt1')) {
501		            		$(this).css('backgroundPosition', ' 0 -880px');
502		            	} else if ($(this).hasClass('evt2')) {
503		            		$(this).css('backgroundPosition', ' 0 -920px');
504		            	}
505		            }
506                    agenda.today = $(this).attr('id').substring(3);
507                    agenda.afficheInfosEvent($(this).attr('id'));
508                    agenda.afficheInfosTiroir( $(this).attr('id') );
509
510					var infos = agenda.get_infosEvent($(this).attr('id'));
511                    var ville = infos.evenement_ville_gb;
512                    var pays = infos.evenement_pays;
513                    var APIkey = '05c63e95c2d64ce92e66c4ab9ee88f5e';
514
515					// chargement de la météo chez openWeatherMap
516					$.ajax({
517						dataType: "json",
518						url: 'https://api.openweathermap.org/data/2.5/weather?q='+ville+','+pays+'&units=metric&APPID='+APIkey,
519						complete: function(reponse) {
520							var pictoMeteo = agenda.calculPictoMeteo(reponse.responseJSON.weather[0].icon);
521
522							// affiche météo sur onglet information
523							$('#agenda_onglet_infos').find('.meteo').css('backgroundPosition', pictoMeteo.x+'px '+pictoMeteo.y+'px');
524							$('#agenda_onglet_infos').find('.temp').html(parseInt(reponse.responseJSON.main.temp, 10) +'°C');
525							// affiche météo dans tiroir
526							$('#agenda_evenement_'+agenda.today).find('.pictoMeteo').css('backgroundPosition', pictoMeteo.x+'px '+pictoMeteo.y+'px');
527							$('#agenda_evenement_'+agenda.today).find('.temp').html(parseInt(reponse.responseJSON.main.temp,10)+'°C');
528							$('#agenda_evenement_'+agenda.today).find('.agenda_event_meteo').show();
529							$('#agenda_evenement_'+agenda.today).css('height', '200px');
530
531							var heureLocale = agenda.calculTime(infos.evenement_timezone);
532							var heures = heureLocale.getHours();
533							var minutes = heureLocale.getMinutes();
534							if (minutes<10) {
535								minutes = '0' + minutes;
536							};
537							var heureVille = heures+'h'+minutes;
538
539							if ($('#page_1').hasClass('langue_fr')) {
540								$('#agenda_onglet_infos').find('.heure').html(heureVille);
541								$('#agenda_evenement_'+agenda.today).find('.heure').html(heureVille);
542							} else {
543								var modeH = ' am';
544								if (heures>12) {
545									heures = heures - 12;
546									modeH = ' pm';
547								};
548
549								heureVille = heures+':'+minutes+ modeH;
550								$('#agenda_onglet_infos').find('.heure').html(heureVille);
551								$('#agenda_evenement_'+agenda.today).find('.heure').html(heureVille);
552							}
553
554
555
556						}
557					});
558
559
560
561
562
563                }
564
565
566                // passé
567                else {
568                    $(this).css('backgroundPosition', '-80px ' + bpy);
569                    $('#agenda_evenement_'+$(this).attr('id').substring(3)).find('.agenda_event_type').css('backgroundPosition', '-80px ' + bpy);
570                    // pour les évenement important (JO, finales…)
571		            if ($(this).hasClass('finale-1')) {
572		            	if ($(this).hasClass('evt0')) {
573		            		$(this).css('backgroundPosition', '-80px -720px');
574							$('#agenda_evenement_'+$(this).attr('id').substring(3)).find('.agenda_event_type').css('backgroundPosition', '-80px -720px');
575		            	} else if ($(this).hasClass('evt1')) {
576		            		$(this).css('backgroundPosition', '-80px -880px');
577		            	} else if ($(this).hasClass('evt2')) {
578		            		$(this).css('backgroundPosition', '-80px -920px');
579		            	}
580		            }
581
582                    $(this).hide();
583                }
584            }
585
586
587
588
589            $(this).on('click', function() {
590                agenda.afficheInfosEvent( $(this).attr('id') );
591                agenda.afficheInfosTiroir( $(this).attr('id') );
592            });
593
594
595
596        });
597
598
599        $('#menu_agenda').draggable( );
600
601
602    };
603
604
605
606
607
608
609/************************
610 *    init domready
611 ************************/
612
613$(document).ready(function() {
614    agenda.chargeContenuAgenda();
615
616});
617// fin domready
618
619
620
621
622
623
624/*********************************
625 *   redimmensionnement fenetre
626 *********************************/
627$(window).resize(function() {
628
629		agenda.centrageCarte();
630
631
632});
633
634
635
636
637
638
639
640
641
642

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.