1document.addEventListener("DOMContentLoaded", function(event) { 2 algoliaBundle.$(function ($) { 3 4 /** We have nothing to do here if autocomplete is disabled **/ 5 if (!algoliaConfig.autocomplete.enabled) { 6 return; 7 } 8 9 /** 10 * Set autocomplete templates 11 * For templating is used Hogan library 12 * Docs: http://twitter.github.io/hogan.js/ 13 **/ 14 algoliaConfig.autocomplete.templates = { 15 suggestions: algoliaBundle.Hogan.compile($('#autocomplete_suggestions_template').html()), 16 products: algoliaBundle.Hogan.compile($('#autocomplete_products_template').html()), 17 universes: algoliaBundle.Hogan.compile($('#autocomplete_universes_template').html()),//Ajout de la section Univers 18 categories: algoliaBundle.Hogan.compile($('#autocomplete_categories_template').html()), 19 pages: algoliaBundle.Hogan.compile($('#autocomplete_pages_template').html()), 20 additionnalSection: algoliaBundle.Hogan.compile($('#autocomplete_extra_template').html()) 21 }; 22 23 /** 24 * Initialise Algolia client 25 * Docs: https://www.algolia.com/doc/javascript 26 **/ 27 var algolia_client = algoliaBundle.algoliasearch(algoliaConfig.applicationId, algoliaConfig.autocomplete.apiKey); 28 algolia_client.addAlgoliaAgent('Magento integration (' + algoliaConfig.extensionVersion + ')'); 29 30 /** Add autocomplete menu sections **/ 31 if (algoliaConfig.autocomplete.nbOfProductsSuggestions > 0) { 32 algoliaConfig.autocomplete.sections.unshift({ hitsPerPage: algoliaConfig.autocomplete.nbOfProductsSuggestions, label: algoliaConfig.translations.products, name: "products"}); 33 } 34 //Ajout section Univers 35 if (algoliaConfig.autocomplete.nbOfUniversesSuggestions > 0) { 36 algoliaConfig.autocomplete.sections.unshift({ hitsPerPage: algoliaConfig.autocomplete.nbOfUniversesSuggestions, label: algoliaConfig.translations.universes, name: "universes"}); 37 } 38 39 if (algoliaConfig.autocomplete.nbOfCategoriesSuggestions > 0) { 40 algoliaConfig.autocomplete.sections.unshift({ hitsPerPage: algoliaConfig.autocomplete.nbOfCategoriesSuggestions, label: algoliaConfig.translations.magazines, name: "categories"}); 41 } 42 43 if (algoliaConfig.autocomplete.nbOfQueriesSuggestions > 0) { 44 algoliaConfig.autocomplete.sections.unshift({ hitsPerPage: algoliaConfig.autocomplete.nbOfQueriesSuggestions, label: '', name: "suggestions"}); 45 } 46 47 /** Setup autocomplete data sources **/ 48 var sources = [], 49 i = 0; 50 $.each(algoliaConfig.autocomplete.sections, function (name, section) { 51 var source = getAutocompleteSource(section, algolia_client, $, i); 52 53 if (source) { 54 sources.push(source); 55 } 56 57 /** Those sections have already specific placeholder, so do not use the default aa-dataset-{i} class **/ 58 if (section.name !== 'suggestions' && section.name !== 'products') { 59 i++; 60 } 61 }); 62 63 /** 64 * ADD YOUR CUSTOM DATA SOURCE HERE 65 **/ 66 67 /** 68 * Setup the autocomplete search input 69 * For autocomplete feature is used Algolia's autocomplete.js library 70 * Docs: https://github.com/algolia/autocomplete.js 71 **/ 72 $(algoliaConfig.autocomplete.selector).each(function (i) { 73 var menu = $(this); 74 var options = { 75 hint: false, 76 templates: { 77 dropdownMenu: '#menu-template' 78 }, 79 dropdownMenuContainer: "#algolia-autocomplete-container", 80 debug: algoliaConfig.autocomplete.isDebugEnabled 81 }; 82 83 if (isMobile() === true) { 84 // Set debug to true, to be able to remove keyboard and be able to scroll in autocomplete menu 85 options.debug = true; 86 } 87 88 if (algoliaConfig.removeBranding === false) { 89 options.templates.footer = '<div class="footer_algolia"><a href="https://www.algolia.com/?utm_source=magento&utm_medium=link&utm_campaign=magento_autocompletion_menu" title="Search by Algolia" target="_blank"><img src="' +algoliaConfig.urls.logo + '" alt="Search by Algolia" /></a></div>'; 90 } 91
92 if (typeof algoliaHookBeforeAutocompleteStart === 'function') { 93 var hookResult = algoliaHookBeforeAutocompleteStart(sources, options, algolia_client); 94 95 sources = hookResult.shift(); 96 options = hookResult.shift(); 97 } 98 99 /** Bind autocomplete feature to the input */ 100 $(this) 101 .autocomplete(options, sources) 102 .parent() 103 .attr('id', 'algolia-autocomplete-tt') 104 .on('autocomplete:updated', function (e) { 105 fixAutocompleteCssSticky(menu); 106 }) 107 .on('autocomplete:updated', function (e) { 108 fixAutocompleteCssHeight(menu); 109 }).on('autocomplete:selected', function (e, suggestion, dataset) { 110 location.assign(suggestion.url); 111 }); 112 113 $(window).resize(function () { 114 fixAutocompleteCssSticky(menu); 115 }); 116 117 // Hack to handle buggy onclick event on iOS 118 $(algoliaConfig.autocomplete.selector).each(function () { 119 var data = $(this).data('aaAutocomplete'); 120 var dropdown = data.dropdown; 121 var suggestionClass = '.' + dropdown.cssClasses.prefix + dropdown.cssClasses.suggestion; 122 123 dropdown.$menu.on('touchstart', suggestionClass, function(e) { 124 e.preventDefault(); 125 e.stopPropagation(); 126 127 var url = $(this).find('a').attr('href'); 128 location.assign(url); 129 }); 130 }); 131 }); 132 }); 133});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.