'use strict'; /* global instantsearch */ var subDomain = $("#hfSubDomainName").val(); //set subdomain value var searchString = $("#hfQuery").val(); // Set search query var categoryQuery = $("#hfCategoryQuery").val(); // Set category path var filterStyle = $("#hfFilterStyle").val(); var indexName = 'prod_Catalog'; var search = instantsearch({ appId: 'U3IS7YI5TB', apiKey: 'c4c4b1e3c773d5b72eee525967d46712', indexName: indexName, searchParameters: { facets: ['UserName', 'IsEnabled', 'SumStock'], hierarchicalFacetsRefinements: { // menu is implemented as a hierarchicalFacetsRefinements 'Category': ['' + categoryQuery + ''] }, attributesToHighlight: ["Category"] } }); /*** Widget to Search Control **/ if ($("#uxSearchText").length > 0) { search.addWidget( instantsearch.widgets.searchBox({ container: '#uxSearchText', placeholder: 'Search a product', }) ); } /*** Widget to Show Record Count **/ search.addWidget( instantsearch.widgets.stats({ container: '#stats', templates: { body: function (data) { return data.nbHits + ' results found' } } }) ); search.on('render', function () { $('.product-picture img').addClass('transparent'); $('.product-picture img').one('load', function () { $(this).removeClass('transparent'); }).each(function () { if (this.complete) $(this).load(); }); }); var hitTemplate = document.getElementById('product') !== null ? document.getElementById('product').innerHTML : ""; // Html to bind product list data var noResultsTemplate = '
No results found matching {{query}}.
'; //Template if no result fount var menuTemplate = ' {{name}}'; //Template for category control //*** Not using right now. But Can Used for other control with checkbox filter ******// var facetTemplateTopCategoryCheckbox = // '' + '
  • ' + '({{count}})
  • '; // '
    '; //*** Using this template for top filters **// var i = 0; var facetTemplateCheckbox = '
    '; //*** Template for color filter ***// var facetTemplateColors = '
  • {{name}}
  • '; //'; var mobileCategory = ' {{name}} ({{count}})'; //*** Widget to bind all product data ***// if ($("#hits").length > 0) { search.addWidget( instantsearch.widgets.hits({ container: '#hits', hitsPerPage: 100, templates: { empty: noResultsTemplate, item: hitTemplate }, transformData: function (hit) { hit.stars = []; for (var i = 1; i <= 5; ++i) { hit.stars.push(i <= hit.Rating); } return hit; } }) ); } if ($("#categories").length > 0) { // Condition to check if category display setting is not OFF from admin search.addWidget( instantsearch.widgets.hierarchicalMenu({ container: '#categories', attributes: ['Category', 'Sub_Category', 'Sub_Sub_Category'], sortBy: ['name:asc'], templates: { item: menuTemplate //header: '
    Categories
    ' }, limit: 50 }) ); } //** Widget to bind color filters ***// if ($("#colorAlgoliaMobile").length > 0) { // Condition to check if left panel display setting is not OFF from admin search.addWidget( instantsearch.widgets.refinementList({ container: '#colorAlgoliaMobile', attributeName: 'Color', operator: 'or', limit: 10, templates: { item: facetTemplateColors } }) ); } //** Widget to bind price filter ***// if ($("#priceAlgoliaMobile").length > 0) { search.addWidget( instantsearch.widgets.priceRanges({ container: '#priceAlgoliaMobile', attributeName: 'Price', cssClasses: { list: 'nav nav-list', count: 'badge pull-right', active: 'active' }, //templates: {} }) ); } //** Widget to bind sort filter ***// if ($("#sortByAlgoliaMobile1").length > 0) { // Condition to check if left panel display setting is not OFF from admin search.addWidget( instantsearch.widgets.sortBySelector({ container: '#sortByAlgoliaMobile1', indices: [ { name: indexName, label: 'Featured' }, { name: indexName + '_Name_Asc', label: 'Name Asc' }, { name: indexName + '_Name_Desc', label: 'Name Desc' }, { name: indexName + '_Price_Asc', label: 'Price - Low to High' }, { name: indexName + '_Price_Desc', label: 'Price - High to Low' } ], label: 'Sort By' }) ); } // setup initial filters search.addWidget({ init: function (options) { options.helper.toggleRefinement('UserName', subDomain); options.helper.toggleRefinement('IsEnabled', '1'); options.helper.addNumericRefinement('SumStock', '>', 0); options.helper.setQuery(searchString); }, render: function () { //*** Functions to Reset height of rightpanel after search or clear all updateHeight(); setTimeout(function () { setCatalogSectionHeight(); }, 500); GetCategoryHeading(); HideColorControl(); $(".ais-price-ranges--item").click(function () { $(".gs-oc-filter-dropdown").removeClass("show-filter"); }); $(".gs-btn-apply").click(function () { $(".gs-oc-filter-dropdown").removeClass("show-filter"); }); } }); //** Widget to bind clear all filter ***// if ($("#resetAll").length > 0) { search.addWidget( // Condition to check if left panel display setting is not OFF from admin instantsearch.widgets.clearAll({ container: '#resetAll', templates: { link: 'Reset' }, autoHideContainer: false, excludeAttributes: ["UserName", "IsEnabled", "Category", "SumStock"] }) ); } //** Widget to bind paging control ***// if ($("#pagination").length > 0) { search.addWidget( instantsearch.widgets.pagination({ container: '#pagination', cssClasses: { active: 'active' }, labels: { previous: ' Previous page', next: 'Next page ' }, maxPages: 20, showFirstLast: false }) ); //** Condition to check if paging is less than 1 page then hide paging control **// var container = document.querySelector('#pagination'); var paginationWidget = instantsearch.widgets.pagination({ container: '#pagination' }); var oldRender = paginationWidget.render; paginationWidget.render = function (params) { var currentState = params.results; if (currentState.nbPages <= 1) container.style.display = 'none'; else container.style.display = 'block'; } search.addWidget(paginationWidget); } //** Algolia Search Start **// search.start();