Spaces:
Running
Running
crie um codigo para ser utilzado no site do wix, sera um site para uma empresa de pulverização agricola .
56de4b7 verified Download script.js from JuniorPrestes/agropulverize-pro: direct link, hf CLI and curl.
- Browser
- Download file 9.96 kB
-
https://huggingface.co/spaces/JuniorPrestes/agropulverize-pro/resolve/main/script.js
- Command line
-
hf download hf://spaces/JuniorPrestes/agropulverize-pro/script.js
-
curl -L -o script.js https://huggingface.co/spaces/JuniorPrestes/agropulverize-pro/resolve/main/script.js
9.96 kB
| // AgroPulverize Pro - Main JavaScript | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // Initialize Feather Icons | |
| if (typeof feather !== 'undefined') { | |
| feather.replace(); | |
| } | |
| // Load News from RSS | |
| loadNews(); | |
| // Initialize Forms | |
| initForms(); | |
| // Initialize Scroll Effects | |
| initScrollEffects(); | |
| // Initialize Mobile Menu | |
| initMobileMenu(); | |
| }); | |
| // News Loading Function | |
| async function loadNews() { | |
| const newsContainer = document.getElementById('news-container'); | |
| if (!newsContainer) return; | |
| // Using a CORS proxy to fetch RSS feed | |
| const rssUrls = [ | |
| 'https://www.noticiasagricolas.com.br/rss/ultimas-noticias.xml', | |
| 'https://g1.globo.com/rss/g1/agronegocios/' | |
| ]; | |
| try { | |
| // Fallback to mock news if RSS fails | |
| const mockNews = [ | |
| { | |
| title: 'Drones agrícolas aumentam produtividade em 40% no Mato Grosso', | |
| description: 'Estudo mostra que pulverização aérea com drones reduziu custos e aumentou eficiência na aplicação de defensivos.', | |
| image: 'http://static.photos/agriculture/640x360/101', | |
| date: '15 Jan 2025', | |
| category: 'Tecnologia' | |
| }, | |
| { | |
| title: 'Governo libera novos créditos para modernização do campo', | |
| description: 'Produtores rurais terão acesso a financiamentos com taxas reduzidas para aquisição de equipamentos de precisão.', | |
| image: 'http://static.photos/finance/640x360/202', | |
| date: '14 Jan 2025', | |
| category: 'Política' | |
| }, | |
| { | |
| title: 'Sustentabilidade: práticas agrícolas de baixo carbono crescem no Brasil', | |
| description: 'Movimento por agricultura regenerativa ganha força entre grandes produtores do Centro-Oeste.', | |
| image: 'http://static.photos/nature/640x360/303', | |
| date: '13 Jan 2025', | |
| category: 'Sustentabilidade' | |
| } | |
| ]; | |
| // Try to fetch real news, fallback to mock | |
| let news = mockNews; | |
| try { | |
| const response = await fetch('https://api.rss2json.com/v1/api.json?rss_url=' + encodeURIComponent(rssUrls[0])); | |
| const data = await response.json(); | |
| if (data.items && data.items.length > 0) { | |
| news = data.items.slice(0, 3).map((item, index) => ({ | |
| title: item.title, | |
| description: item.description ? item.description.replace(/<[^>]*>/g, '').substring(0, 120) + '...' : 'Leia mais sobre esta notícia...', | |
| image: `http://static.photos/agriculture/640x360/${400 + index}`, | |
| date: new Date(item.pubDate).toLocaleDateString('pt-BR', { day: '2-digit', month: 'short', year: 'numeric' }), | |
| category: 'Agronegócio', | |
| link: item.link | |
| })); | |
| } | |
| } catch (e) { | |
| console.log('Using mock news data'); | |
| } | |
| renderNews(news); | |
| } catch (error) { | |
| console.error('Error loading news:', error); | |
| newsContainer.innerHTML = '<p class="text-secondary-500 text-center col-span-3">Não foi possível carregar as notícias.</p>'; | |
| } | |
| } | |
| function renderNews(news) { | |
| const newsContainer = document.getElementById('news-container'); | |
| newsContainer.innerHTML = news.map((item, index) => ` | |
| <article class="news-card bg-secondary-50 rounded-2xl overflow-hidden group cursor-pointer" onclick="window.open('${item.link || '#'}', '_blank')"> | |
| <div class="relative h-48 overflow-hidden"> | |
| <img src="${item.image}" alt="${item.title}" class="news-image w-full h-full object-cover"> | |
| <div class="absolute top-4 left-4"> | |
| <span class="bg-primary-500 text-white text-xs font-semibold px-3 py-1 rounded-full">${item.category}</span> | |
| </div> | |
| </div> | |
| <div class="p-6"> | |
| <div class="flex items-center gap-2 text-secondary-400 text-sm mb-3"> | |
| <i data-feather="calendar" class="w-4 h-4"></i> | |
| <span>${item.date}</span> | |
| </div> | |
| <h3 class="font-bold text-secondary-900 mb-2 line-clamp-2 group-hover:text-primary-600 transition-colors">${item.title}</h3> | |
| <p class="text-secondary-600 text-sm line-clamp-2">${item.description}</p> | |
| <div class="mt-4 flex items-center gap-2 text-primary-600 font-medium text-sm group-hover:gap-3 transition-all"> | |
| Ler mais | |
| <i data-feather="arrow-right" class="w-4 h-4"></i> | |
| </div> | |
| </div> | |
| </article> | |
| `).join(''); | |
| // Re-initialize Feather Icons for new content | |
| if (typeof feather !== 'undefined') { | |
| feather.replace(); | |
| } | |
| } | |
| // Form Initialization | |
| function initForms() { | |
| // Contact Form | |
| const contactForm = document.getElementById('contact-form'); | |
| if (contactForm) { | |
| contactForm.addEventListener('submit', handleContactSubmit); | |
| } | |
| // Login Form | |
| const loginForm = document.getElementById('login-form'); | |
| if (loginForm) { | |
| loginForm.addEventListener('submit', handleLoginSubmit); | |
| } | |
| } | |
| function handleContactSubmit(e) { | |
| e.preventDefault(); | |
| const formData = new FormData(e.target); | |
| const data = Object.fromEntries(formData); | |
| // Show success message | |
| showToast('Mensagem enviada com sucesso! Entraremos em contato em breve.', 'success'); | |
| // Reset form | |
| e.target.reset(); | |
| // Here you would typically send to a server | |
| console.log('Contact form data:', data); | |
| } | |
| function handleLoginSubmit(e) { | |
| e.preventDefault(); | |
| // Simulate login | |
| showToast('Área do cliente em desenvolvimento. Entre em contato pelo WhatsApp!', 'error'); | |
| e.target.reset(); | |
| } | |
| // Toast Notification | |
| function showToast(message, type = 'success') { | |
| // Remove existing toasts | |
| const existingToast = document.querySelector('.toast'); | |
| if (existingToast) { | |
| existingToast.remove(); | |
| } | |
| const toast = document.createElement('div'); | |
| toast.className = `toast toast-${type}`; | |
| toast.innerHTML = ` | |
| <div class="flex items-center gap-3"> | |
| <div class="w-10 h-10 ${type === 'success' ? 'bg-green-100' : 'bg-red-100'} rounded-full flex items-center justify-center"> | |
| <i data-feather="${type === 'success' ? 'check' : 'alert-circle'}" class="w-5 h-5 ${type === 'success' ? 'text-green-600' : 'text-red-600'}"></i> | |
| </div> | |
| <div> | |
| <div class="font-semibold text-secondary-900">${type === 'success' ? 'Sucesso!' : 'Atenção'}</div> | |
| <div class="text-secondary-600 text-sm">${message}</div> | |
| </div> | |
| </div> | |
| `; | |
| document.body.appendChild(toast); | |
| // Initialize feather icons in toast | |
| if (typeof feather !== 'undefined') { | |
| feather.replace(); | |
| } | |
| // Show toast | |
| requestAnimationFrame(() => { | |
| toast.classList.add('show'); | |
| }); | |
| // Hide after 4 seconds | |
| setTimeout(() => { | |
| toast.classList.remove('show'); | |
| setTimeout(() => toast.remove(), 300); | |
| }, 4000); | |
| } | |
| // Scroll Effects | |
| function initScrollEffects() { | |
| const navbar = document.querySelector('agro-navbar'); | |
| if (!navbar) return; | |
| const shadowRoot = navbar.shadowRoot; | |
| if (!shadowRoot) return; | |
| const nav = shadowRoot.querySelector('nav'); | |
| if (!nav) return; | |
| let lastScroll = 0; | |
| window.addEventListener('scroll', () => { | |
| const currentScroll = window.pageYOffset; | |
| if (currentScroll > 100) { | |
| nav.classList.add('bg-white/95', 'backdrop-blur-md', 'shadow-lg'); | |
| nav.classList.remove('bg-transparent'); | |
| } else { | |
| nav.classList.remove('bg-white/95', 'backdrop-blur-md', 'shadow-lg'); | |
| nav.classList.add('bg-transparent'); | |
| } | |
| lastScroll = currentScroll; | |
| }, { passive: true }); | |
| // Smooth scroll for anchor links | |
| document.querySelectorAll('a[href^="#"]').forEach(anchor => { | |
| anchor.addEventListener('click', function(e) { | |
| const href = this.getAttribute('href'); | |
| if (href === '#') return; | |
| const target = document.querySelector(href); | |
| if (target) { | |
| e.preventDefault(); | |
| target.scrollIntoView({ | |
| behavior: 'smooth', | |
| block: 'start' | |
| }); | |
| } | |
| }); | |
| }); | |
| } | |
| // Mobile Menu | |
| function initMobileMenu() { | |
| // Mobile menu functionality is handled in the navbar component | |
| } | |
| // Utility: Format Phone Number | |
| function formatPhone(value) { | |
| return value | |
| .replace(/\D/g, '') | |
| .replace(/(\d{2})(\d)/, '($1) $2') | |
| .replace(/(\d{5})(\d)/, '$1-$2') | |
| .replace(/(-\d{4})\d+?$/, '$1'); | |
| } | |
| // Utility: Format CPF/CNPJ | |
| function formatDocument(value) { | |
| const cleaned = value.replace(/\D/g, ''); | |
| if (cleaned.length <= 11) { | |
| // CPF | |
| return cleaned | |
| .replace(/(\d{3})(\d)/, '$1.$2') | |
| .replace(/(\d{3})(\d)/, '$1.$2') | |
| .replace(/(\d{3})(\d{1,2})$/, '$1-$2'); | |
| } else { | |
| // CNPJ | |
| return cleaned | |
| .replace(/(\d{2})(\d)/, '$1.$2') | |
| .replace(/(\d{3})(\d)/, '$1.$2') | |
| .replace(/(\d{3})(\d)/, '$1/$2') | |
| .replace(/(\d{4})(\d{1,2})$/, '$1-$2'); | |
| } | |
| } | |
| // Auto-format inputs | |
| document.addEventListener('input', function(e) { | |
| if (e.target.matches('input[type="tel"]')) { | |
| e.target.value = formatPhone(e.target.value); | |
| } | |
| if (e.target.matches('input[placeholder*="CPF/CNPJ"]')) { | |
| e.target.value = formatDocument(e.target.value); | |
| } | |
| }); |