// assets/js/script.js - Hlavní JavaScript pro ProTym.cz document.addEventListener('DOMContentLoaded', function() { console.log('ProTym.cz - JavaScript inicializován'); // Scroll to top funkce const scrollToTopBtn = document.getElementById('scrollToTop'); if (scrollToTopBtn) { window.addEventListener('scroll', () => { if (window.pageYOffset > 300) { scrollToTopBtn.style.display = 'block'; } else { scrollToTopBtn.style.display = 'none'; } }); scrollToTopBtn.addEventListener('click', () => { window.scrollTo({ top: 0, behavior: 'smooth' }); }); } // Automatické skrývání alertů po 5 sekundách const autoDismissAlerts = document.querySelectorAll('.alert.alert-dismissible'); autoDismissAlerts.forEach(alert => { setTimeout(() => { if (alert && document.body.contains(alert)) { const bsAlert = new bootstrap.Alert(alert); bsAlert.close(); } }, 5000); }); // Formulářová validace const forms = document.querySelectorAll('form'); forms.forEach(form => { form.addEventListener('submit', function(e) { const requiredFields = this.querySelectorAll('[required]'); let isValid = true; requiredFields.forEach(field => { if (!field.value.trim()) { isValid = false; field.classList.add('is-invalid'); // Přidání chybové zprávy if (!field.nextElementSibling || !field.nextElementSibling.classList.contains('invalid-feedback')) { const errorDiv = document.createElement('div'); errorDiv.className = 'invalid-feedback'; errorDiv.textContent = 'Toto pole je povinné'; field.parentNode.appendChild(errorDiv); } } else { field.classList.remove('is-invalid'); // Odstranění chybové zprávy const errorDiv = field.nextElementSibling; if (errorDiv && errorDiv.classList.contains('invalid-feedback')) { errorDiv.remove(); } } }); if (!isValid) { e.preventDefault(); const firstInvalid = this.querySelector('.is-invalid'); if (firstInvalid) { firstInvalid.focus(); } } }); }); // Toggle password visibility document.querySelectorAll('.toggle-password').forEach(button => { button.addEventListener('click', function() { const input = this.parentElement.querySelector('input'); const icon = this.querySelector('i'); if (input.type === 'password') { input.type = 'text'; icon.className = 'fas fa-eye-slash'; } else { input.type = 'password'; icon.className = 'fas fa-eye'; } }); }); // Sport icon preview - pouze pokud existují potřebné elementy const sportSelect = document.getElementById('sport_type'); const previewIcon = document.getElementById('previewIcon'); if (sportSelect && previewIcon) { sportSelect.addEventListener('change', function() { const selectedOption = this.options[this.selectedIndex]; const sportIcon = selectedOption.getAttribute('data-icon'); if (sportIcon && previewIcon) { previewIcon.className = sportIcon + ' fa-3x text-primary'; } }); // Inicializace preview při načtení stránky const initialOption = sportSelect.options[sportSelect.selectedIndex]; const initialIcon = initialOption.getAttribute('data-icon'); if (initialIcon) { previewIcon.className = initialIcon + ' fa-3x text-primary'; } } // Dynamická aktualizace náhledu týmu const teamNameInput = document.getElementById('name'); const teamCityInput = document.getElementById('city'); const teamPrivacyInput = document.getElementById('is_private'); const previewName = document.getElementById('previewName'); const previewCity = document.querySelector('#previewSport + p'); const previewBadge = document.querySelector('.card-body .badge'); if (teamNameInput && previewName) { teamNameInput.addEventListener('input', function() { previewName.textContent = this.value || 'Název týmu'; }); } if (teamCityInput) { teamCityInput.addEventListener('input', function() { if (previewCity) { if (this.value) { previewCity.innerHTML = '' + this.value; previewCity.style.display = 'block'; } else { previewCity.style.display = 'none'; } } }); } if (teamPrivacyInput && previewBadge) { teamPrivacyInput.addEventListener('change', function() { if (this.checked) { previewBadge.className = 'badge bg-secondary'; previewBadge.textContent = 'Soukromý'; } else { previewBadge.className = 'badge bg-success'; previewBadge.textContent = 'Veřejný'; } }); } // Potvrzení smazání týmu const deleteButtons = document.querySelectorAll('[data-bs-target="#deleteTeamModal"]'); deleteButtons.forEach(button => { button.addEventListener('click', function() { const teamId = this.getAttribute('data-team-id'); const teamName = this.getAttribute('data-team-name'); if (teamName) { const deleteNameSpan = document.getElementById('deleteTeamName'); if (deleteNameSpan) { deleteNameSpan.textContent = teamName; } } if (teamId) { const confirmLink = document.getElementById('confirmDelete'); if (confirmLink) { confirmLink.href = 'team_delete.php?id=' + teamId; } } }); }); // Smooth scroll pro anchor links document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { e.preventDefault(); const target = document.querySelector(this.getAttribute('href')); if (target) { target.scrollIntoView({ behavior: 'smooth', block: 'start' }); } }); }); // Tooltip inicializace const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')); tooltipTriggerList.map(function (tooltipTriggerEl) { return new bootstrap.Tooltip(tooltipTriggerEl); }); // Popover inicializace const popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]')); popoverTriggerList.map(function (popoverTriggerEl) { return new bootstrap.Popover(popoverTriggerEl); }); // Loading stav pro tlačítka document.querySelectorAll('form').forEach(form => { form.addEventListener('submit', function() { const submitButton = this.querySelector('button[type="submit"]'); if (submitButton) { submitButton.disabled = true; submitButton.innerHTML = ' Zpracování...'; } }); }); }); // Utility funkce function showToast(message, type = 'success') { // Vytvoření toast container pokud neexistuje let toastContainer = document.getElementById('toast-container'); if (!toastContainer) { toastContainer = document.createElement('div'); toastContainer.id = 'toast-container'; toastContainer.className = 'toast-container position-fixed bottom-0 end-0 p-3'; document.body.appendChild(toastContainer); } const toastId = 'toast-' + Date.now(); const toast = document.createElement('div'); toast.id = toastId; toast.className = `toast align-items-center text-white bg-${type} border-0`; toast.innerHTML = `