var client = algoliasearch(algoliaApplicationID, algoliaApiKey); const formatter_date_filter = new Intl.DateTimeFormat(lang, { day: '2-digit', month: 'long', year: 'numeric' }); const formatter_date_hit = new Intl.DateTimeFormat(lang, { weekday: 'long', day: '2-digit', month: 'long', year: 'numeric' }); const allowed_exhibitor_attributes = ['brand', 'exhibitor', 'sector', 'sectorClass', 'top_position', 'focus', 'is_new', 'hall', 'stands', 'image']; const allowed_participant_attributes = ['objectID', 'brand', 'image', 'quartier_fr', 'quartier_en']; const allowed_conference_attributes = ['title_fr','title_en','page_url_fr', 'conference_space','page_url_en', 'speaker_image_url','speakers', 'hall', 'partners', 'date', 'start_time', 'end_time']; function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } function eraseCookie(name) { createCookie(name,"",-1); } function shuffle(arra1) { var ctr = arra1.length, temp, index; // While there are elements in the array while (ctr > 0) { // Pick a random index index = Math.floor(Math.random() * ctr); // Decrease ctr by 1 ctr--; // And swap the last element with it temp = arra1[ctr]; arra1[ctr] = arra1[index]; arra1[index] = temp; } return arra1; } function searchBoxFunc(container) { return instantsearch.widgets.searchBox({ container: container }); } function initSlider(container, content, template, favoriName) { if (content != null && content.nbHits > 0) { $(container).append(template); $.each(shuffle(content.hits).slice(0, 50), function(key, hit) { hit.sectorClass = (hit.sector != null) ? hit.sector.toLowerCase().replace(/ & | /gi, '-') : ''; hit.brand.ficheUrl = listeExposantUrl + '/' + hit.brand.slug; attributes = JSON.stringify(objectFiltered(hit, allowed_exhibitor_attributes)).replace(/"/g, """).replace(/'/g, "'"); $(container+' #resultatsFiltres').append('
' + '
' + '
'+hit.sector+(hit.is_new ? 'New' : '')+'
' + (hit.top_position ? '
Top position
' : '')+ (hit.focus ? '
Focus Produit
' : '')+ "
" + '
' + '' + '' + '
' + '
' + (hit.image != null ? '' : '') + '
' + '
' + '

' + hit.brand.name + '

' + '

' + hit.exhibitor['country_'+lang]+'

' + '

' + (hit.hall ? 'Hall ' + hit.hall : '') + (hit.stands ? ' - Stand ' + hit.stands : '')+'

' + '
' + '
' + ''+translate('Ajouter aux favoris')+'' + ''+translate('Voir les favoris')+'' + '
' + '
'); }); $('.bandeauFavoris').fadeOut(0); if(window.innerWidth>993){ if(window.innerWidth>1439){ $(container+' .variable-width-3').slick({ dots: false, infinite: false, speed: 300, slidesToShow: 2, centerMode: false, variableWidth: true }); }else{ $(container+' .variable-width-3').slick({ dots: false, infinite: false, speed: 300, slidesToShow: 2, centerMode: false, variableWidth: true }); } }else{ $(container+' .variable-width-3').slick({ dots: false, infinite: false, speed: 300, slidesToShow: 1, centerMode: false, variableWidth: true }); } } } function initSliderPwd(container, content, template, favoriName) { if (content != null && content.nbHits > 0) { $(container).append(template); $.each(shuffle(content.hits).slice(0, 50), function(key, hit) { hit.brand.ficheUrl = listeExposantPdwUrl + '/' + hit.brand.slug; attributes = JSON.stringify(objectFiltered(hit, allowed_participant_attributes)).replace(/"/g, """).replace(/'/g, "'"); $(container+' #resultatsFiltres').append('
' + '
' + (hit.featured ? '' : '')+ "
" + '
' + ''+ '' + '
' + '
' + (hit.image != null ? '' : '') + '
' + '
' + '

' + hit.brand.name + '

' + '

' + hit['quartier_'+lang]+'

' + '
' + '
' + ''+translate('Ajouter aux favoris')+'' + ''+translate('Voir les favoris')+'' + '
' + '
'); }); $('.bandeauFavoris').fadeOut(0); if(window.innerWidth>993){ if(window.innerWidth>1439){ $(container+' .variable-width-3').slick({ dots: false, infinite: false, speed: 300, slidesToShow: 2, centerMode: false, variableWidth: true }); }else{ $(container+' .variable-width-3').slick({ dots: false, infinite: false, speed: 300, slidesToShow: 2, centerMode: false, variableWidth: true }); } }else{ $(container+' .variable-width-3').slick({ dots: false, infinite: false, speed: 300, slidesToShow: 1, centerMode: false, variableWidth: true }); } } } //pagination const renderPagination = function(renderOptions, isFirstRender) { const pages = renderOptions.pages; const currentRefinement = renderOptions.currentRefinement; const nbHits = renderOptions.nbHits; const nbPages = renderOptions.nbPages; const isFirstPage = renderOptions.isFirstPage; const isLastPage = renderOptions.isLastPage; const refine = renderOptions.refine; const createURL = renderOptions.createURL; const container = document.querySelector('#pagination'); if (nbHits === 0) { container.innerHTML = '' } else { container.innerHTML = ''; } $('#pagination a').each(function() { $(this).on('click', function(event) { event.preventDefault(); refine(event.currentTarget.dataset.value); }); }); }; $(document).ready(function() { $(document).favorites(); $('.bandeauFavoris').fadeOut(); if ($('#searchboxMobNav').length > 0 && $('#autocompleteMobNav').length > 0) { const search_engine_nav = instantsearch({ indexName: 'InsertionProduct', searchClient: client }); const configuration_engine_nav = instantsearch.widgets.configure({ hitsPerPage: 10, distinct: true}); const renderAutocompleteHeader = function(renderOptions, isFirstRender) { const indices = renderOptions.indices; var exhibitors = []; var products = []; for (var item in indices) { exhibitors = $.grep(indices[item].hits, function (i,n){ return i._tags.indexOf('insertion') > -1; }); products = $.grep(indices[item].hits, function (i,n){ return i._tags.indexOf('product') > -1; }); } var container_id = renderOptions.widgetParams.container.id; document.querySelector('#'+container_id).innerHTML = '' + ''; } const searchBoxMobNav = searchBoxFunc('#searchboxMobNav'); const customAutocompleteNav = instantsearch.connectors.connectAutocomplete(renderAutocompleteHeader); search_engine_nav.addWidgets([ configuration_engine_nav, customAutocompleteNav({ container: document.querySelector('#autocompleteMobNav'), }), searchBoxMobNav ]); search_engine_nav.start(); $("header .search-button").click(function() { $('header input.search-box').val($(this).parent().find('input.search-box').val()); search_engine_nav.helper.setQuery($(this).parent().find('input.search-box').val()).search(); }); $("header #searchResult .search-input").keyup(function() { $('header input.search-box').val($(this).val()); search_engine_nav.helper.setQuery($(this).val()).search(); }); var insertionProductIndex = client.initIndex('InsertionProduct'); insertionProductIndex.search({ facets: ['h_categories.'+lang+'.0', 'sector', 'label_'+lang] }).then(function(res) { $.each(res.facets, function(facet, datas) { switch (facet) { case 'h_categories.'+lang+'.0': $('#categoriesMob').empty(); $('#categories').empty(); $.each(datas, function(data, count) { $('#categoriesMob').append('
  • '+data+'
  • '); $('#categories').append('
  • '+data+'
  • '); }); break; case 'sector': $('#sectorsMob').empty(); $('#sectors').empty(); $.each(datas, function(data, count) { $('#sectorsMob').append('
  • '+data+'
  • '); $('#sectors').append('
  • '+data+'
  • '); }); break; case 'label_'+lang: $('#labelsMob').empty(); $('#labels').empty(); $.each(datas, function(data, count) { $('#labelsMob').append('
  • '+data+'
  • '); $('#labels').append('
  • '+data+'
  • '); }); break; default: } }); }); } $(document).on('change', ".favori input, .favori2 input", function() { if ($(this).prop("checked") == true){ id= $(this).attr('id'); $('.bandeau'+id).fadeIn(); } else{ $('.bandeauFavoris').fadeOut(0); } }); $(document).on('mouseleave', '.encart', function() { $(this).find('.bandeauFavoris').fadeOut(0); }); $(document).on('mouseleave', '.bandeauGen', function() { $(this).fadeOut(0); }); }); function clearRefinement(container) { return instantsearch.widgets.clearRefinements({ container: container, templates: { resetLabel: translate('Effacer tous les filtres'), } }); } function objectFiltered(raw, allowed) { return Object.keys(raw) .filter(function(key) { return (allowed.indexOf(key) != -1); } ) .reduce(function (obj, key) { obj[key] = raw[key]; return obj; }, {}); }