PageSourceSearch

https://www.woven.is/blog/js/js.js?v=2026

js woven.is collected 2026-09-29 09:09:21 UTC 53,734 bytes, 1,635 lines download raw bytes

1jQuery(document).ready(function ($) {
2    'use strict';
3    init_lazy('.lazy--main', '.scrollbox--main');
4    init_lazy('.lazy--happening', '.scrollbox--happening');
5    navbar();
6    init_stories();
7    init_inquire();
8    init_newsletter_modal();
9    init_redraw_carriage();
10    init_catalog();
11    init_catalog_images();
12    init_catalog_rolldown();
13    init_catalog_add2myrugs();
14    init_filter_tree();
15    init_share();
16    init_contact_form();
17    init_login_form();
18    init_index();
19    init_gohez();
20    loginModal();
21    advSearchOpen();
22    cookie();
23    collectionReadMore();
24    togglePassword();
25    checkScreenSize();
26    init_Banda_ref();
27});
28
29
30function init_Banda_ref() {
31    const params = new URLSearchParams(window.location.search);
32
33    function getCookieValue(name) {
34        const nameEQ = name + "=";
35        const ca = document.cookie.split(";");
36        for (let i = 0; i < ca.length; i++) {
37            let c = ca[i];
38            while (c.charAt(0) === " ") c = c.substring(1);
39            if (c.indexOf(nameEQ) === 0) {
40                return c.substring(nameEQ.length);
41            }
42        }
43        return null;
44    }
45
46    function bandaRefFromCookie() {
47        let cookieVal = getCookieValue("BANDAREF");
48        if (cookieVal == null) return false;
49        try {
50            cookieVal = decodeURIComponent(cookieVal.replace(/\+/g, " "));
51        } catch {
52            // use raw
53        }
54        const normalized = String(cookieVal).trim().toLowerCase();
55        return normalized === "true" || normalized === "1" || normalized === "yes";
56    }
57
58    window.syncBandaRefHiddenInputs = function () {
59        if (!window.isBandaReferral || !window.isBandaReferral()) return;
60        $('input[name="DATA[BANDAREF]"]').val("true");
61    };
62
63    if (params.get("utm_source") === "banda") {
64        const data = {
65            value: true,
66            expiresAt: Date.now() + 1000 * 60 * 30 // 30 minutes
67        };
68        localStorage.setItem("BANDAREF", JSON.stringify(data));
69    }
70
71    // Active Banda ref: utm/localStorage window and/or BANDAREF cookie (e.g. server-set)
72    window.isBandaReferral = function () {
73        const item = localStorage.getItem("BANDAREF");
74        if (item) {
75            try {
76                const data = JSON.parse(item);
77                if (Date.now() > data.expiresAt) {
78                    localStorage.removeItem("BANDAREF");
79                } else {
80                    return !!data.value;
81                }
82            } catch {
83                // ignore invalid JSON
84            }
85        }
86        return bandaRefFromCookie();
87    };
88
89    window.syncBandaRefHiddenInputs();
90}
91
92function mobileFooterOpen() {
93    const footerTitles = document.querySelectorAll('.footerTitle2');
94
95    footerTitles.forEach(function (title) {
96        title.addEventListener('click', toggleFooterSection);
97    });
98
99    listenersAttached = true;
100}
101
102function toggleFooterSection(event) {
103    const title = event.currentTarget;
104    const locationWrapper = title.nextElementSibling;
105
106    if (locationWrapper.classList.contains('open')) {
107        locationWrapper.classList.remove('open');
108        setTimeout(() => {
109            locationWrapper.style.display = 'none';
110        }, 500);
111    } else {
112        locationWrapper.style.display = 'block';
113        setTimeout(() => {
114            locationWrapper.classList.add('open');
115        }, 10);
116    }
117}
118
119function removeMobileFooterListeners() {
120    const footerTitles = document.querySelectorAll('.footerTitle2');
121
122    footerTitles.forEach(function (title) {
123        title.removeEventListener('click', toggleFooterSection);
124    });
125
126    listenersAttached = false;
127}
128
129function checkScreenSize() {
130    let listenersAttached = false;
131    document.addEventListener('DOMContentLoaded', checkScreenSize);
132    window.addEventListener('resize', checkScreenSize);
133
134    if (window.innerWidth <= 974) {
135        if (!listenersAttached) {
136            mobileFooterOpen();
137        }
138    } else {
139        if (listenersAttached) {
140            removeMobileFooterListeners();
141        }
142
143        const footerTitles = document.querySelectorAll('.footerTitle2');
144        footerTitles.forEach(function (title) {
145            const locationWrapper = title.nextElementSibling;
146            locationWrapper.classList.remove('open');
147            locationWrapper.style.display = 'block';
148        });
149    }
150}
151
152function togglePassword() {
153    const togglePasswords = document.querySelectorAll(".js-password_eye");
154    if (!togglePasswords.length) {
155        return;
156    }
157
158    togglePasswords.forEach(function (togglePassword) {
159        togglePassword.addEventListener("click", function (e) {
160            e.preventDefault();
161            const passwordId = this.getAttribute("data-passid");
162            if (!passwordId) {
163                return;
164            }
165            const wrapper = this.closest("form") || document;
166            const password = wrapper.querySelector("#" + passwordId);
167            if (!password) {
168                return;
169            }
170            const type = password.getAttribute("type") === "password" ? "text" : "password";
171            password.setAttribute("type", type);
172
173            const isVisible = type === "text";
174            this.classList.toggle("visible", isVisible);
175            this.setAttribute("aria-label", isVisible ? "Hide password" : "Show password");
176            this.setAttribute("title", isVisible ? "Hide password" : "Show password");
177        });
178    });
179}
180
181function collectionReadMore() {
182    $(document).ready(function () {
183        $('.colDesc').each(function () {
184            var $this = $(this);
185            if ($this.children().length > 1) {
186                $('#readMoreBTNWrapper').addClass('show');
187            }
188        });
189    });
190
191    let $collectionWrapper = $('.collectionHeroWrapper');
192    let $readMoreBTN = $('.readMoreBTN');
193
194    $readMoreBTN.on('click', function () {
195        $collectionWrapper.toggleClass("readMore");
196
197        if ($collectionWrapper.hasClass("readMore")) {
198            $readMoreBTN.text("close");
199        } else {
200            $readMoreBTN.text("Read More");
201        }
202    });
203}
204
205const globalNotifAnimation = () => {
206    const $globalNotif = $('#globalNotif');
207    $globalNotif.addClass('show');
208    setTimeout(function () {
209        $globalNotif.removeClass('show');
210    }, 5000);
211
212    $globalNotif.on("click", function () {
213        $globalNotif.removeClass('show');
214    })
215}
216
217function cookie() {
218    const cookieBanner = document.querySelector("#cookieBannerWrapper"),
219        cookieBTNs = document.querySelectorAll(".cookieBTN");
220
221    const setCookie = (name, value, days) => {
222        let expires = "";
223        if (days) {
224            const date = new Date();
225            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
226            expires = "; expires=" + date.toUTCString();
227        }
228        document.cookie = name + "=" + (value || "") + expires + "; path=/";
229    };
230
231    const getCookie = (name) => {
232        let nameEQ = name + "=";
233        let ca = document.cookie.split(';');
234        for (let i = 0; i < ca.length; i++) {
235            let c = ca[i];
236            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
237            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
238        }
239        return null;
240    };
241
242    const executeCookie = () => {
243        if (document.cookie.includes("woven")) return;
244        cookieBanner.classList.add("show");
245
246        cookieBTNs.forEach((button) => {
247            button.addEventListener("click", () => {
248                cookieBanner.classList.remove("show");
249
250                if (button.id === "acceptCookies") {
251                    setCookie("cookieBy", "woven", 30);
252                }
253            });
254        });
255    };
256
257    const applyLayoutFromCookie = () => {
258        const layout = getCookie("pageLayout");
259        const productGrid = document.querySelector('.rugThumbsWrapper');
260        if (layout && productGrid) {
261            const rugViewButton = document.querySelector('input[value="rug_view"]');
262            const listViewButton = document.querySelector('input[value="list_view"]');
263
264            if (layout === "rug_view" && rugViewButton) {
265                productGrid.classList.remove('list-view');
266                productGrid.classList.add('rug-view');
267                rugViewButton.checked = true;
268            } else if (layout === "list_view" && listViewButton) {
269                productGrid.classList.remove('rug-view');
270                productGrid.classList.add('list-view');
271                listViewButton.checked = true;
272            }
273        }
274    };
275
276    const handleLayoutSwitcher = () => {
277        const layoutSwitcher = document.querySelector('.layoutSwitcher');
278        const productGrid = document.querySelector('.rugThumbsWrapper');
279
280        if (layoutSwitcher && productGrid) {
281            const rugViewButton = layoutSwitcher.querySelector('input[value="rug_view"]');
282            const listViewButton = layoutSwitcher.querySelector('input[value="list_view"]');
283
284            if (rugViewButton && listViewButton) {
285                rugViewButton.addEventListener('change', function () {
286                    if (rugViewButton.checked) {
287                        productGrid.classList.remove('list-view');
288                        productGrid.classList.add('rug-view');
289                        setCookie("pageLayout", "rug_view", 30);
290                    }
291                });
292
293                listViewButton.addEventListener('change', function () {
294                    if (listViewButton.checked) {
295                        productGrid.classList.remove('rug-view');
296                        productGrid.classList.add('list-view');
297                        setCookie("pageLayout", "list_view", 30);
298                    }
299                });
300            }
301        }
302    };
303
304    window.addEventListener("load", () => {
305        executeCookie();
306        applyLayoutFromCookie();
307        handleLayoutSwitcher();
308    });
309}
310
311
312function navbar() {
313    const menuIcon = document.querySelector(".navMenuIcon");
314    const navList = document.querySelector("ul.topNavLinkList");
315    const dropDowns = document.querySelectorAll('.topNavLinkWrapper');
316
317    // Exit early if required elements don't exist
318    if (!menuIcon || !navList) {
319        return;
320    }
321
322    function toggleMenu() {
323        navList.classList.toggle('open');
324    }
325
326    function handleDropdowns() {
327        dropDowns.forEach(function (dropDown) {
328            const subMenu = dropDown.querySelector('.topNavSubMenuWrapper');
329            if (!subMenu) return;
330
331            if (window.matchMedia("(min-width: 974px)").matches) {
332                dropDown.addEventListener('mouseenter', function () {
333                    dropDown.classList.add('open');
334                });
335
336                dropDown.addEventListener('mouseleave', function () {
337                    setTimeout(() => {
338                        if (!subMenu.matches(':hover')) {
339                            dropDown.classList.remove('open');
340                        }
341                    }, 100);
342                });
343
344                subMenu.addEventListener('mouseleave', function () {
345                    dropDown.classList.remove('open');
346                });
347            } else {
348                dropDown.addEventListener('click', function (event) {
349                    dropDown.classList.toggle('open');
350                });
351
352                dropDown.addEventListener('click', function () {
353                    dropDowns.forEach(function (otherDropDown) {
354                        if (otherDropDown !== dropDown) {
355                            otherDropDown.classList.remove('open');
356                        }
357                    });
358                });
359            }
360        });
361    }
362
363    menuIcon.addEventListener("click", toggleMenu);
364    // menuIcon.addEventListener("touchstart", toggleMenu);
365
366    handleDropdowns();
367}
368
369function loginModal() {
370    const $loginModal = $("#loginModalWrapper");
371
372    $(".js-login-close").on("click", function () {
373        $("#inquireModalWrapper").animate({
374            right: "-200%",
375            ease: "swing"
376        });
377    });
378
379    function openLoginModal(e) {
380        const $trigger = $(this);
381
382        if ($trigger.is("a") && $trigger.attr("href")) {
383            return true;
384        }
385
386        e.preventDefault();
387
388        if (!$loginModal.length) {
389            window.location.href = "/login/";
390            return false;
391        }
392
393        $loginModal.css("visibility", "visible").animate({ opacity: 1 });
394        return false;
395    }
396
397    $(".loginOpenBTN").on("click", openLoginModal);
398    $(".loginOpenBTN").on("touchstart", openLoginModal);
399
400    $("#js-login-close").on("click", function () {
401        $loginModal.animate({ opacity: 0 }).css("visibility", "hidden");
402    });
403}
404
405function advSearchOpen() {
406    $(".topNavSearchWrapper").on("click", function () {
407        $("#advSearchWrapper").toggleClass("open");
408        $(this).toggleClass("open");
409
410        setTimeout(function () {
411            $("#searchBar").focus();
412        }, 500);
413    });
414
415    const form = document.querySelector(".js-search_by_keyword");
416    if (form) {
417        form.addEventListener("submit", function (event) {
418            const catInputs = form.querySelectorAll('input[name="params[cat_id]"]');
419            catInputs.forEach(input => {
420                input.value = "";
421            });
422        });
423    }
424}
425
426function init_redraw_carriage() {
427    $(window).on('resize', function () {
428        $('.train__carriage').hide(0, function () {
429            $('.train__carriage').show();
430        });
431    });
432}
433
434var loadingThroughTheLeftFilter = false;
435var historyURLAddress = window.location.href;
436
437function init_stories() {
438    var ajaxContainer = $('.js-ajax-container'),
439        ajaxContent = $('.js-ajax-content'),
440        lazy = '.lazy--main',
441        scrollbox = '.scrollbox--main';
442
443    init_lazy(lazy, scrollbox);
444
445    // Close button
446    ajaxContainer.on('click touchstart', '.osfc_close', function (event) {
447        event.preventDefault();
448        ajaxContainer.fadeOut('fast', function () {
449            history.pushState("", document.title, window.location.pathname + window.location.search);
450            ajaxContent.html('');
451        });
452    });
453
454    // Left + Right Controls using GSAP for smooth scrolling
455    ajaxContainer.on('click', '.osfc_horizon-next', function (event) {
456        event.preventDefault();
457        var $scrollbox = $(this).closest('.js-ajax-container').find('.scrollbox');
458        var amount = $(window).width() / 2;
459        if (window.innerWidth > 974) {
460            gsap.to($scrollbox, { duration: 0.6, scrollTo: { x: '+=' + amount } });
461        }
462    });
463
464    ajaxContainer.on('click', '.osfc_horizon-prev', function (event) {
465        event.preventDefault();
466        var $scrollbox = $(this).closest('.js-ajax-container').find('.scrollbox');
467        var amount = $(window).width() / 2;
468        if (window.innerWidth > 974) {
469            gsap.to($scrollbox, { duration: 0.6, scrollTo: { x: '-=' + amount } });
470        }
471    });
472    function load_content(type, CAT_TAG) {
473        $.ajax({
474            url: '/?ac=list&name=ajax_' + type + '&CAT_TAG=' + CAT_TAG,
475            success: function (res) {
476                $('.js-ajax-content').html(res);
477                $('.js-ajax-container').fadeIn('slow');
478
479                var lazy = 'img.lazy--' + type,
480                    scrollbox = '.js-ajax-content .scrollbox--' + type;
481
482                init_lazy(lazy, scrollbox);
483
484                function scrollHorizontally(element, scrollAmount) {
485                    gsap.to(element, { duration: 0.4, scrollTo: { x: element.scrollLeft + scrollAmount } });
486                }
487
488                function scrollVertically(element, scrollAmount) {
489                    gsap.to(element, { duration: 0.4, scrollTo: { y: element.scrollTop + scrollAmount } });
490                }
491
492                // Updated mousewheel event handler
493                $('.js-ajax-container .scrollbox').mousewheel(function (event) {
494                    event.preventDefault();
495                    var deltaX = parseInt(event.deltaX);
496                    var deltaY = parseInt(event.deltaY);
497                    var scrollAmount = 0;
498
499                    if (window.innerWidth > 974) {
500                        // Desktop: use horizontal scrolling
501                        if (Math.abs(deltaX) > 0) {
502                            var normalizedDelta = Math.min(Math.max(deltaX, -3), 3);
503                            var factor = 50 * (1 + Math.abs(normalizedDelta) / 3);
504                            scrollAmount = normalizedDelta * factor;
505                        } else {
506                            var normalizedDelta = Math.min(Math.max(deltaY, -3), 3);
507                            var factor = 50 * (1 + Math.abs(normalizedDelta) / 3);
508                            scrollAmount = -normalizedDelta * factor;
509                        }
510                        scrollHorizontally(this, scrollAmount);
511                    } else {
512                        // Mobile: use vertical scrolling
513                        if (Math.abs(deltaY) > 0) {
514                            scrollAmount = Math.min(Math.max(deltaY, -3), 3) * 50;
515                        } else {
516                            scrollAmount = Math.min(Math.max(deltaX, -3), 3) * 50;
517                        }
518                        scrollVertically(this, scrollAmount);
519                    }
520                });
521
522                if (detect_ff()) {
523                    $('.train__carriage').hide(0, function () {
524                        $('.train__carriage').show();
525                    });
526                }
527                if (detectIE()) return;
528                // Patch for SVG positioning
529                // setTimeout(function() {
530                //     $('svg').css('position', 'relative');
531                //     $('svg').css('position', 'absolute');
532                //     setTimeout(function() {
533                //         $('svg').css('position', 'absolute');
534                //     }, 1400);
535                // }, 1200);
536            }
537        });
538    }
539
540    function init_onhashchange() {
541        ajaxContainer.hide();
542        ajaxContent.html('');
543
544        if (window.location.hash) {
545            if (window.location.hash.indexOf('story_') == 1) {
546                var CAT_TAG = window.location.hash.replace('#story_', '');
547                load_content('story', CAT_TAG);
548            } else if (window.location.hash.indexOf('happening_') == 1) {
549                var CAT_TAG = window.location.hash.replace('#happening_', '');
550                load_content('story', CAT_TAG);
551            } else if (window.location.hash.indexOf('article_') == 1) {
552                var CAT_TAG = window.location.hash.replace('#article_', '');
553                load_content('story', CAT_TAG);
554            } else if (window.location.hash.indexOf('gallery_') == 1) {
555                var CAT_TAG = window.location.hash.replace('#gallery_', '');
556                load_content('gallery', CAT_TAG);
557            } else if (window.location.hash.indexOf('video_') == 1) {
558                var CAT_TAG = window.location.hash.replace('#video_', '');
559                load_content('video', CAT_TAG);
560            } else if (window.location.hash.indexOf('scroll_to_first_story') == 1) {
561                setTimeout(function () {
562                    $('.scrollbox--main').animate({ scrollLeft: $(window).width() / 1.4 }, 500);
563                }, 500);
564                if (typeof window.history.replaceState == 'function') {
565                    history.replaceState("", document.title, window.location.pathname + window.location.search);
566                }
567            } else if (!loadingThroughTheLeftFilter && window.location.hash.indexOf('#|nav|||||') == 0) {
568                let id = window.location.hash.slice(10, window.location.hash.indexOf('|||', 11));
569                leftLinkTrigger(id);
570            }
571        } else if (historyURLAddress !== window.location.href) {
572            window.location.reload();
573        }
574        historyURLAddress = window.location.href;
575    }
576
577    init_onhashchange();
578
579    window.addEventListener('hashchange', init_onhashchange, false);
580
581    $(document).on('click', '.open-big-story-now', function (event) {
582        event.preventDefault();
583        $('#' + $(this).data('storyId')).toggle('fast');
584    });
585}
586
587function init_lazy(lazy, scrollbox) {
588    if (!$(lazy).length) {
589        return;
590    }
591    $(lazy).lazyload({
592        threshold: 400,
593        container: $(scrollbox)
594    });
595}
596
597function pause_all_videos() {
598    $('video').each(function () { this.pause(); });
599}
600
601function init_gohez() {
602    $('.js-gohez').unbind('click');
603    $.each($('.js-gohez'), function () {
604        let p = $(this).closest('.catalog-sub-desc').find('p');
605        if (p.length < 2) {
606            $(this).hide();
607        } else {
608            $(this).on('click', function (event) {
609                event.preventDefault();
610                $(this).toggleClass('js-gohez-active');
611                $('.js-gohez-block', $(this).closest('.catalog-sub-desc')).toggleClass('js-gohez-block-active');
612            });
613        }
614    })
615}
616
617$(".alien-bg-img1").each(function (i) {
618    //debugger;
619    var getImageSrc = $(this).attr('data-bg-img');
620    $(this).css('background-image', "url('" + getImageSrc + "')");
621});
622
623/* Swiper Slider Controls */
624if ($('.swiper-container').length) {
625    var swiper = new Swiper('.swiper-container', {
626        pagination: '.swiper-pagination',
627        paginationClickable: true,
628        nextButton: '.swiper-button-next',
629        prevButton: '.swiper-button-prev',
630        spaceBetween: 30,
631        loop: true,
632        paginationType: 'bullets'
633    });
634    if ($('.swiper-slide').length <= 1) {
635        $('.swiper-button-next, .swiper-button-prev').addClass('hidden');
636    }
637}
638
639var alienSliderPos = 0;
640
641$(document).on("click", ".swiper-slide > div", function () {
642    var hoverbigimgTitle = $(this).attr('data-title-img');
643    $(".swiper-pagination-title span").text(hoverbigimgTitle);
644
645    $('.swiper-slide > div').each(function () {
646        var src = $(this).attr('data-bg-img-zoom');
647        $(this).zoom({
648            url: src,
649            touch: false,
650            on: 'click',
651            duration: 50,
652            magnify: 0.75
653        });
654    });
655
656    $(document).on("click", ".zoomImg", function () {
657        $(this).trigger('zoom.destroy');
658    });
659
660    /*prev button*/
661    if ($(".productsidebar").length) {
662        $(".swiper-button-prev").css({ "left": "40px" });
663    }
664
665    if (alienSliderPos == 1) {
666        return false;
667    }
668
669    $('.swiper-container-over').fadeIn('fast');
670
671    if (alienSliderPos == 0) {
672
673        setTimeout(function () {
674            $('.swiper-main-container').addClass('swiper-main-container-full');
675            $('body').addClass('overflowhidden');
676        }, 300);
677        alienSliderPos = 1;
678        swiper.params.paginationType = 'fraction';
679        $('.closepopupproductnow').fadeIn("fast");
680        $('.swiper-pagination-title').fadeIn("fast");
681    }
682
683    setTimeout(function () {
684        swiper.update();
685        swiper.onResize();
686        $('.swiper-container-over').fadeOut("slow");
687    }, 800);
688});
689
690$(document).on("click", ".closepopupproductnow", function () {
691    $('.closepopupproductnow').fadeOut("fast");
692    $('.swiper-main-container-full .swiper-pagination-title').fadeOut("fast");
693    $('.swiper-slide > div').trigger('zoom.destroy');
694    $("img.zoomImg").remove();
695    $('.swiper-container-over').fadeIn('fast');
696
697    setTimeout(function () {
698        $('.swiper-main-container').removeClass('swiper-main-container-full');
699        $('body').removeClass('overflowhidden');
700    }, 300);
701
702    alienSliderPos = 0;
703    swiper.params.paginationType = 'bullets';
704
705    setTimeout(function () {
706        swiper.update();
707        swiper.onResize();
708        $('.swiper-container-over').fadeOut("slow");
709    }, 800);
710
711    /*prev button*/
712    if ($(".productsidebar").length) {
713        var divWnow = $(".productsidebar").innerWidth();
714        $(".swiper-button-prev").css({ "left": "-" + divWnow + "px" });
715    }
716});
717
718function open_img_fullscreen_slider() {
719    var bigimg = $("div.swiper-slide-active > div").attr('data-bg-img-zoom');
720    var divgallery12 = "<div id='openIMGproductFull' style='background-image: url(" + bigimg + ")' class='gallery-pop-up'></div>";
721    $("body").prepend(divgallery12);
722    $("body").addClass("overflowhidden-addons");
723    $("#openIMGproductFull").fadeIn();
724}
725
726function init_catalog() {
727    var titleFixedCatalog = $('.js-title-fixed-catalog');
728    if (!titleFixedCatalog.length) {
729        return;
730    }
731
732    function redraw() {
733        var width = $('.js-right-not-fixed-content').width();
734        titleFixedCatalog.width(width);
735    }
736    redraw();
737    $(window).resize(redraw);
738}
739
740function init_catalog_images() {
741    var $image_effects = $('.catalogimgeffects');
742    var $product_side_bar = $('.productsidebar');
743
744    if (!$image_effects.length && !$product_side_bar.length) {
745        return;
746    }
747
748    if ($image_effects.length) {
749        $(window).scroll(function () {
750            var op = (100 - ($(window).scrollTop() * 100 / ($('.alien-bg-img-cont').outerHeight() - 80))) / 100;
751            $image_effects.css("opacity", op);
752        });
753    }
754
755    if (!$product_side_bar.length)
756        return;
757
758    function adjust_width() {
759        var width = $product_side_bar.innerWidth();
760        $(".swiper-button-prev").css({ "left": "-" + width + "px" });
761    }
762    $(window).resize(function () {
763        adjust_width();
764    });
765    adjust_width();
766}
767
768function init_inquire() {
769    var modal = $('.inquiremodal'),
770        productname = $('.js-inquireform__productname'),
771        productsku = $('.js-inquireform__productsku');
772
773    function inquireShow(name, sku) {
774        productname.text(name);
775        productsku.val(sku);
776
777        if (typeof window.syncBandaRefHiddenInputs === "function") {
778            window.syncBandaRefHiddenInputs();
779        }
780
781        modal.addClass('shown');
782    }
783    function inquireHide() {
784        modal.removeClass('shown');
785    }
786
787    $(document).on('click touchend', '.js-inquire-open', function (event) {
788        event.preventDefault();
789        event.stopPropagation();
790        var name = $(this).data('name');
791        var sku = $(this).data('sku');
792        inquireShow(name, sku);
793    });
794
795    $(document).on('click touchend', '.js-inquire-close', function (event) {
796        event.preventDefault();
797        event.stopPropagation();
798        inquireHide();
799    });
800}
801
802function init_newsletter_modal() {
803    var modal = $('#newsletterModal');
804    if (!modal.length) return;
805
806    var hideTimer = null;
807    var form = modal.find('.newsletter-form').get(0);
808
809    function clearHideTimer() {
810        if (hideTimer) {
811            clearTimeout(hideTimer);
812            hideTimer = null;
813        }
814    }
815
816    function resetNewsletterModal() {
817        clearHideTimer();
818        modal.removeClass('is-success');
819        if (form) {
820            form.reset();
821        }
822    }
823
824    function newsletterShow() {
825        resetNewsletterModal();
826        modal.addClass('open').attr('aria-hidden', 'false');
827        $('body').addClass('newsletter-modal-open');
828    }
829
830    function newsletterHide() {
831        resetNewsletterModal();
832        modal.removeClass('open').attr('aria-hidden', 'true');
833        $('body').removeClass('newsletter-modal-open');
834    }
835
836    function newsletterThankYou() {
837        modal.addClass('is-success');
838        clearHideTimer();
839        hideTimer = setTimeout(newsletterHide, 10000);
840    }
841
842    $(document).on('click touchend', '.js-newsletter-open', function (event) {
843        event.preventDefault();
844        event.stopPropagation();
845        newsletterShow();
846    });
847
848    $(document).on('click touchend', '.js-newsletter-close', function (event) {
849        event.preventDefault();
850        event.stopPropagation();
851        newsletterHide();
852    });
853
854    $(document).on('keydown', '.js-newsletter-close', function (event) {
855        if (event.key === 'Enter' || event.key === ' ') {
856            event.preventDefault();
857            newsletterHide();
858        }
859    });
860
861    modal.on('click', function (event) {
862        if (event.target === this) {
863            newsletterHide();
864        }
865    });
866
867    $(document).on('keydown', function (event) {
868        if (event.key === 'Escape' && modal.hasClass('open')) {
869            newsletterHide();
870        }
871    });
872
873    modal.on('submit', '.newsletter-form', function () {
874        newsletterThankYou();
875    });
876}
877
878function init_catalog_rolldown() {
879    $(document).on('click touchend', '.product__item__rollover', function (event) {
880        event.preventDefault();
881        var href = $(this).data('href');
882        document.location = href;
883    });
884    $(document).on('click touchend', '.product__item__inquire__caption', function (event) {
885        event.preventDefault();
886        event.stopPropagation();
887        $(this).closest('.product__item__inquire').find('.product__item__inquire__rolldown').toggleClass('product__item__inquire__rolldown--shown');
888    });
889    $(document).on('click touchend', '.product__item__inquire__item', function (event) {
890        event.preventDefault();
891        event.stopPropagation();
892    });
893}
894
895
896
897function init_catalog_add2myrugs() {
898    $(document).on('click touchend', '.js-add2myrugs', function (event) {
899        event.preventDefault();
900        event.stopPropagation();
901
902        var link = $(this),
903            section = link.data('section'),
904            ac = link.data('ac'),
905            ID = link.data('id'),
906            idText = String(ID),
907            links = $('.js-add2myrugs').filter(function () {
908                return String($(this).data('id')) === idText;
909            }),
910            linkAdd = links.filter(function () {
911                return $(this).data('ac') == 'add2wishlist';
912            }),
913            linkRemove = links.filter(function () {
914                return $(this).data('ac') == 'remove_from_wishlist';
915            });
916
917        if (link.data('loading')) {
918            return false;
919        }
920
921        // Change text
922        link.data('oldText', link.html());
923        link.data('loading', true);
924        link.text(link.data('loadingText'));
925
926        $.ajax({
927            url: '/',
928            type: 'GET',
929            data: {
930                section: section,
931                ac: ac,
932                ID: ID
933            }
934        })
935            .done(function (res) {
936                var responseText = $.trim(String(res || ''));
937                // show login form
938                if (responseText == idText + '-Please login to perform this operation!' || responseText.indexOf('Please login') !== -1) {
939                    $('.topmenu__dropdown').removeClass('shown');
940                    $('.topmenu__dropdown--accbo').addClass('shown');
941                    // Close other menus
942                    $('.woven-menu-hold').removeClass('woven-menu-hold');
943                    var dropdown = $('.login_menu').closest('li').find('.drobdownmenu');
944                    dropdown.addClass('woven-menu-hold');
945
946                    setTimeout(function () { dropdown.find('input:visible:not(disabled):first').trigger('focus'); }, 300);
947                    link.text('PLEASE LOGIN');
948                    return false;
949                } else if (responseText == idText || responseText.indexOf(idText) !== -1) {
950                    // ok
951                    if (ac == 'add2wishlist') {
952                        linkAdd.hide();
953                        linkRemove.show();
954                    } else if (ac == 'remove_from_wishlist') {
955                        linkAdd.show();
956                        linkRemove.hide();
957                    }
958                } else {
959                    console.warn('Unexpected response', res);
960                }
961            })
962            .always(function () {
963                // Return text
964                link.html(link.data('oldText'));
965                link.removeData('oldText');
966                link.removeData('loading');
967            });
968
969    });
970}
971
972// function init_top_menu() {
973//     var $menu = $('.menu-hide-show');
974//     var $header = $('header');
975//     var $menu_btn = $('.menu-hide-show-button');
976//     var $menu_holder = $(".woven-menu-holder");
977
978//     var $inner_holder = $(".woven-menu-inner-holder");
979//     var $inner_content = $('.woven-menu-inner-content');
980
981//     var $w = $(window);
982//     var $b = $('body');
983
984//     var full_height_element_open = 0;
985
986//     $menu_btn.click(function(event) {
987//         event.preventDefault();
988
989//         var shown = $menu_btn.data('shown') ? 1 : 0;
990//         $menu_btn.data('shown', 1 - shown);
991//         if (!shown) {
992//             $menu.addClass("menu-hide-show-visible");
993//             $header.removeClass("main-menu-holder-border");
994//             return false;
995//         }
996//         $header.addClass("main-menu-holder-border");
997//         $menu.removeClass("menu-hide-show-visible");
998//         return false;
999//     });
1000
1001//     function MenuW() {
1002//         $('.drobdownmenu').each(function() {
1003//             var x = $(this).offset();
1004//             var width = $(window).width() - x.left;
1005//             $(this).css("width", width);
1006//         });
1007//     }
1008
1009//     $w.resize(function() {
1010//         setTimeout(function() { MenuW(); }, 600);
1011//     });
1012
1013//     function menu_load(event) {
1014//         event.preventDefault();
1015
1016//         var $t = $(this);
1017//         if ($t.attr('id') == 'woven-news-click' || $t.data('menu-hold') == 'true') {
1018//             $('.woven-menu-hold').removeClass('woven-menu-hold');
1019//             $menu_holder.addClass("woven-menu-hold");
1020//         }
1021
1022//         var getAjaxUrl = $t.data('ajax-url') ? '/static/?get=' + encodeURIComponent($t.data('ajax-url')) : $t.attr('href');
1023
1024//         $inner_content.fadeOut(250);
1025
1026//         $.ajax({
1027//             url: getAjaxUrl
1028//         }).done(function(res) {
1029//             $inner_holder.html(res);
1030//             var $inner_content = $(".woven-menu-inner-content");
1031
1032//             MenuW();
1033
1034//             full_height_element_open = $inner_content.data('full-height') ? 1 : 0;
1035//             if (full_height_element_open) {
1036//                 $b.addClass("overflowhidden-addons");
1037//             } else {
1038//                 $b.removeClass("overflowhidden-addons");
1039//             }
1040
1041//             $inner_content.fadeIn(250);
1042
1043//             if ($inner_content.data('remove-class')) {
1044//                 $menu_holder.removeClass('woven-menu-hold');
1045//             } else {
1046//                 $menu_holder.addClass('woven-menu-hold');
1047//             }
1048
1049//         });
1050//         load_myrugs_form();
1051//         return false;
1052//     }
1053
1054//     //
1055//     // $('.scrollbox--main').on('scroll', function(event) {
1056//     //     event.preventDefault();
1057//     //     $('.js-main-menu-change-color').css('color', ($(this).scrollLeft() > ($('html').outerWidth() * 3.5)) ? '#000' : '#FFF');
1058//     // });
1059
1060//     $(document).on("click", ".menu-ajax-click", menu_load);
1061
1062//     MenuW();
1063//     // menuwindowsH();
1064
1065
1066
1067//     $(document).on('click', '.js-open-stories', function(event) {
1068//         event.preventDefault();
1069//         menu_load();
1070//     });
1071
1072//     $(document).on('click', '.js-inquiry-close', function(event) {
1073//         event.preventDefault();
1074//         $('.woven-menu-hold').removeClass('woven-menu-hold');
1075//     });
1076
1077// }
1078
1079
1080//Main page "train" logic
1081function init_main_train() {
1082    var trainHolder = $('#trainHolder');
1083    if (!trainHolder.length) {
1084        return;
1085    }
1086
1087    $('.horizon-next').click(function (event) {
1088        event.preventDefault();
1089        trainHolder.animate({ scrollLeft: '+=' + $(window).width() / 2 }, 400);
1090    });
1091
1092    $('.horizon-prev').click(function (event) {
1093        event.preventDefault();
1094        trainHolder.animate({ scrollLeft: '-=' + $(window).width() / 2 }, 400);
1095    });
1096
1097    // Following is a weird patch.
1098    // Don't remove!
1099
1100    setTimeout(function () {
1101        $('svg').css('position', 'relative');
1102        $('svg').css('position', 'absolute');
1103        setTimeout(function () {
1104            $('svg').css('position', 'absolute');
1105        }, 1400);
1106    }, 1200);
1107}
1108
1109function init_filter_tree() {
1110    var $filterForm = $('.js-filter-form');
1111    if (!$filterForm.length)
1112        return;
1113    var $products_container = $('#right-not-fixed-content');
1114    var $side_filter_block = $('.aside__filter');
1115    var $side_filter_form = 0;
1116    if ($side_filter_block.length)
1117        $side_filter_form = $side_filter_block.find('.js-filter-form');
1118    else
1119        $side_filter_form = $($filterForm.get(0));
1120
1121    //debugger;
1122
1123    function filter_loading(val) {
1124        var $left_fixed_bar = $('#left-fixed-bar')
1125        if (val) {
1126            $left_fixed_bar.addClass('js-loading');
1127            return;
1128        }
1129        $left_fixed_bar.removeClass('js-loading');
1130    }
1131
1132    function jump2products_with_hash() {
1133        var $cat_tag = $side_filter_form.find('input[name="CAT_TAG"]').val();
1134        if ($cat_tag != '') $cat_tag += '/';
1135        window.location = sitehome + 'products/' + $cat_tag + '#' + window.location.hash;
1136        return false;
1137    }
1138
1139    function jump2products_with_search($search_form2submit) {
1140        if (!($search_form2submit.parents('#advSearchWrapper').length || !$products_container.length))
1141            return false;
1142        //If this is a right pop-up or we're not on a products page...
1143        $search_form2submit.find('input[name="CAT_TAG"]').val('');
1144        window.location = sitehome + 'products/?' + $search_form2submit.serialize();
1145        return true;
1146
1147    }
1148
1149    function apply_hash_to_left_filter() {
1150        try {
1151            var hash = window.location.hash;
1152            if (!hash || (hash.length < 2))
1153                return false;
1154            if (hash.indexOf('%')) {
1155                hash = decodeURIComponent(hash);
1156                if (hash.substr(-1) != '|')
1157                    hash += '|';
1158            }
1159
1160            var filterHash = hash.match(/\|nav\|(.*)\|nav\|/);
1161            //In case there is no hash at all
1162            if (filterHash == null) return true;
1163            //In case the hash doesn't match
1164            if (!(filterHash.length === 2))
1165                return true;
1166
1167            var filterHashValues = filterHash[1].split('|');
1168            var filterInput = $side_filter_form.find(':input:not(:submit)');
1169            if (filterInput.length != filterHashValues.length)
1170                throw 'hash values count does not match form fields count';
1171
1172            $.each(filterInput, function (index, val) {
1173                $(this).val(filterHashValues[index]);
1174            });
1175
1176            //If there is no left filter form, we jump to a place where there is.
1177            if (!$side_filter_block.length)
1178                jump2products_with_hash();
1179
1180            //If left form is here, let's submit it and get the right side loaded
1181            $side_filter_form.trigger('submit');
1182        } catch (e) { console.log(e); }
1183        return true;
1184    }
1185
1186    function left_filter_to_hash($search_form2submit) {
1187        try {
1188            var data = $search_form2submit.serializeArray();
1189            var hashes = data.map(function (elem) {
1190                return elem['value'];
1191            }).join('|');
1192            var hash = '#|nav|' + hashes + '|nav|';
1193            window.location.hash = hash;
1194        } catch (e) { console.log(e); }
1195    }
1196
1197    function apply_left_filter($search_form2submit, load_categories) {
1198        if (!$search_form2submit) return;
1199
1200        var $cat_field = $search_form2submit.find('input[name="CAT_TAG"]');
1201        var url = $search_form2submit.serialize();
1202        if ($cat_field.length)
1203            url += '&params[cat_id]=' + $cat_field.val();
1204
1205        filter_loading(true);
1206        left_filter_to_hash($search_form2submit);
1207        var list_name = 'products';
1208        if (load_categories) {
1209            list_name = 'categories_studio'
1210            $('.js_studio_root_menu').hide();
1211        }
1212        $products_container.hide();
1213        $.get(sitehome + '?ac=list&name=' + list_name + '&section=products&' + url, function (res) {
1214            $products_container.html(res);
1215            $products_container.show();
1216            filter_loading(false);
1217            //if(!load_categories)
1218            $('.js_studio_root_menu').hide();
1219        }).success(function (result) { init_gohez(); $('.catalog-desc').css('margin-top', '0'); }).error(function (jqXHR, textStatus, errorThrown) { filter_loading(false); });
1220        return false;
1221    }
1222
1223    function verify_filter_form_exists() {
1224        if (!$side_filter_form || !$side_filter_form.length) {
1225            console.log('Left search form is missing!')
1226            return false;
1227        }
1228        return true;
1229    }
1230
1231    function some_werid_action_that_makes_no_sense() {
1232        $('.topmenu.topmenu--gray .topmenu__dropdown').removeClass('shown');
1233        $('.topmenu .topmenu__dropdown--white').removeClass('shown')
1234    }
1235
1236    function origin_toggle_current($link) {
1237        $('.js-load-filter-tree').removeClass('current');
1238        $link.addClass('current');
1239    }
1240
1241    function set_left_filter_form_field_value(f_name, $v) {
1242        $side_filter_form.find('input[name="' + f_name + '"]').val($v);
1243    }
1244
1245    function load_li4feft_menu_origin_filter($link, data, i) {
1246        var $li = $link.closest('li');
1247        var id = $link.data('parent_id');
1248        $li.find('ul').remove();
1249        $.get('/?ac=list&name=ajax_catalog_filter_subcategories&PARENT_ID=' + id, function (res) {
1250            origin_toggle_current($link);
1251            if (res == '') {
1252                some_werid_action_that_makes_no_sense();
1253                return;
1254            }
1255            $(res).insertAfter($link);
1256            if (data && data.length && i < data.length) {
1257                $link = get_li_by_seo_title(data[i].SEO_TITLE);
1258                load_li4feft_menu_origin_filter($link, data, i + 1)
1259            }
1260        }).success(function (result) { init_gohez(); loadingThroughTheLeftFilter = false; });
1261    }
1262
1263
1264    function get_li_by_seo_title(SEO_TITLE) {
1265        var $res = $('.js-load-filter-tree[data-id="' + SEO_TITLE + '"]');
1266        if (!$res.length) return false;
1267        return $res;
1268    }
1269
1270    function load_all_origins4SEO_TITLE(SEO_TITLE) {
1271        //debugger;
1272        var $link = get_li_by_seo_title(SEO_TITLE);
1273        if ($link) {
1274            load_li4feft_menu_origin_filter($link)
1275            return;
1276        }
1277
1278
1279        $.getJSON('/products/?ac=getcatpath&SEO_TITLE=' + SEO_TITLE, function (data) {
1280            if (data['status'] == 'OK' && data['data'].length) {
1281                $link = get_li_by_seo_title(data['data'][0].SEO_TITLE);
1282                if (!$link) {
1283
1284                    console.log(data);
1285                    console.log('Link not found for ' + data['data'][0].SEO_TITLE);
1286                    return false;
1287                }
1288                load_li4feft_menu_origin_filter($link, data['data'], 1);
1289                return;
1290            }
1291            console.log(data);
1292        });
1293    }
1294
1295    $(document).on('click', '[data-filter-layout]', function (event) {
1296        event.preventDefault();
1297        if (!verify_filter_form_exists()) return false;
1298        set_left_filter_form_field_value('LAYOUT', $(this).data('filterLayout'));
1299        apply_left_filter($side_filter_form, 0);
1300        some_werid_action_that_makes_no_sense();
1301
1302    });
1303
1304    $(document).on('click', '[data-filter-category]', function (event) {
1305        event.preventDefault();
1306        if (!verify_filter_form_exists()) return false;
1307        set_left_filter_form_field_value('CATEGORY', $(this).data('filterCategory'));
1308        apply_left_filter($side_filter_form, 0);
1309        some_werid_action_that_makes_no_sense();
1310    });
1311
1312    $(document).on('submit', '.js-search_by_rug_id', function (event) {
1313        event.preventDefault();
1314        var form = $(this);
1315        form.find('.form_err_message').hide();
1316        $.get('/?' + form.serialize() + '&r=' + Math.random(), function (res) {
1317            if (res.res == 'ERROR') {
1318                form.find('.form_err_message.ajax_error').removeClass('hidden').show().text(res.error);
1319                return;
1320            }
1321            window.location = sitehome + res.data.URL;
1322        });
1323    });
1324
1325    apply_hash_to_left_filter();
1326    if ($side_filter_block.length)
1327        load_all_origins4SEO_TITLE($side_filter_form.find('input[name="CAT_TAG"]').val());
1328}
1329
1330function initLoadFilterTree() {
1331    $(document).on('click', '.js_sub_item__subcategories', function (e) {
1332        e.preventDefault();
1333        let id = $(this).data('id');
1334        leftLinkTrigger(id);
1335        return false
1336    });
1337}
1338
1339function leftLinkTrigger(idLink) {
1340    $('.menu-level a[data-id="' + idLink + '"]').trigger('click');
1341}
1342
1343function init_share() {
1344    $(document).on('click', '.share_toggle', function (event) {
1345        event.preventDefault();
1346        $(this).parent().find('.share_popup').toggleClass('share_popup--shown');
1347    });
1348
1349}
1350
1351function load_myrugs_form() {
1352    $('.js-myrugs-link').css('display', 'none');
1353
1354    $('input[type="checkbox"][data-field]').each(function () {
1355        if (!$(this).prop('checked')) {
1356            return;
1357        }
1358        $('.js-myrugs-link[data-active-field="' + $(this).data('field') + '"]').css('display', 'block');
1359    });
1360}
1361
1362function init_contact_form() {
1363    var $how_fields = $('.js-howchange_field');
1364    if (!$how_fields.length) return;
1365
1366    $how_fields.change(function () {
1367        var $selectBox = $(this)
1368        var alt_opt_id = $selectBox.data('alt_id');
1369        var $alt_field = $selectBox.parents('form').find('.' + alt_opt_id);
1370        if (!$alt_field.length) return;
1371
1372        var selected = $selectBox.val();
1373
1374        if (selected === 'Other') {
1375            $alt_field.show().addClass('mandatory').prop('disabled', false);
1376            return;
1377        }
1378        $alt_field.hide().removeClass('mandatory').prop('disabled', true);
1379    });
1380
1381
1382}
1383
1384function init_login_form() {
1385    let $loginForm = $('.js-form-login');
1386    let $registerForm = $('.js-form-register');
1387    let $forgotForm = $('.js-form-forgot');
1388    let $profileForm = $('.js-form-profile');
1389    var $account_area = $('.js-form-account');
1390
1391    function load_profile_form() {
1392        window.document.location.href = '/acc_profile/';
1393        return;
1394    }
1395
1396    function process_form_error($form, error) {
1397        var $err = $form.find('.error_mess.ajax_errors');
1398        $err.text('Error: ' + error);
1399        if (error == 'err_wrong_login')
1400            $err.text('Wrong email or password ');
1401        if (error == 'reg_err_code_LOGIN_NOT_UNIQUE')
1402            $err.text('Account with this email already exists.');
1403        if (error == 'err_acc_not_found')
1404            $err.text('Account not found');
1405        if (error == 'reg_err_code_PASSWORD_EMPTY')
1406            $err.text('Password cannot be empty');
1407        $form.find('.error_mess.ajax_errors').show();
1408    }
1409
1410    function login_on($form) {
1411        var next = $form.data('next');
1412        if (!next) next = 'acc_account';
1413        if (/^https?:\/\//i.test(next) || next.indexOf('/') === 0) {
1414            window.document.location.href = next;
1415            return;
1416        }
1417
1418        var base = $form.find('.siteHomeInput').val();
1419        if (!base && typeof sitehome !== 'undefined') {
1420            base = sitehome;
1421        }
1422        if (!base) {
1423            base = '/';
1424        }
1425
1426        window.document.location.href = base.replace(/\/+$/, '/') + next.replace(/^\/+|\/+$/g, '') + '/';
1427    }
1428
1429    function validate_formb4_send($form) {
1430        // console.log('submit');
1431        $form.find('.error_mess.ajax_errors').text('');
1432        $form.find('.error_mess').hide('fast');
1433        $('.forgot_pass_message').hide();
1434        if (!validate_any_form($form.get(0)))
1435            return false;
1436        return true;
1437    }
1438
1439    //$registerForm
1440    function send_form4login($form, func) {
1441        let data = $form.serialize();
1442        $.ajax({
1443            type: "POST",
1444            dataType: 'json',
1445            url: '/',
1446            data: data,
1447            success: function (res) {
1448                if (res.res === 'ERROR') {
1449                    process_form_error($form, res.error);
1450                    return;
1451                }
1452                if (res.res === 'OK') {
1453                    if (!func) {
1454                        login_on($form);
1455                    } else {
1456                        func($form);
1457                    }
1458                }
1459            }
1460        });
1461    }
1462
1463    $registerForm.submit(function (e) {
1464        e.preventDefault();
1465        $registerForm.find('.pass2').val($registerForm.find('.pass1').val());
1466        $registerForm.find('.pageURLinput').val();
1467
1468        if (!validate_formb4_send($registerForm)) {
1469            return false;
1470        }
1471
1472        function submit_register_form() {
1473            let r = Math.random();
1474            $.getJSON('/?section=contact_form&ac=ajax_code&json=1&rand=' + r, function (result) {
1475                $registerForm.find('input[name="AJAX_CODE"], input[name="ADR_SESS_ID"], input[name="ADR_SESS_UID"]').remove();
1476                $registerForm.append(result.code_field + result.session_fields);
1477                send_form4login($registerForm);
1478
1479                const webhookURL = "https://hook.us2.make.com/bu62vrn3ujzozfif98ubtuv4b1nviie6";
1480                let data = $registerForm.serialize();
1481                $.ajax({
1482                    type: "POST",
1483                    dataType: 'json',
1484                    url: webhookURL,
1485                    data: data,
1486                    success: function (res) {
1487                        console.log('Webhook response:', res);
1488                    },
1489                    error: function (err) {
1490                        console.log('Webhook error:', err);
1491                    }
1492                });
1493            });
1494        }
1495
1496        if (typeof window.adrecom_execute_recaptcha === 'function') {
1497            window.adrecom_execute_recaptcha($registerForm, 'register_register', submit_register_form, function (message) {
1498                process_form_error($registerForm, message);
1499            });
1500        } else {
1501            submit_register_form();
1502        }
1503
1504        return false;
1505
1506    });
1507
1508    $loginForm.submit(function (event) {
1509        event.preventDefault();
1510        var $form = $(this);
1511        // console.log('submit');
1512        if (!validate_formb4_send($form))
1513            return false;
1514        send_form4login($form);
1515        return false;
1516    });
1517
1518
1519
1520    $forgotForm.submit(function (e) {
1521        e.preventDefault();
1522        if (!validate_formb4_send($forgotForm))
1523            return false;
1524        send_form4login($forgotForm, function () {
1525            window.document.location.href = '/login/?params[show_forgot_msg]=1';
1526        });
1527
1528    });
1529
1530    $profileForm.submit(function (e) {
1531        e.preventDefault();
1532        if (!validate_formb4_send($profileForm))
1533            return false;
1534        $.getJSON('/?' + $profileForm.serialize(), function (res) {
1535            if (res.res == 'ERROR') {
1536                process_form_error($profileForm, res.error);
1537                return;
1538            }
1539            if (res.res == 'OK') {
1540                $account_area.show('fast');
1541            }
1542        });
1543        return false;
1544    });
1545}
1546
1547/**
1548 * detect IE
1549 * returns version of IE or false, if browser is not Internet Explorer
1550 */
1551function detectIE() {
1552    var ua = window.navigator.userAgent;
1553
1554    // Test values; Uncomment to check result …
1555
1556    // IE 10
1557    // ua = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)';
1558
1559    // IE 11
1560    // ua = 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko';
1561
1562    // Edge 12 (Spartan)
1563    // ua = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0';
1564
1565    // Edge 13
1566    // ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586';
1567
1568    var msie = ua.indexOf('MSIE ');
1569    if (msie > 0) {
1570        // IE 10 or older => return version number
1571        return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
1572    }
1573
1574    var trident = ua.indexOf('Trident/');
1575    if (trident > 0) {
1576        // IE 11 => return version number
1577        var rv = ua.indexOf('rv:');
1578        return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
1579    }
1580
1581    var edge = ua.indexOf('Edge/');
1582    if (edge > 0) {
1583        // Edge (IE 12+) => return version number
1584        return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
1585    }
1586
1587    // other browser
1588    return false;
1589}
1590
1591
1592function detect_ff() {
1593    return navigator.userAgent.indexOf('Firefox') > -1;
1594}
1595
1596function init_index() {
1597
1598    if (!detectIE())
1599        return;
1600
1601
1602    var $all_trapezoids = $('.stories__item--is-trapezoid');
1603    $all_trapezoids.find('img').hide();
1604    $all_trapezoids.find('.scaled_polygon').each(function (i, obj) {
1605        var $t = $(obj);
1606        var points = '';
1607        var x = 0;
1608        var y = 0;
1609        var w = $t.data('pict_width');
1610        var h = $t.data('pict_height');
1611        for (var i = 0; i < $t.prop('points').numberOfItems; i++) {
1612            x = $t.prop('points').getItem(i).x;
1613            y = $t.prop('points').getItem(i).y;
1614            points += (x * w) + ' ' + (y * h) + ' ';
1615        }
1616        $t.attr('points', points);
1617    });
1618
1619
1620    function resize_all_trapezoids() {
1621        $all_trapezoids.find('svg').show().each(function (i, obj) {
1622            var $svg = $(obj);
1623            var $div = $svg.parent();
1624            var w = $svg.data('pict_width');
1625            var h = $svg.data('pict_height');
1626            $svg.width(((w / h) * $svg.height()));
1627        });
1628    }
1629
1630    resize_all_trapezoids();
1631
1632    $(window).on('resize', function () {
1633        resize_all_trapezoids();
1634    });
1635}

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.