PageSourceSearch

https://www.ikea.pr/webroot/conjurer/js/Searcher.js?v=1088

js ikea.pr collected 2026-10-04 00:55:25 UTC 18,951 bytes, 487 lines download raw bytes

1var Searcher = {
2    lastQuery: null,
3    autocompleteDOM: null,
4    autocompleteTranslations: null,
5    lastResult: null,
6
7    // drop searcher params
8    winWidth: 0,
9    winHeight: 0,
10    mainNavHeight: 0,
11    dropSearcher: null,
12    dropSearcherContent: null,
13    hamburgerMenu: null,
14    backLayout: null,
15    closeIcon: null,
16    searchIcon: null,
17    dropSearcherInput: null,
18    popupInspire: null,
19    popupInspireHeight: null,
20    topBanner: null,
21    topBannerheight: null,
22    someMenuIsOpen: null,
23
24    initialize: function () {
25        document.querySelectorAll('form[role="search"], .header_searcher_desktop_input_container')
26            .forEach(form => {
27                form.addEventListener('submit', function (e) {
28                    const q = form.querySelector('input[name="q"]');
29                    if (!q.value.trim()) {
30                        e.preventDefault();   // kill the submission
31                        q.focus();            // send cursor back
32                    }
33                }, { once: false });
34            });
35
36
37        $('#header_searcher_desktop_input').keydown(function (event) {
38            if ((event.keyCode == 13) && ($(this).val().length < 3)) {
39                event.preventDefault();
40                return false;
41            }
42        });
43
44        /*$('[data-action="search"]').each(function (index) {
45            Searcher.initialize_autocomplete("#" + $(this).attr("id"));
46        });*/
47
48        $("[data-action='searcherImg']").click(function () {
49
50            if ($("#header_searcher_desktop_input").val().length > 2) {
51                $("#header_searcher_" + $(this).data("type") + "_input_container").submit();
52            }
53        });
54        $('.auto_head_search_button').click(function(e) {
55            e.preventDefault();
56            var input =$('#header_searcher_desktop_input').val().trim();
57        
58            if (input.length >= 3) {
59               $('#header_searcher_desktop_input').closest("form").submit();
60            }
61        });
62        
63        $('#searcherDropdown').click(function (e) {
64            e.preventDefault();
65            $('#header_searcher_mobile_input_container').toggleClass('visibilitySearcher');
66            $("#header_searcher_mobile_input").focus();
67            //setTimeout(function() { $("#header_searcher_mobile_input").get(0).focus() }, 100);
68        });
69
70        $('#close-wrapper').click(function (e) {
71            $("#header_searcher_mobile_input").val('');
72            $('#header_searcher_mobile_input_container').toggleClass('visibilitySearcher');
73        });
74
75        Searcher.initializeDropSearcher();
76
77    },
78
79    autocomplete: function (query, callback) {
80
81        var query = query.trim();
82
83        if (query === Searcher.lastquery) {
84            callback(Searcher.lastResult);
85            return;
86        } else {
87            Searcher.lastquery = query;
88        }
89
90        if (query.length > 0 && query.length < 3) {
91            return;
92        }
93
94        Searcher.dropSearcher.busyLoad("show");
95        Searcher.dropSearcher.css({ "min-height": "220px", "padding": "30px 10px" });
96        $.ajax({
97            type: "GET",
98            dataType: "json",
99            contentType: "application/x-www-form-urlencoded",
100            url: validateURL.URL() + '/search/suggest',
101            data: { "term": query },
102            success: function (result) {
103                Searcher.lastResult = result;
104                callback(result);
105
106                if (availableEvents() == true && typeof result.impressionDataSearch !== 'undefined') {
107
108                    var listado = JSON.parse(result.impressionDataSearch)
109                    if (listado && listado.length > 0 && listado[0]) {
110                        ga4.viewItemList(listado);
111                        ga4.searchSuggestions(listado);
112
113                        $('#dropSearcherContent a[data-item]').click(function () {
114                            event.preventDefault();
115                            ga4.goItem(listado, $(this).data("item"), 'select_item', 'search suggestions');
116                            if (typeof $(this).attr('href') !== 'undefined') {
117                                window.location.href = $(this).attr('href');
118                            }
119                        });
120                    }
121                }
122
123
124            },
125            timeout: 10000,
126            complete: function () {
127                Searcher.dropSearcher.busyLoad("hide");
128            }
129        });
130
131    },
132
133    autocomplete_result: function (result) {
134
135        // returns boolean in case the browser is Internet Explorer
136        function isIE() {
137            ua = navigator.userAgent;
138            var is_ie = ua.indexOf("MSIE ") > -1 || ua.indexOf("Trident/") > -1;
139            return is_ie;
140        }
141
142        // Hack para IE
143        if (!isIE) {
144            Searcher.openDropSearcher();
145        }
146
147        if (result.html_content != undefined && result.html_content.trim().length > 0) {
148            Searcher.dropSearcherContent.html(result.html_content);
149            //Searcher.dropSearcherContent.find(".lazy").lazy();
150        } else {
151            Searcher.dropSearcherContent.html("");
152            setTimeout(function () {
153                Searcher.dropSearcher.css({ "min-height": "0px", "padding": "10px 10px" });
154            }, 200);
155        }
156
157    },
158    searcherOpenedOnce: false,
159    //======================================= dropSearcher =======================================
160    initializeDropSearcher: function () {
161
162        Searcher.calculateSizes();
163
164        var resizeCallback = null;
165        // var resizeCallback2 = null;
166        // var resizeCallback3= null;
167        $(window).resize(function () {
168            clearTimeout(resizeCallback);
169            resizeCallback = setTimeout(Searcher.calculateSizes, 100);
170            // resizeCallback2 = setTimeout(Searcher.closeDropSearcher(), 200);
171            // resizeCallback3 = setTimeout(Searcher.closeMobileNavMenu(), 300);
172            if ($('#headerMenuServices').hasClass('show') && winWidth <= 992) {
173                Searcher.hamburgerMenu.click();
174            }
175        });
176
177        Searcher.dropSearcherInput = $('#searcher input');
178        Searcher.searchIcon = $('#searcher .searchIcon');
179        Searcher.hamburgerMenu = $('.navbar-toggler-cross');
180        Searcher.dropSearcher = $('#dropSearcher');
181        Searcher.dropSearcherContent = Searcher.dropSearcher.find("#dropSearcherContent");
182        Searcher.backLayout = $('#backLayout');
183        Searcher.closeIcon = $('#header_searcher_desktop_input_container + .input-group-append .closeIcon');
184        Searcher.searchButton = $('#header_searcher_desktop_input_container + .input-group-append .auto_head_search_button');
185        Searcher.buttonsDivider = $('#header_searcher_desktop_input_container + .input-group-append .search-box-search__divider');
186        Searcher.popupInspire = $('#popupInspire');
187        Searcher.popupInspireHeight = $('#popupInspire').outerHeight(true) || 0;
188        Searcher.topBanner = $('#topBanner');
189        Searcher.topBannerHeight = Searcher.topBanner.outerHeight(true);
190        Searcher.searchImgIcon = $('#header_searcher_desktop_input_container + .input-group-append .imgSearchIcon');
191        Searcher.someMenuIsOpen = Searcher.dropSearcher.hasClass('visible') || $('#headerMenuServices').hasClass('show');
192        Searcher.productMenu = $('#headerMain > div:first');
193        Searcher.input = $('#header_searcher_desktop_input');
194        
195
196        //---------------
197        if (winWidth >= 992) {
198            Searcher.dropSearcher.find(".container").css({ 'max-width': $('#searcher').outerWidth(true) });
199        }
200
201
202        // on focus -----------------
203        Searcher.dropSearcherInput.focus(function () {
204            Searcher.openDropSearcher();
205            Searcher.dropSearcherInput.trigger("input");
206            Searcher.searchButton.css({display:'none'})
207            Searcher.closeIcon.css({display:'none'})
208            Searcher.buttonsDivider.css({display:'none'})
209        });
210
211        // Detectar cuando ningún elemento dentro del producto menú tiene foco
212        Searcher.productMenu.on('focusout', function () {
213            setTimeout(function () {
214                const hasFocus = Searcher.productMenu.find(':focus').length || $('#dropSearcher').find(':focus').length;
215                if (!hasFocus) {
216                    Searcher.closeDropSearcher();
217                }
218            }, 0); // Ejecutamos después de que el evento focusout termine
219        });
220
221        // on writing -----------------
222        let hadText = false;
223        var searchCallback = null;
224        let resetTimeout;
225        Searcher.dropSearcherInput.on('input', function() {
226            clearTimeout(resetTimeout);
227            Searcher.openDropSearcher();
228            var inputVal = $(this).val().trim();
229            var iconGroup = $('.input-group-preappend.search-icon-align');
230            var qrIcon = $('#btn-scan-qr');
231
232            if (!Searcher.searcherOpenedOnce) {
233                Searcher.searcherOpenedOnce = true;
234                return;
235            }
236            clearTimeout(searchCallback);
237            searchCallback = setTimeout(function() {
238                Searcher.autocomplete(inputVal, Searcher.autocomplete_result);
239            }, 500);
240            if (inputVal.length > 0) {
241                $('.auto_head_search_button').addClass('active');
242                Searcher.searchButton.css({ display: 'block' });
243                Searcher.closeIcon.css({ display: 'block' });
244                Searcher.buttonsDivider.css({ display: 'block' });
245                $('#header_searcher_desktop_input').addClass('padding-reduced');
246
247                if (!iconGroup.hasClass('fadeOutLeft')) {
248                    iconGroup.removeClass('fadeInLeft').addClass('fadeOutLeft');
249                    resetTimeout = setTimeout(function () {
250                        if (iconGroup.hasClass('fadeOutLeft')) {
251                            iconGroup.css('display', 'none');
252                        }
253                    }, 400);
254                }
255                qrIcon.css('display', 'none');
256                if (!hadText) {
257                    hadText = true;
258                    Searcher.closeIcon
259                        .css('display', 'inline-block')
260                        .removeClass('fadeOutRight')
261                        .addClass('fadeInRight');
262                    Searcher.searchButton
263                        .css('display', 'inline-block')
264                        .removeClass('fadeOutRight')
265                        .addClass('fadeInRight');
266                    Searcher.buttonsDivider
267                        .css('display', 'inline-block')
268                        .removeClass('fadeOutRight')
269                        .addClass('fadeInRight');
270
271                    resetTimeout = setTimeout(function () {
272                        Searcher.closeIcon.removeClass('fadeInRight');
273                        Searcher.searchButton.removeClass('fadeInRight');
274                        Searcher.buttonsDivider.removeClass('fadeInRight');
275                    }, 500);
276                }
277            } else {
278                $('.auto_head_search_button').removeClass('active');
279                $('#header_searcher_desktop_input').removeClass('padding-reduced');
280                Searcher.closeIcon
281                    .removeClass('fadeInRight')
282                    .addClass('fadeOutRight');
283                Searcher.searchButton
284                    .removeClass('fadeInRight')
285                    .addClass('fadeOutRight');
286                Searcher.buttonsDivider
287                    .removeClass('fadeInRight')
288                    .addClass('fadeOutRight');
289                hadText = false;
290                if (!iconGroup.hasClass('fadeInLeft')) {
291                    iconGroup.css('display', 'flex');
292                    iconGroup.removeClass('fadeOutLeft');
293                }
294                iconGroup.css('display', 'flex').addClass('fadeInLeft');
295                qrIcon.css('display', 'flex');
296            }
297        });
298
299        Searcher.dropSearcherInput.blur(function(){
300            setTimeout(function(){
301                if (Searcher.dropSearcherInput.val().length == 0) {
302                    Searcher.searchButton.css({display:'none'})
303                    Searcher.closeIcon.css({display:'none'})
304                    Searcher.buttonsDivider.css({display:'none'})
305                }
306            }, 100);
307        });
308
309        Searcher.searchIcon.click(function () {
310            $('form.header_searcher_desktop_input_container').submit();
311        });
312
313        Searcher.closeIcon.click(function () {
314            Searcher.dropSearcherInput.val('');
315            Searcher.closeDropSearcher();
316            $('#header_searcher_desktop_input').removeClass('padding-reduced');
317            const iconGroup = $('.input-group-preappend.search-icon-align');
318            const qrIcon = $('#btn-scan-qr');
319            iconGroup.css('display', 'flex')
320                    .removeClass('fadeOutLeft')
321                    .addClass('fadeInLeft');
322            qrIcon.css('display', 'flex');            
323        });
324
325        Searcher.hamburgerMenu.click(function () {
326            if (Searcher.hamburgerMenu.hasClass('collapsed')) {
327                if (Searcher.dropSearcher.hasClass('visible')) {
328                    Searcher.closeDropSearcher();
329                }
330                Searcher.openMobileNavMenu();
331                Searcher.topBanner.fadeOut('fast');
332            } else {
333                Searcher.topBanner.fadeIn('fast');
334            }
335        });
336
337        // dblclick not allowed!!
338        Searcher.hamburgerMenu.dblclick(function (e) {
339            e.stopPropagation();
340            e.preventDefault();
341            ScrollHider.hide();
342            return
343        });
344
345
346        Searcher.backLayout.click(function () {
347            Searcher.closeDropSearcher();
348        });
349
350        Searcher.popupInspire.find('.close').click(function (e) {
351            Searcher.calculateSizes();
352            Searcher.mobileNavMenuPosition();
353        });
354
355
356    },
357
358    calculateSizes: function () {
359
360        winWidth = Math.floor($(window).width());
361        winHeight = Math.floor($(window).height());
362        mainNavHeight = Math.floor($('.mainNav').outerHeight(true));
363
364        Searcher.popupInspire = $('#popupInspire');
365        Searcher.popupInspireHeight = Searcher.popupInspire?.outerHeight(true) || 0;
366        Searcher.topBanner = $('#topBanner');
367        Searcher.topBannerHeight = Searcher.topBanner.outerHeight(true) || 0;
368
369        // var deviceAgent = navigator.userAgent.toLowerCase();
370        // var isApple = deviceAgent.match(/(iphone|ipod|ipad)/);
371        // if (isApple) {}
372
373        Searcher.recalculateDropPosition();
374
375    },
376    openDropSearcher: function () {
377        Searcher.recalculateDropPosition();
378        if (Searcher.dropSearcher.hasClass("visible")) {
379            return;
380        }
381        
382        if($('#headerMenuServices').hasClass('show')){
383            Searcher.hamburgerMenu.click();
384        }
385        
386        Searcher.dropSearcher
387            .addClass('visible')
388            .css('opacity', 0)
389            .slideDown(300)
390            .animate(
391                { opacity: 1 },
392                { queue: false, duration: 300 }
393            );
394        Searcher.backLayout.addClass('visible');
395        Searcher.closeIcon.css({ display: 'block' });
396        Searcher.searchImgIcon.css({ display: 'none' });
397        ScrollHider.hide();
398    },
399
400    closeDropSearcher: function () {
401        Searcher.recalculateDropPosition();
402        Searcher.closeIcon.addClass('fadeOutRight'); 
403        Searcher.searchButton.addClass('fadeOutRight'); 
404        Searcher.buttonsDivider.addClass('fadeOutRight'); 
405        Searcher.dropSearcher.removeClass('visible');
406        Searcher.backLayout.removeClass('visible');
407        Searcher.dropSearcherContent.html("");
408        Searcher.closeIcon.css({ display: 'none' });
409        Searcher.searchImgIcon.css({ display: 'block' });
410        ScrollHider.show();
411
412        setTimeout(function(){
413            Searcher.closeIcon.removeClass('fadeOutRight'); 
414            Searcher.searchButton.removeClass('fadeOutRight'); 
415            Searcher.buttonsDivider.removeClass('fadeOutRight'); 
416            Searcher.dropSearcherContent.html('');
417            Searcher.closeIcon.css({display:'none'})
418            Searcher.searchButton.css({display:'none'});      // <- ocultar lupa
419            Searcher.buttonsDivider.css({display:'none'}); 
420            Searcher.searchImgIcon.css({display:'block'})
421            Searcher.backLayout.removeClass('visible'); 
422            ScrollHider.show();
423            Searcher.dropSearcher.fadeOut(300, function(){
424                Searcher.dropSearcher.removeClass('visible'); 
425            });
426        }, 500);
427    },
428
429    // Coloca el dropSearcher en el bottom del input aunque haga scroll
430    recalculateDropPosition: function () {
431        if (Searcher.dropSearcherInput?.length) {
432            const inputBottom = (Searcher.dropSearcherInput.offset().top + Searcher.dropSearcherInput.outerHeight(true) + 2) - ($("#headerMain").hasClass("fixed") ? $(window).scrollTop() : 0);
433            Searcher.dropSearcher.css('top', `${inputBottom}px`);
434            Searcher.backLayout.css('top', `${inputBottom}px`);
435        }
436    },
437
438    openMobileNavMenu: function () {
439        if (winWidth <= 992) {
440            $('.headerMainToggler').css({ 'overflow': 'hidden' });
441            Searcher.mobileNavMenuPosition();
442        }
443    },
444
445    closeMobileNavMenu: function () {
446        if (winWidth <= 992) {
447            $('#headerMenuServices ').removeClass('show');
448            $('#headerMenuServices ').collapse('hide')
449            Searcher.hamburgerMenu.addClass('collapsed');
450            $('.headerMainToggler').css({ 'overflow': 'auto' });
451            Searcher.mobileNavMenuPosition();
452        }
453    },
454
455    mobileNavMenuPosition() {
456        setTimeout(() => {
457            Searcher.popupInspireHeight = Searcher.popupInspire?.outerHeight(true) || 0;
458            Searcher.topBanner = Searcher.topBanner.outerHeight(true) || 0;
459            Searcher.calculateSizes();
460            $('#headerMenuServices').css({
461                'max-height': (Math.floor(winHeight - mainNavHeight) + 2) + 'px',
462                'top': (Math.floor(mainNavHeight - 1 + Searcher.popupInspireHeight)) + 'px'
463            });
464            // console.log('mobileNavMenuPosition', Math.floor(mainNavHeight - 1 + Searcher.popupInspireHeight))  + 'px';
465        }, 200);
466
467    }
468};
469
470document.addEventListener('DOMContentLoaded', () => {
471    Searcher.initialize();
472});
473
474$('#headerMenuServices').on('hidden.bs.collapse', function () {
475    // console.log('headerMenuServices oculto');
476})
477
478$("#headerMenuServices *").click(function () {
479    Searcher.closeDropSearcher();
480});
481
482$(document).keyup(function (e) {
483    // escape key maps to keycode `27`
484    if (e.key === "Escape") {
485        Searcher.closeDropSearcher();
486    }
487});

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.