/* global instantsearch: true */ /*jshint camelcase: false */ $(document).ready(function () { var algoliaSettings = CONFIG.algolia; var isAlgoliaSettingsValid = algoliaSettings.applicationID && algoliaSettings.apiKey && algoliaSettings.indexName; if (!isAlgoliaSettingsValid) { window.console.error('Algolia Settings are invalid.'); return; } var search = instantsearch({ appId: algoliaSettings.applicationID, apiKey: algoliaSettings.apiKey, indexName: algoliaSettings.indexName, searchFunction: function (helper) { var searchInput = $('#algolia-search-input').find('input'); if (searchInput.val()) { helper.search(); } } }); // Registering Widgets [ instantsearch.widgets.searchBox({ container: '#algolia-search-input', placeholder: algoliaSettings.labels.input_placeholder }), instantsearch.widgets.hits({ container: '#algolia-hits', hitsPerPage: algoliaSettings.hits.per_page || 10, templates: { item: function (data) { var link = data.permalink ? data.permalink : (CONFIG.root + data.path); return ( '' + data._highlightResult.title.value + '' ); }, empty: function (data) { return ( '
' + algoliaSettings.labels.hits_empty.replace(/\$\{query}/, data.query) + '
' ); } }, cssClasses: { item: 'algolia-hit-item' } }), instantsearch.widgets.stats({ container: '#algolia-stats', templates: { body: function (data) { var stats = algoliaSettings.labels.hits_stats .replace(/\$\{hits}/, data.nbHits) .replace(/\$\{time}/, data.processingTimeMS); return ( stats + '' + ' Algolia' + '' + '
' ); } } }), instantsearch.widgets.pagination({ container: '#algolia-pagination', scrollTo: false, showFirstLast: false, labels: { first: '', last: '', previous: '', next: '' }, cssClasses: { root: 'pagination', item: 'pagination-item', link: 'page-number', active: 'current', disabled: 'disabled-item' } }) ].forEach(search.addWidget, search); search.start(); $('.popup-trigger').on('click', function(e) { e.stopPropagation(); $('body') .append('
') .css('overflow', 'hidden'); $('.popup').toggle(); $('#algolia-search-input').find('input').focus(); }); $('.popup-btn-close').click(function(){ $('.popup').hide(); $('.algolia-pop-overlay').remove(); $('body').css('overflow', ''); }); });