Spaces:
Running
Running
Download script.js from cada-1/blogsphere-chronicles: direct link, hf CLI and curl.
- Browser
- Download file 3.48 kB
-
https://huggingface.co/spaces/cada-1/blogsphere-chronicles/resolve/main/script.js
- Command line
-
hf download hf://spaces/cada-1/blogsphere-chronicles/script.js
-
curl -L -o script.js https://huggingface.co/spaces/cada-1/blogsphere-chronicles/resolve/main/script.js
3.48 kB
| // Initialize Alpine.js for reactive components | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // Mobile menu toggle functionality | |
| const mobileMenuButton = document.getElementById('mobile-menu-button'); | |
| const mobileMenu = document.getElementById('mobile-menu'); | |
| if(mobileMenuButton && mobileMenu) { | |
| mobileMenuButton.addEventListener('click', function() { | |
| mobileMenu.classList.toggle('hidden'); | |
| }); | |
| } | |
| // Smooth scrolling for anchor links | |
| document.querySelectorAll('a[href^="#"]').forEach(anchor => { | |
| anchor.addEventListener('click', function (e) { | |
| e.preventDefault(); | |
| const targetId = this.getAttribute('href'); | |
| if(targetId === '#') return; | |
| const targetElement = document.querySelector(targetId); | |
| if(targetElement) { | |
| targetElement.scrollIntoView({ | |
| behavior: 'smooth' | |
| }); | |
| } | |
| }); | |
| }); | |
| // Initialize tooltips | |
| const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')); | |
| tooltipTriggerList.map(function (tooltipTriggerEl) { | |
| return new bootstrap.Tooltip(tooltipTriggerEl); | |
| }); | |
| // Dark mode toggle | |
| const darkModeToggle = document.getElementById('dark-mode-toggle'); | |
| if(darkModeToggle) { | |
| darkModeToggle.addEventListener('click', function() { | |
| document.documentElement.classList.toggle('dark'); | |
| localStorage.setItem('darkMode', document.documentElement.classList.contains('dark')); | |
| }); | |
| // Check for saved user preference | |
| if (localStorage.getItem('darkMode') === 'true') { | |
| document.documentElement.classList.add('dark'); | |
| } | |
| } | |
| }); | |
| // Blog search functionality | |
| function searchBlog() { | |
| const searchInput = document.getElementById('blog-search'); | |
| const searchTerm = searchInput.value.toLowerCase(); | |
| const articles = document.querySelectorAll('.blog-post-card'); | |
| articles.forEach(article => { | |
| const title = article.querySelector('.blog-post-title').textContent.toLowerCase(); | |
| const excerpt = article.querySelector('.blog-post-excerpt').textContent.toLowerCase(); | |
| if(title.includes(searchTerm) || excerpt.includes(searchTerm)) { | |
| article.style.display = 'block'; | |
| article.classList.add('fade-in'); | |
| } else { | |
| article.style.display = 'none'; | |
| } | |
| }); | |
| } | |
| // Form validation | |
| function validateForm(formId) { | |
| const form = document.getElementById(formId); | |
| if(form) { | |
| form.addEventListener('submit', function(e) { | |
| let isValid = true; | |
| const inputs = form.querySelectorAll('input[required], textarea[required]'); | |
| inputs.forEach(input => { | |
| if(!input.value.trim()) { | |
| input.classList.add('border-red-500'); | |
| isValid = false; | |
| } else { | |
| input.classList.remove('border-red-500'); | |
| } | |
| }); | |
| if(!isValid) { | |
| e.preventDefault(); | |
| alert('ุงูุฑุฌุงุก ู ูุก ุฌู ูุน ุงูุญููู ุงูู ุทููุจุฉ'); | |
| } | |
| }); | |
| } | |
| } | |
| // Initialize form validation for contact form | |
| document.addEventListener('DOMContentLoaded', function() { | |
| validateForm('contact-form'); | |
| }); |