/* ========================================================= NSURED PRODUCT CATALOGUE DATA --------------------------------------------------------- TO UPDATE FROM YOUR PDF: Replace the array below with your actual product list. Copy the name, brand, description etc. from your catalogue into this JavaScript array. ========================================================= */ const products = [ // ANNAPURNA PRODUCTS { id: 1, name: "Annapurna Pure Cow Desi Ghee", brand: "annapurna", brandDisplay: "Annapurna", category: "Dairy / Ghee", description: "Traditional pure cow desi ghee made using authentic methods. Rich aroma and granular texture perfect for daily cooking and festive preparations.", image: "http://static.photos/food/640x360/101", source: "https://www.annapurnagroup.in/annapurna/", mfg: "Annapurna Group" }, { id: 2, name: "Annapurna Premium Cow Ghee (Jar)", brand: "annapurna", brandDisplay: "Annapurna", category: "Dairy / Ghee", description: "Premium jar packaging for longer shelf life. Ideal for modern kitchens and retail shelving.", image: "http://static.photos/food/640x360/102", source: "https://www.annapurnagroup.in/annapurna/", mfg: "Annapurna Group" }, // NUTTY GRITTIES PRODUCTS { id: 3, name: "Nutty Gritties Classic Trail Mix", brand: "nuttygritties", brandDisplay: "Nutty Gritties", category: "Healthy Snacks", description: "A wholesome blend of premium nuts, seeds, and dried fruits. Perfect on-the-go energy snack.", image: "http://static.photos/food/640x360/201", source: "https://nuttygritties.com/collections/all/", mfg: "Nutty Gritties" }, { id: 4, name: "Nutty Gritties Roasted Almonds", brand: "nuttygritties", brandDisplay: "Nutty Gritties", category: "Nuts", description: "California almonds lightly roasted to perfection. High protein, zero guilt snacking.", image: "http://static.photos/food/640x360/202", source: "https://nuttygritties.com/collections/all/", mfg: "Nutty Gritties" }, { id: 5, name: "Nutty Gritties Cashew Nuts", brand: "nuttygritties", brandDisplay: "Nutty Gritties", category: "Nuts", description: "Premium whole cashews, crisp and lightly salted. Great for gifting and household consumption.", image: "http://static.photos/food/640x360/203", source: "https://nuttygritties.com/collections/all/", mfg: "Nutty Gritties" }, // ROASTY TASTY PRODUCTS { id: 6, name: "Roasty Tasty Peri Peri Makhana", brand: "roastytasty", brandDisplay: "Roasty Tasty", category: "Roasted Snacks", description: "Crunchy fox nuts roasted in fiery Peri Peri seasoning. Gluten-free, low calorie, high crunch.", image: "http://static.photos/food/640x360/301", source: "https://www.roastytasty.com/collections/all-products-roasted-snacks", mfg: "Roasty Tasty" }, { id: 7, name: "Roasty Tasty Cream & Onion Makhana", brand: "roastytasty", brandDisplay: "Roasty Tasty", category: "Roasted Snacks", description: "Classic cream and onion flavor on popped lotus seeds. A healthy alternative to fried chips.", image: "http://static.photos/food/640x360/302", source: "https://www.roastytasty.com/collections/all-products-roasted-snacks", mfg: "Roasty Tasty" }, { id: 8, name: "Roasty Tasty Himalayan Salt Makhana", brand: "roastytasty", brandDisplay: "Roasty Tasty", category: "Roasted Snacks", description: "Minimalist seasoning with pure Himalayan pink salt. Let the natural taste of roasted makhanas shine.", image: "http://static.photos/food/640x360/303", source: "https://www.roastytasty.com/collections/all-products-roasted-snacks", mfg: "Roasty Tasty" } ]; /* ========================================================= BRAND SOURCE MAP (for reference & modal links) ========================================================= */ const brandSources = { annapurna: "https://www.annapurnagroup.in/annapurna/", nuttygritties: "https://nuttygritties.com/collections/all/", roastytasty: "https://www.roastytasty.com/collections/all-products-roasted-snacks" }; /* ========================================================= DOM ELEMENTS (safely queried) ========================================================= */ let productGrid, searchInput, filterContainer, noResults, mobileMenuBtn, mobileMenu; let modal, modalOverlay, modalContent, closeModalBtn; let modalImage, modalTitle, modalDesc, modalBrand, modalMfg, modalCategory, modalSource; /* ========================================================= INITIALIZATION ========================================================= */ document.addEventListener('DOMContentLoaded', function() { try { cacheElements(); setupLogos(); setupEventListeners(); renderProducts(products); // Initialize Lucide icons safely if (typeof lucide !== 'undefined' && lucide.createIcons) { lucide.createIcons(); } } catch (err) { console.error('Initialization error:', err); } }); function cacheElements() { productGrid = document.getElementById('productGrid'); searchInput = document.getElementById('searchInput'); filterContainer = document.getElementById('filterContainer'); noResults = document.getElementById('noResults'); mobileMenuBtn = document.getElementById('mobileMenuBtn'); mobileMenu = document.getElementById('mobileMenu'); modal = document.getElementById('productModal'); modalOverlay = document.getElementById('modalOverlay'); modalContent = document.getElementById('modalContent'); closeModalBtn = document.getElementById('closeModal'); modalImage = document.getElementById('modalImage'); modalTitle = document.getElementById('modalTitle'); modalDesc = document.getElementById('modalDesc'); modalBrand = document.getElementById('modalBrand'); modalMfg = document.getElementById('modalMfg'); modalCategory = document.getElementById('modalCategory'); modalSource = document.getElementById('modalSource'); } /* ========================================================= LOGO HANDLING (fail-safe) ========================================================= */ function setupLogos() { const logos = document.querySelectorAll('.site-logo'); logos.forEach(function(logo) { if (!logo) return; logo.addEventListener('error', function() { this.style.display = 'none'; const parent = this.parentElement; if (!parent) return; const fallback = parent.querySelector('.logo-fallback'); if (fallback) { fallback.classList.remove('hidden'); fallback.classList.add('flex'); } }); }); } /* ========================================================= EVENT LISTENERS ========================================================= */ function setupEventListeners() { // Mobile menu if (mobileMenuBtn && mobileMenu) { mobileMenuBtn.addEventListener('click', function() { mobileMenu.classList.toggle('hidden'); const icon = this.querySelector('i'); if (icon) { const isOpen = !mobileMenu.classList.contains('hidden'); icon.setAttribute('data-lucide', isOpen ? 'x' : 'menu'); if (typeof lucide !== 'undefined' && lucide.createIcons) { lucide.createIcons(); } } }); } // Search if (searchInput) { searchInput.addEventListener('input', function(e) { const term = (e.target.value || '').toLowerCase().trim(); filterAndRender(term, getCurrentFilter()); }); } // Filter buttons if (filterContainer) { filterContainer.addEventListener('click', function(e) { const btn = e.target.closest('.filter-btn'); if (!btn) return; filterContainer.querySelectorAll('.filter-btn').forEach(function(b) { b.classList.remove('active', 'bg-emerald-600', 'text-white', 'shadow-md'); b.classList.add('bg-white', 'text-gray-700'); }); btn.classList.remove('bg-white', 'text-gray-700'); btn.classList.add('active', 'bg-emerald-600', 'text-white', 'shadow-md'); const term = searchInput ? (searchInput.value || '').toLowerCase().trim() : ''; filterAndRender(term, btn.dataset.filter || 'all'); }); } // Brand cards click -> filter products document.querySelectorAll('.brand-card').forEach(function(card) { card.addEventListener('click', function() { const brand = this.dataset.brand; if (!brand) return; // Scroll to products const productsSection = document.getElementById('products'); if (productsSection) { productsSection.scrollIntoView({ behavior: 'smooth' }); } // Trigger filter const btn = document.querySelector('.filter-btn[data-filter="' + brand + '"]'); if (btn) { btn.click(); } }); }); // Modal close if (closeModalBtn) { closeModalBtn.addEventListener('click', closeModal); } if (modalOverlay) { modalOverlay.addEventListener('click', closeModal); } document.addEventListener('keydown', function(e) { if (e.key === 'Escape') closeModal(); }); } /* ========================================================= RENDERING ========================================================= */ function renderProducts(list) { if (!productGrid) return; productGrid.innerHTML = ''; if (!Array.isArray(list) || list.length === 0) { if (noResults) noResults.classList.remove('hidden'); return; } if (noResults) noResults.classList.add('hidden'); list.forEach(function(product) { if (!product || !product.id) return; const card = document.createElement('div'); card.className = 'product-card bg-white rounded-2xl overflow-hidden shadow-sm border border-gray-100 hover:shadow-xl cursor-pointer group h-full flex flex-col'; card.onclick = function() { openModal(product); }; const imgSrc = product.image || 'http://static.photos/food/640x360/1'; const brandName = product.brandDisplay || product.brand || 'Brand'; const badgeColor = getBrandColor(product.brand); card.innerHTML = '
' + '' + escapeHtml(product.name || '') + '' + '' + escapeHtml(brandName) + '' + '
' + '
' + '

' + escapeHtml(product.name || '') + '

' + '

' + escapeHtml(product.category || '') + '

' + '

' + escapeHtml(product.description || '') + '

' + '
' + 'View Details' + '' + '
' + '
'; productGrid.appendChild(card); }); // Re-render icons for newly added content if (typeof lucide !== 'undefined' && lucide.createIcons) { lucide.createIcons(); } } function getCurrentFilter() { const activeBtn = document.querySelector('.filter-btn.active'); return activeBtn ? (activeBtn.dataset.filter || 'all') : 'all'; } function filterAndRender(searchTerm, filterBrand) { let filtered = products.filter(function(p) { if (!p) return false; const matchesSearch = !searchTerm || ((p.name || '').toLowerCase().includes(searchTerm)) || ((p.description || '').toLowerCase().includes(searchTerm)) || ((p.category || '').toLowerCase().includes(searchTerm)); const matchesBrand = !filterBrand || filterBrand === 'all' || p.brand === filterBrand; return matchesSearch && matchesBrand; }); renderProducts(filtered); } /* ========================================================= MODAL ========================================================= */ function openModal(product) { if (!product || !modal || !modalContent) return; const safeProduct = product || {}; if (modalImage) { modalImage.src = safeProduct.image || ''; modalImage.alt = safeProduct.name || 'Product'; } if (modalTitle) modalTitle.textContent = safeProduct.name || ''; if (modalDesc) modalDesc.textContent = safeProduct.description || ''; if (modalBrand) { modalBrand.textContent = (safeProduct.brandDisplay || safeProduct.brand || '').toUpperCase(); modalBrand.className = 'absolute top-4 left-4 px-3 py-1 bg-white/90 backdrop-blur rounded-full text-xs font-bold uppercase tracking-wide shadow-sm ' + getBrandTextColor(safeProduct.brand); } if (modalMfg) modalMfg.textContent = safeProduct.mfg || safeProduct.brandDisplay || ''; if (modalCategory) modalCategory.textContent = safeProduct.category || ''; if (modalSource) { modalSource.href = safeProduct.source || brandSources[safeProduct.brand] || '#'; } modal.classList.remove('hidden'); // Small delay to allow display:block to apply before adding opacity class requestAnimationFrame(function() { if (modalContent) modalContent.classList.add('active'); }); document.body.style.overflow = 'hidden'; } function closeModal() { if (!modal || !modalContent) return; modalContent.classList.remove('active'); setTimeout(function() { modal.classList.add('hidden'); document.body.style.overflow = ''; }, 300); } /* ========================================================= UTILITIES ========================================================= */ function getBrandColor(brand) { const colors = { annapurna: 'bg-amber-500', nuttygritties: 'bg-emerald-600', roastytasty: 'bg-rose-500' }; return colors[brand] || 'bg-gray-600'; } function getBrandTextColor(brand) { const colors = { annapurna: 'text-amber-600', nuttygritties: 'text-emerald-600', roastytasty: 'text-rose-600' }; return colors[brand] || 'text-gray-600'; } function escapeHtml(text) { if (text === null || text === undefined) return ''; const str = String(text); const div = document.createElement('div'); div.textContent = str; return div.innerHTML; } /* ========================================================= PDF / CATALOGUE SETUP --------------------------------------------------------- To enable the embedded PDF viewer: 1. Upload your PDF to the same folder as this site. 2. Update the iframe src in index.html OR rename file to Nsured_Catalogue.pdf. ========================================================= */