/** * blog-search.js - Logic for real-time article filtering and dropdown results * Updated to support unified site-wide searching (Blogs + Services/Abilities + Pages) */ // 1. Static site-wide Pages & Services (Abilities) Dataset const ADDITIONAL_SEARCH_DATA = [ // --- Services / Abilities --- { title: "Amazon Account Launch & Registration", excerpt: "Launch and register your Amazon seller account with professional setup and configuration.", type: "service", url: "../services/amazon-account-launch.php", tags: ["Amazon", "Launch", "Registration", "Onboarding"] }, { title: "Amazon Product Listing Services", excerpt: "Professional Amazon product listing and SEO optimization to improve visibility and sales.", type: "service", url: "../services/amazon-product-listing.php", tags: ["Amazon", "Listing", "SEO", "Optimization"] }, { title: "Amazon Brand & Product-Specific Videos", excerpt: "High-quality product and brand videos for Amazon listings to boost conversion rates.", type: "service", url: "../services/amazon-brand-product-videos.php", tags: ["Amazon", "Videos", "Brand", "Product Video"] }, { title: "A+ Content (Enhanced Brand Content)", excerpt: "Create beautiful Amazon A+ Content and premium product descriptions.", type: "service", url: "../services/aplus-content-services.php", tags: ["Amazon", "A+", "EBC", "Enhanced Brand Content"] }, { title: "Amazon Advertising (PPC) Services", excerpt: "Optimize and manage your Amazon Pay-Per-Click campaigns to maximize ROI.", type: "service", url: "../services/amazon-advertising-services.php", tags: ["Amazon", "PPC", "Advertising", "Ads"] }, { title: "Amazon Account Management", excerpt: "Full-service management for your Amazon store, including inventory, health, and growth.", type: "service", url: "../services/amazon-account-management.php", tags: ["Amazon", "Management", "Account Manager"] }, { title: "Amazon Account Reinstatement", excerpt: "Get your suspended Amazon seller account or listing reinstated quickly.", type: "service", url: "../services/amazon-account-reinstatement.php", tags: ["Amazon", "Reinstatement", "Suspended", "Appeals"] }, { title: "Flipkart Seller Services & Registration", excerpt: "Register and launch your store on Flipkart with professional setup.", type: "service", url: "../services/flipkart-seller-services.php", tags: ["Flipkart", "Launch", "Registration", "Onboarding"] }, { title: "Flipkart Account Management", excerpt: "End-to-end account management, performance monitoring, and growth strategies on Flipkart.", type: "service", url: "../services/flipkart-account-management.php", tags: ["Flipkart", "Management", "Account Manager"] }, { title: "Flipkart RPD (Return Pickup Dispute)", excerpt: "Manage and resolve return pickup disputes on Flipkart to save costs.", type: "service", url: "../services/flipkart-rpd-services.php", tags: ["Flipkart", "RPD", "Disputes", "Returns"] }, { title: "Flipkart Advertising Services", excerpt: "Professional Flipkart product advertising and campaigns to boost visibility.", type: "service", url: "../services/flipkart-advertising-services.php", tags: ["Flipkart", "Advertising", "PPC", "Ads"] }, { title: "JioMart Seller Services", excerpt: "Onboarding, product cataloging, and store optimization for JioMart sellers.", type: "service", url: "../services/jiomart-services.php", tags: ["JioMart", "Seller", "Onboarding"] }, { title: "Meesho Seller Services", excerpt: "Meesho seller registration, product uploads, listing optimization, and order management.", type: "service", url: "../services/meesho-services.php", tags: ["Meesho", "Seller", "Listing"] }, { title: "Myntra Seller Services", excerpt: "Grow your fashion brand on Myntra with cataloging and store management.", type: "service", url: "../services/Myntra-Seller-Services.php", tags: ["Myntra", "Seller", "Fashion", "Listing"] }, { title: "Ajio Seller Services", excerpt: "Get your brand registered and listed on Ajio with our specialized cataloging.", type: "service", url: "../services/Ajio-Seller-Services.php", tags: ["Ajio", "Seller", "Cataloging"] }, { title: "Nykaa Seller Services", excerpt: "Professional seller solutions, registration, and product listing on Nykaa.", type: "service", url: "../services/Nayaka-Seller-Services.php", tags: ["Nykaa", "Beauty", "Seller", "Listing"] }, { title: "Blinkit Seller Services", excerpt: "List and scale your fast-moving products on Blinkit quick commerce.", type: "service", url: "../services/Blinkit.php", tags: ["Blinkit", "Quick Commerce", "Q-Commerce", "Instant Delivery"] }, { title: "Zepto Seller Services", excerpt: "Get your products onboarding and managed on Zepto quick-delivery platform.", type: "service", url: "../services/Zepto.php", tags: ["Zepto", "Quick Commerce", "Q-Commerce", "Instant Delivery"] }, { title: "Swiggy Instamart Services", excerpt: "Onboard and optimize your catalog on Swiggy Instamart for instant sales.", type: "service", url: "../services/Instamart.php", tags: ["Instamart", "Swiggy", "Quick Commerce", "Q-Commerce"] }, { title: "BigBasket Seller Services", excerpt: "Professional cataloging and store management services for BigBasket.", type: "service", url: "../services/BigBasket.php", tags: ["BigBasket", "Grocery", "Seller"] }, { title: "Amazon Fresh Services", excerpt: "Expand your grocery business with Amazon Fresh listing and management.", type: "service", url: "../services/Amazon-now.php", tags: ["Amazon Fresh", "Grocery", "Seller", "Now"] }, { title: "Flipkart Minute Services", excerpt: "List and optimize your items on Flipkart Minute instant delivery service.", type: "service", url: "../services/Flipkart-Minute.php", tags: ["Flipkart Minute", "Quick Commerce", "Q-Commerce"] }, { title: "Cataloging Services", excerpt: "Professional cataloging, photoshoot, and listing services for top e-commerce websites.", type: "service", url: "../services/cataloging-services.php", tags: ["Cataloging", "Photoshoot", "Listing"] }, { title: "GST Registration & Compliance", excerpt: "Get new GST registration, legal filings, and complete e-commerce tax compliance.", type: "service", url: "../services/gst-registration-services.php", tags: ["GST", "Tax", "Legal", "Compliance", "Filing"] }, { title: "Company Registration & Incorporation", excerpt: "Incorporate Private Limited, LLP, One Person Company, or Partnership easily.", type: "service", url: "../services/company-registration-services.php", tags: ["Company", "Incorporation", "Legal", "Partnership", "LLP"] }, { title: "Trademark Registration & IP", excerpt: "Secure your brand name, logo, and intellectual property with trademark filing.", type: "service", url: "../services/trademark-registration-services.php", tags: ["Trademark", "Legal", "IP", "Brand", "Copyright"] }, { title: "FSSAI Registration & Food License", excerpt: "Obtain FSSAI food license for food-related e-commerce or retail operations.", type: "service", url: "../services/fssai-registration-services.php", tags: ["FSSAI", "Legal", "Food License", "Safety"] }, { title: "MSME Udyam Registration", excerpt: "Register your business as an MSME to access government benefits and subsidies.", type: "service", url: "../services/udyam-registration-services.php", tags: ["MSME", "Udyam", "Legal", "Registration", "Micro"] }, // --- Pages --- { title: "Home - Digitalsbooster", excerpt: "We provide e-commerce account management, cataloging, marketplace advertising, and legal registration services.", type: "page", url: "../index.php", tags: ["Home", "Digitalsbooster", "E-commerce", "Growth"] }, { title: "About Us - Who We Are", excerpt: "Learn about Digitalsbooster's mission, vision, and how we help brands scale across online marketplaces.", type: "page", url: "../company/about-us.php", tags: ["About Us", "Company", "Mission", "Vision"] }, { title: "Our Team", excerpt: "Meet our passionate team of e-commerce specialists, digital marketers, and legal compliance experts.", type: "page", url: "../company/our-team.php", tags: ["Team", "Company", "Experts", "Staff"] }, { title: "Frequently Asked Questions (FAQs)", excerpt: "Find quick answers regarding e-commerce onboarding, account management, legal compliance, and pricing.", type: "page", url: "../company/faqs.php", tags: ["FAQs", "Company", "Help", "Support", "Questions"] }, { title: "Clients & Partners", excerpt: "Discover the brands that have scaled their digital sales and reached millions of customers with Digitalsbooster.", type: "page", url: "../company/clients.php", tags: ["Clients", "Company", "Success Stories", "Partners", "Brands"] }, { title: "Careers at Digitalsbooster", excerpt: "Join a fast-growing, innovative team of e-commerce specialists and tech enthusiasts.", type: "page", url: "../company/career.php", tags: ["Career", "Company", "Jobs", "Hiring", "Work"] }, { title: "Contact Us", excerpt: "Get in touch with Digitalsbooster for a free consultation or custom quotes.", type: "page", url: "../contact-us.php", tags: ["Contact Us", "Help", "Talk", "Support", "Enquiry", "Email"] } ]; // Helper to determine depth and calculate prefix to Digitalsbooster root const getRelativePrefix = () => { const loc = window.location.pathname; if (loc.match(/\/blogs\/post/i)) { return '../../'; } if (loc.match(/\/(blogs|company|services)/i)) { return '../'; } return ''; }; // Compile dynamic blog posts + static services & pages const getCombinedDataset = (blogData) => { const blogs = (blogData || []).map(b => ({ ...b, type: 'blog' })); const prefix = getRelativePrefix(); const pagesAndServices = ADDITIONAL_SEARCH_DATA.map(item => ({ ...item, resolvedUrl: prefix + item.url.replace(/^\.\.\//, '') })); return [...blogs, ...pagesAndServices]; }; // 2. Core Data Helpers (Exposed for Dashboard reuse) window.BlogSearchHelpers = { getImgUrl: (path) => { if (!path) return '../assets/images/placeholder.png'; if (path.startsWith('http://') || path.startsWith('https:///')) return path; // If it's already resolved (starts with relative dots or matches correct folder structure), return as is if (path.startsWith('.') || path.includes('dashboard/index.html')) return path; // Otherwise, clean and resolve relative path prefix let cleanPath = path.replace(/^(\.\.\/)+/, '').replace(/^\//, ''); if (cleanPath.startsWith('dashboard/')) { cleanPath = 'blogs/' + cleanPath; } const prefix = getRelativePrefix(); return prefix + cleanPath; }, parseTags: (tagData) => { if (!tagData) return []; try { if (typeof tagData === 'string' && tagData.startsWith('[')) return JSON.parse(tagData); if (typeof tagData === 'string') return tagData.split(',').map(t => t.trim()).filter(t => t !== ''); if (Array.isArray(tagData)) return tagData; } catch (e) { console.error("Error parsing tags:", e); } return []; }, // Unified filter logic covering title, excerpt, full body/content, tags, and authors filterData: (data, searchTerm) => { if (!searchTerm) return []; const term = searchTerm.toLowerCase().trim(); const unifiedDataset = getCombinedDataset(data); return unifiedDataset.filter(item => { if (!item) return false; const titleMatch = (item.title || '').toString().toLowerCase().includes(term); const excerptMatch = (item.excerpt || '').toString().toLowerCase().includes(term); const contentMatch = (item.content || item.body || '').toString().toLowerCase().includes(term); const authorMatch = (item.author_name || item.author || '').toString().toLowerCase().includes(term); const tags = window.BlogSearchHelpers.parseTags(item.tags || item.category); const tagMatch = tags.some(tag => tag && tag.toString().toLowerCase().includes(term)); return titleMatch || excerptMatch || contentMatch || authorMatch || tagMatch; }); } }; document.addEventListener('DOMContentLoaded', () => { // Initialize Search Instances const setupSearch = (inputId, dropdownId, blogsOnly = false) => { const input = document.getElementById(inputId); const dropdown = document.getElementById(dropdownId); if (!input || !dropdown) return; input.addEventListener('input', (e) => { const searchTerm = e.target.value; const data = window.BLOG_DATA || (typeof BLOG_DATA !== 'undefined' ? BLOG_DATA : []); console.log("Search term:", searchTerm); console.log("Data source (window.BLOG_DATA):", data); if (searchTerm.trim().length < 1) { dropdown.innerHTML = ''; dropdown.style.display = 'none'; return; } let filteredResults = window.BlogSearchHelpers.filterData(data, searchTerm); if (blogsOnly) { filteredResults = filteredResults.filter(item => item.type === 'blog'); } console.log("Filtered results matching query:", filteredResults); renderDropdown(filteredResults, dropdown); }); input.addEventListener('click', () => { if (input.value.length >= 1 && dropdown.innerHTML !== '') { dropdown.style.display = 'block'; } }); // Close dropdown when clicking outside specific instance document.addEventListener('click', (e) => { if (!input.contains(e.target) && !dropdown.contains(e.target)) { dropdown.style.display = 'none'; } }); }; const renderDropdown = (results, dropdown) => { if (results.length === 0) { dropdown.innerHTML = '
No results found matching your search.
'; } else { const prefix = getRelativePrefix(); dropdown.innerHTML = results.map(post => { let postUrl = ''; if (post.type === 'blog') { if (prefix === '../index.html') { postUrl = `index.php?post=${post.slug || post.id}`; } else if (prefix === '../') { postUrl = `post/index.php?post=${post.slug || post.id}`; } else { postUrl = `blogs/post/index.php?post=${post.slug || post.id}`; } } else { postUrl = post.resolvedUrl; } const tags = window.BlogSearchHelpers.parseTags(post.tags || post.category); const displayTag = tags.length > 0 ? tags[0] : (post.type === 'service' ? 'Service' : 'Page'); // Determine icon or image to show let imgHtml = ''; if (post.type === 'blog') { const img = window.BlogSearchHelpers.getImgUrl(post.featured_image || post.imageURL); imgHtml = `${post.title}`; } else if (post.type === 'service') { imgHtml = `
`; } else { imgHtml = `
`; } const author = post.type === 'blog' ? (post.author_name || post.author || 'Digitalsbooster') : 'Digitalsbooster'; const metaText = post.type === 'blog' ? `By ${author} • ${displayTag}` : `${post.type.charAt(0).toUpperCase() + post.type.slice(1)} • ${displayTag}`; return `
${imgHtml}
${post.title}
${metaText}
`; }).join(''); } dropdown.style.display = 'block'; }; // Initialize Hero Search (Blogs Page) setupSearch('blog-search-input', 'blog-search-results', true); // Initialize Header Search (Global - Desktop & Mobile) setupSearch('header-search-input-desktop', 'header-search-results-desktop'); setupSearch('header-search-input-mobile', 'header-search-results-mobile'); // 4. Dynamic Placeholder Animation const initPlaceholderAnimation = () => { const desktopInput = document.getElementById('header-search-input-desktop'); const mobileInput = document.getElementById('header-search-input-mobile'); const inputs = [desktopInput, mobileInput].filter(input => input !== null); if (inputs.length === 0) return; const placeholders = ["articles...", "authors...", "tags..."]; let currentIdx = 0; let charIdx = 0; let isDeleting = false; let typingSpeed = 100; const type = () => { const currentFull = "Search by " + placeholders[currentIdx]; if (isDeleting) { charIdx--; typingSpeed = 50; } else { charIdx++; typingSpeed = 100; } const text = currentFull.substring(0, charIdx); inputs.forEach(input => { if (input.value === "") { input.placeholder = text; } }); if (!isDeleting && charIdx === currentFull.length) { isDeleting = true; typingSpeed = 2000; // Pause at the end } else if (isDeleting && charIdx === 0) { isDeleting = false; currentIdx = (currentIdx + 1) % placeholders.length; typingSpeed = 500; } setTimeout(type, typingSpeed); }; type(); }; initPlaceholderAnimation(); // 3. Mobile Search Toggle Logic const mobToggle = document.getElementById('mobile-search-toggle'); const mobClose = document.getElementById('mobile-search-close'); const mobSearchBox = document.getElementById('mobile-search-box'); const mobInput = document.getElementById('header-search-input-mobile'); if (mobToggle && mobSearchBox) { mobToggle.addEventListener('click', (e) => { e.stopPropagation(); const isVisible = mobSearchBox.style.display === 'block'; mobSearchBox.style.display = isVisible ? 'none' : 'block'; if (!isVisible) { setTimeout(() => mobInput && mobInput.focus(), 100); } }); } if (mobClose && mobSearchBox) { mobClose.addEventListener('click', (e) => { e.stopPropagation(); mobSearchBox.style.display = 'none'; }); } // Close mobile search if clicking outside document.addEventListener('click', (e) => { if (mobSearchBox && mobSearchBox.style.display === 'block') { const wrapper = document.getElementById('header-search-wrapper-mobile'); if (wrapper && !wrapper.contains(e.target) && !mobToggle.contains(e.target)) { mobSearchBox.style.display = 'none'; } } }); // Close on Escape key document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && mobSearchBox && mobSearchBox.style.display === 'block') { mobSearchBox.style.display = 'none'; } }); });