PageSourceSearch

https://www.viversum.fr/js/algolia.js?v=5ee9105172b228006667fa6aefd94648

js viversum.fr collected 2026-10-04 03:03:05 UTC 19,394 bytes, 534 lines download raw bytes

1(function ($) {
2    var hashKeyword = {};
3    $.getJSON('/algolia-keyword.json', function (arr) {
4        for (i = 0; i < arr.length; i++) {
5            hashKeyword[arr[i]['TITRE'].toUpperCase()] = arr[i]['SOURCE'];
6        }
7    });
8
9    //moteur de recherche
10    var client = algoliasearch('01ICHCG81B', 'a670b849c1897f2742d0de889c6e599d'),
11        kang_site = $('input[name=\'kang_site\']').val(),
12        is_voice_offer = kang_site != 'kangpro' ? true : false,
13        lastRequest = null,
14        lastKeywordValue = '',
15        voiceOfferHitsPerPage = is_voice_offer == true ? 2 : 0;
16
17    $(document).click(function (event) {
18        if (!$(event.target).is('.autocomplete, .autocomplete *, #search_input_home_2, #search_header, #keyword, #textfieldsearch')) {
19            $('.autocomplete').hide();
20        }
21    });
22
23    $('.result_page').on('click', 'a', function (event) {
24        event.stopPropagation();
25    });
26
27    function storeSearch(totalNbHits, keyword, element) {
28        var cat_id = '', parent_cat_id = '';
29        if (typeof element !== 'undefined') {
30            cat_id = element.attr('cat_id');
31            parent_cat_id = element.attr('parent_cat_id');
32        }
33        $.post('/ajax/on_search_result_click.js', {
34            totalNbHits: totalNbHits,
35            keyword: keyword,
36            cat_id: cat_id,
37            parent_cat_id: parent_cat_id,
38        }, function (result) {
39
40        });
41    }
42
43    $('body').on('click', '.autocomplete_result', function (event) {
44        event.preventDefault(event);
45
46        if (lastRequest !== null) {
47            var totalNbHits = lastRequest.results.reduce(
48                    function (carry, algoliaIndex) {
49                        return carry + algoliaIndex.nbHits;
50                    }, 0),
51                keyword = lastRequest.results[0].query;
52
53            storeSearch(totalNbHits, keyword, $(this));
54        }
55        // window.location.href = $(this).attr('href');
56    });
57
58    $('body').on('click', '.autocomplete_result a', function (event) {
59        event.preventDefault(event);
60        window.location.href = $(this).attr('href');
61    });
62
63    $('body').on('click', '.autocomplete_see_more_button', function (event) {
64        event.preventDefault(event);
65
66        let homepageSearchForm = $('#homepage_search_form');
67        let searchForm = $('#search_form');
68        if (homepageSearchForm) {
69            homepageSearchForm.submit();
70        } else if (searchForm){
71            searchForm.submit();
72        }
73    });
74
75    $('body').on('click', '.search_input_cross', function (event) {
76        $(this).prev('input').val('');
77        $(this).hide();
78    });
79
80    let currentLocalSearchRequest = null;
81    let localSearchTimeout = null;
82
83    $('body').on('input click', '#search_input_home_2, #search_header, #keyword, #textfieldsearch, #mobile_textfieldsearch',
84        function () {
85            lastKeywordValue = $(this).val();
86            window.lastSearch = $(this).val();
87            let isLocalSearch = /^\d/.test(lastKeywordValue);
88
89            if ($(this).val() === '') {
90                $('.autocomplete').remove();
91                $(this).next('.search_input_cross').hide();
92
93                if ($('.categories_badges_container.home').length && !$('.categories_badges_container.category').length) {
94                    $('.categories_badges_container.home').show();
95                }
96            } else {
97                if ($('.categories_badges_container.home').length && !$('.categories_badges_container.category').length) {
98                    $('.categories_badges_container.home').hide();
99                }
100                $(this).next('.search_input_cross').show();
101                if ($('.autocomplete').length && $('.autocomplete').css('display') == 'none') {
102                    $('.autocomplete').show();
103                } else if (!isLocalSearch) {
104                    searchByQueries(client, $(this).val(), addAutocomplete);
105                } else {
106                    let localSearchValue = $(this).val().trim();
107
108                    if (currentLocalSearchRequest) {
109                        currentLocalSearchRequest.abort();
110                    }
111
112                    if (localSearchTimeout) {
113                        clearTimeout(localSearchTimeout);
114                    }
115
116                    if (localSearchValue !== '' && window.globalVue) {
117                        localSearchTimeout = setTimeout(() => {
118                            currentLocalSearchRequest = $.ajax({
119                                url: window.globalVue.ziggy_route('offer.search-by-offer-code'),
120                                method: 'POST',
121                                data: {
122                                    query: localSearchValue,
123                                },
124                                success: function (response) {
125                                    if (response.length === 0) {
126                                        $('.autocomplete').hide();
127                                        return false;
128                                    }
129
130                                    response.forEach((offer) => {
131                                        offer._highlightResult = {
132                                            cat_name: {value: offer.cat_name},
133                                            first_name: {value: offer.first_name},
134                                            last_name: {value: offer.last_name},
135                                            offer_code: {value: highlightText(offer.offer_code.toString(), localSearchValue)},
136                                        };
137                                    });
138
139                                    addAutocomplete(null, {results: [{hits: response}]});
140                                }
141                            });
142                        }, 300);
143                    } else {
144                        $('.autocomplete').hide();
145                    }
146                }
147            }
148        }
149    );
150
151    function highlightText(text, highlight) {
152        if (!highlight) return text;
153        const regex = new RegExp(`^(${highlight})`, 'i');
154        return text.replace(regex, '<strong>$1</strong>');
155    }
156
157    function searchLocal(value) {
158        var localSearches = window.localSearches,
159            localSearchLength = localSearches.length,
160            levenshteinDistance, results = [];
161
162        for (var i = 0; i < localSearchLength; i++) {
163            levenshteinDistance = getEditDistance(localSearches[i].to_search, value);
164
165            if (levenshteinDistance <= 2) {
166                results.push(localSearches[i]);
167            }
168        }
169
170        var resultsLength = results.length, html = '';
171
172        for (i = 0; i < resultsLength; i++) {
173            if (is_voice_offer) {
174                html += constructCategory(results[i].url, results[i].name, ('autocomplete_voice_category'));
175            }
176        }
177
178        $('.autocomplete_category_list').append(html);
179
180        $('.autocomplete_category_list').each(function (index) {
181            var seen = {};
182            $(this).find('.autocomplete_category').each(function () {
183                var txt = $(this).text() + $(this).attr('href');
184                if (seen[txt]) {
185                    $(this).remove();
186                } else {
187                    seen[txt] = true;
188                }
189            });
190        });
191    }
192
193    function removeAutocomplete() {
194        var autocomplete = $('.autocomplete');
195        if (autocomplete.length) {
196            autocomplete.remove();
197        }
198    }
199
200    function getServiceId() {
201        var serviceId = 287;
202
203        if (typeof window.serviceId !== 'undefined') {
204            serviceId = window.serviceId;
205        }
206
207        return serviceId;
208    }
209
210    function getPageType() {
211        var pageType = 'home';
212
213        if (typeof window.serviceId !== 'undefined') {
214            pageType = window.pageType;
215        }
216
217        return pageType;
218    }
219
220    function getDivToAppendAutocomplete() {
221        return $('.autocomplete_container');
222    }
223
224    function addAutocomplete(error, content) {
225        removeAutocomplete();
226
227        var serviceId = getServiceId();
228
229        var totalNbHits = content.results.reduce(function (carry, algoliaIndex) {
230            return carry + algoliaIndex.nbHits;
231        }, 0), keyword = content.results[0].query;
232        if (totalNbHits == 0) {
233            storeSearch(totalNbHits, keyword);
234        } else {
235            var autoCompleteInput = getDivToAppendAutocomplete(),
236                autoCompleteHtml = $('#autocomplete_template').html();
237
238            var autoCompleteDiv = autoCompleteInput.append(autoCompleteHtml);
239
240            var categories = getCategories(content.results),
241                categoriesHtml = constructCategoriesHTML(categories);
242
243            $(autoCompleteDiv).find('.autocomplete_category_list').append(categoriesHtml);
244
245            var voiceOffers = (is_voice_offer) ? getHits(content.results) : [],
246                voiceOffersHtml = constructVoiceOffersHTML(voiceOffers);
247
248            $(autoCompleteDiv).find('.autocomplete_masters').find('ul').append(voiceOffersHtml);
249
250            var seeAllMasterText, noresultsText;
251
252            if (serviceId == 328) {
253                seeAllMasterText = 'View our advisors';
254                noresultsText = 'No results';
255                $('.autocomplete_category_title').text('See all skills');
256            } else if (serviceId == 327) {
257                seeAllMasterText = 'Voir tous les voyants';
258                noresultsText = 'Aucun résultat';
259            } else if (serviceId == 323) {
260                seeAllMasterText = 'VER TODOS LOS MASTERS';
261                noresultsText = 'No hay resultados';
262                $('.autocomplete_category_title').text('Ver todos de la categoría :');
263            } else if (serviceId == 326) {
264                seeAllMasterText = 'VER TODOS LOS ESPECIALISTAS';
265                noresultsText = 'No hay resultados';
266                $('.autocomplete_category_title').text('Ver todos de la categoría :');
267            } else if (serviceId == 322) {
268                seeAllMasterText = 'VEDERE TUTTI I MASTERS';
269                noresultsText = 'Nessun risultato';
270                $('.autocomplete_category_title').text('Vedere tutto nella categoria :');
271            } else if (serviceId == 287) {
272                seeAllMasterText = 'Voir tous les masters';
273                noresultsText = 'Aucun résultat';
274            } else if (['329','330'].includes(serviceId.toString())) {
275                seeAllMasterText = 'Alle Berater anzeigen';
276                noresultsText = 'Keine Ergebnisse';
277                $('.autocomplete_category_title').text('Alles in der Kategorie anzeigen :');
278            }
279
280            $('.autocomplete_container').addClass('autocomplete_click_to_call_only');
281            $('.autocomplete_djobs').addClass('hide');
282
283            if (countMastersResults(content) > voiceOfferHitsPerPage) {
284                $(autoCompleteDiv).find('.autocomplete_masters').append('<button href="resultats-de-la-recherche.html" class="autocomplete_see_more_button autocomplete_clicktocall_button font-smaller">' + seeAllMasterText + '</button>');
285            }
286            if (countMastersResults(content) < 1) {
287                $(autoCompleteDiv).find('.autocomplete_masters_list').append('<li class="autocomplete_no_result">' + noresultsText + '</li>');
288            }
289
290            if (is_voice_offer) {
291                var offerIds = getOfferIds(voiceOffers);
292                var voiceOffersButtonsHtml = getAndConstructVoiceOffersButtonsHTML(offerIds);
293            }
294
295            lastRequest = content;
296            searchLocal(lastKeywordValue);
297        }
298    }
299
300    function constructVoiceOffersHTML(voiceOffers) {
301        var html = '';
302
303        $.each(voiceOffers, function (index, voiceOffer) {
304            html += '<li class="autocomplete_result voice" cat_id="' + voiceOffer.cat_id + '" parent_cat_id="' + voiceOffer.parent_cat_id + '">';
305            html += '<div class="autocomplete_master_infos">';
306            html += '<a href="' + voiceOffer.profil_url + '">';
307            html += '<img src="' + voiceOffer.photo_url + '">';
308            html += '</a>';
309
310            html += '<div class="autocomplete_master_name">';
311            if (voiceOffer.offer_code !== undefined) {
312                html += '<div class="flex">';
313                html += '<a class="autocomplete_master_nickname voice mr-2" href="' + voiceOffer.profil_url + '">';
314                html += '<span>';
315                html += voiceOffer._highlightResult.first_name.value + '&nbsp;' + voiceOffer._highlightResult.last_name.value;
316                html += '</span>';
317                html += '</a>';
318                html += "<small>" + voiceOffer._highlightResult.offer_code.value + "</small>";
319                html += '</div>';
320            } else {
321                html += '<a class="autocomplete_master_nickname voice" href="' + voiceOffer.profil_url + '">';
322                html += '<span>';
323                html += voiceOffer._highlightResult.first_name.value + '&nbsp;' + voiceOffer._highlightResult.last_name.value;
324                html += '</span>';
325                html += '</a>';
326            }
327
328            html += '<div class="autocomplete_master_row">';
329
330            html += '<a href="' + voiceOffer.profil_url + '">';
331            html += '<span class="font-smaller">';
332            html += voiceOffer._highlightResult.cat_name.value.replace(/ /g, '\u00a0');
333            html += '</span>';
334            html += '</a>';
335
336            html += '<div id="offer_id_' + voiceOffer.offer_id + '" class="algolia_voice_status_buttons algolia_live_research">';
337            html += '</div>';
338
339            html += '</div>';
340            html += '</div>';
341            html += '</div>';
342            html += '</li>';
343        });
344
345        return html;
346    }
347
348    function getAndConstructVoiceOffersButtonsHTML(voiceOffers) {
349
350        $.post('/ajax/getAndConstructAlgoliaVoiceOffersButtonsHTML.js', {
351            voice_offers: JSON.stringify(voiceOffers),
352        }).done(function (result) {
353            resultDecode = $.parseJSON(result);
354            $.each(resultDecode, function (offerId, buttons) {
355                $('.autocomplete_masters').find('ul').find('#offer_id_' + offerId).html('');
356                $('.autocomplete_masters').find('ul').find('#offer_id_' + offerId).append(buttons);
357            });
358        }).fail(function () {
359            console.log('error algolia offers buttons added');
360        }).always(function () {
361            console.log('complete algolia offers buttons added');
362        });
363
364    }
365
366    function getOfferIds(result) {
367        var array = [];
368        for (var i = 0; i < result.length; i++) {
369            array.push(result[i]['offer_id']);
370        }
371        return array;
372    }
373
374    function getHits(results) {
375        return typeof results[0] !== 'undefined' ? results[0].hits : [];
376    }
377
378    function getCategories(results) {
379        var clickToCallHits = is_voice_offer ? getHits(results) : [];
380
381        var clickToCallCategories = groupBy(clickToCallHits, 'cat_name');
382
383        return $.extend(clickToCallCategories, {}, {});
384    }
385
386    function constructCategoriesHTML(categories) {
387        var html = '', name, url, type;
388
389        $.each(categories, function (index, category) {
390            url = category[0].cat_url;
391            name = category[0]._highlightResult.cat_name.value;
392            type = 'autocomplete_voice_category';
393            html += constructCategory(url, name, type);
394        });
395
396        return html;
397    }
398
399    function constructCategory(url, name, type) {
400        if (name == '') {
401            return '';
402        }
403
404        if (typeof type === 'undefined') {
405            type = 'autocomplete_voice_category';
406        }
407
408        var html = '';
409
410        html += '<li class="autocomplete_category ' + type + '">';
411        html += '<a href="' + url + '">' + name + '</a>';
412        html += '</li>';
413
414        return html;
415    }
416
417    function groupBy(arrayToGroup, key) {
418        return arrayToGroup.reduce(function (carry, offer) {
419            (carry[offer[key]] = carry[offer[key]] || []).push(offer);
420            return carry;
421        }, {});
422    }
423
424    function countMastersResults(content) {
425        var counter = 0;
426        if (typeof content.results[2] === 'undefined') {
427            counter = content.results[0].nbHits;
428        } else {
429            counter = content.results[0].nbHits + content.results[2].nbHits;
430        }
431        return counter;
432    }
433
434    function searchByQueries(client, value, callback) { //https://www.algolia.com/doc/api-client/javascript/search/#search-multiple-indices
435        var serviceId = getServiceId();
436
437        switch (window.algoliaUserSegment) {
438            case 'mixte':
439                voiceOfferHitsPerPage = 8;
440                break;
441            case 'digital':
442                voiceOfferHitsPerPage = 1;
443                break;
444            case 'click_to_call':
445                voiceOfferHitsPerPage = 3;
446                break;
447        }
448
449        if (hashKeyword[value.toUpperCase()] == 'DA') {
450            voiceOfferHitsPerPage = 0;
451        }
452
453        if ((serviceId === 323 || serviceId === 326) || hashKeyword[value.toUpperCase()] == 'Voyance') {
454            voiceOfferHitsPerPage = 8;
455        }
456
457        var voiceOfferQuery = {
458            indexName: 'voiceOffer_' + serviceId,
459            query: value,
460            params: {
461                hitsPerPage: voiceOfferHitsPerPage,
462            },
463        };
464
465        var queries = [voiceOfferQuery];
466
467        return client.search(queries, callback);
468    }
469
470    function getEditDistance(a, b) {
471        if (a.length == 0) {
472            return b.length;
473        }
474        if (b.length == 0) {
475            return a.length;
476        }
477
478        var matrix = [];
479
480        // increment along the first column of each row
481        var i;
482        for (i = 0; i <= b.length; i++) {
483            matrix[i] = [i];
484        }
485
486        // increment each column in the first row
487        var j;
488        for (j = 0; j <= a.length; j++) {
489            matrix[0][j] = j;
490        }
491
492        // Fill in the rest of the matrix
493        for (i = 1; i <= b.length; i++) {
494            for (j = 1; j <= a.length; j++) {
495                if (b.charAt(i - 1) == a.charAt(j - 1)) {
496                    matrix[i][j] = matrix[i - 1][j - 1];
497                } else {
498                    matrix[i][j] = Math.min(matrix[i - 1][j - 1] + 1, // substitution
499                        Math.min(matrix[i][j - 1] + 1, // insertion
500                            matrix[i - 1][j] + 1)); // deletion
501                }
502            }
503        }
504
505        return matrix[b.length][a.length];
506    }
507
508    function equalizeHeight(elements) {
509        var highestBox = 0;
510        elements.each(function () {
511            if ($(this).height() > highestBox) {
512                highestBox = $(this).height();
513            }
514        });
515        elements.height(highestBox);
516    }
517
518    function isMobile() {
519        if (window.innerWidth <= 320 && window.innerHeight <= 568) {
520            return true;
521        } else {
522            return false;
523        }
524    }
525})(jQuery);
526
527/*
528 * First let's get all the data we need as an array.
529 * There'd be an array for categories, an array for digital masters and an
530 * array for digital offers.
531 *
532 * These arrays would contain stuff of their part in the HTML
533 *
534 */

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.