Spaces:
Running
Running
File size: 16,238 Bytes
f09587d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 | /* =========================================================
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 =
'<div class="relative overflow-hidden h-48 sm:h-56 flex-shrink-0">' +
'<img src="' + imgSrc + '" alt="' + escapeHtml(product.name || '') + '" class="w-full h-full object-cover group-hover:scale-110 transition-transform duration-500">' +
'<span class="absolute top-3 left-3 px-3 py-1 rounded-full text-xs font-bold text-white ' + badgeColor + ' shadow-md">' + escapeHtml(brandName) + '</span>' +
'</div>' +
'<div class="p-5 flex flex-col flex-grow">' +
'<h3 class="font-bold text-gray-900 text-lg mb-1 leading-snug">' + escapeHtml(product.name || '') + '</h3>' +
'<p class="text-xs text-gray-500 mb-3 font-medium uppercase tracking-wide">' + escapeHtml(product.category || '') + '</p>' +
'<p class="text-gray-600 text-sm line-clamp-2 mb-4 flex-grow">' + escapeHtml(product.description || '') + '</p>' +
'<div class="flex items-center text-emerald-600 font-semibold text-sm mt-auto pt-3 border-t border-gray-100">' +
'<span>View Details</span>' +
'<i data-lucide="arrow-right" class="w-4 h-4 ml-2 group-hover:translate-x-1 transition-transform"></i>' +
'</div>' +
'</div>';
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.
========================================================= */ |