1jQuery(document).ready(function($) { 2 // Inicializa o Flatpickr 3 var datePicker = flatpickr('#agenda-date-picker', { 4 defaultDate: 'today', // Define a data inicial como hoje 5 dateFormat: 'd/m/Y', // Formato da data (dia/mês/ano) 6 locale: 'pt', // Define o idioma como português 7 onChange: function(selectedDates, dateStr, instance) { 8 // Atualiza o input com a data selecionada 9 $('#agenda-date-picker').val(dateStr); 10 11 // Converte a data para o formato YYYY-MM-DD 12 var selectedDate = selectedDates[0]; 13 var formattedDate = selectedDate.toISOString().split('T')[0]; 14 15 // Carrega os eventos para a data selecionada 16 loadEvents(formattedDate); 17 }, 18 onDayCreate: function(dObj, dStr, fp, dayElem) { 19 // Destaca os dias que têm eventos 20 if (agenda_event_dates.includes(dayElem.dateObj.toISOString().split('T')[0])) { 21 dayElem.classList.add('event-day'); // Adiciona uma classe para destacar 22 } 23 } 24 }); 25 26 // Carrega os eventos do dia atual ao carregar a página 27 var currentDate = new Date(); 28 var formattedDate = currentDate.toISOString().split('T')[0]; 29 loadEvents(formattedDate); 30 31 // Botão "Dia Anterior" 32 $('#prev-day').on('click', function() { 33 var currentDate = datePicker.selectedDates[0]; 34 if (currentDate) { 35 var prevDate = new Date(currentDate); 36 prevDate.setDate(prevDate.getDate() - 1); // Subtrai um dia 37 datePicker.setDate(prevDate); // Atualiza o calendário 38 var formattedDate = formatDate(prevDate); // Formata a data como DD/MM/YYYY 39 $('#agenda-date-picker').val(formattedDate); // Atualiza o input 40 loadEvents(prevDate.toISOString().split('T')[0]); // Carrega os eventos 41 } 42 }); 43 44 // Botão "Próximo Dia" 45 $('#next-day').on('click', function() { 46 var currentDate = datePicker.selectedDates[0]; 47 if (currentDate) { 48 var nextDate = new Date(currentDate); 49 nextDate.setDate(nextDate.getDate() + 1); // Adiciona um dia 50 datePicker.setDate(nextDate); // Atualiza o calendário 51 var formattedDate = formatDate(nextDate); // Formata a data como DD/MM/YYYY 52 $('#agenda-date-picker').val(formattedDate); // Atualiza o input 53 loadEvents(nextDate.toISOString().split('T')[0]); // Carrega os eventos 54 } 55 }); 56 57 // Função para formatar a data como DD/MM/YYYY 58 function formatDate(date) { 59 var day = String(date.getDate()).padStart(2, '0'); // Dia (com zero à esquerda) 60 var month = String(date.getMonth() + 1).padStart(2, '0'); // Mês (com zero à esquerda) 61 var year = date.getFullYear(); // Ano 62 return `${day}/${month}/${year}`; // Retorna a data no formato DD/MM/YYYY 63 } 64 65 // Carrega eventos para a data selecionada 66 function loadEvents(date) { 67 $.ajax({
68 url: agenda_ajax.ajax_url, 69 type: 'POST', 70 data: { 71 action: 'agenda_load_events', 72 date: date 73 }, 74 success: function(response) { 75 $('.agenda-events').html(response); // Exibe os eventos na página 76 } 77 }); 78 } 79});
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.