PageSourceSearch

https://www.intimina.com/themes/uhura/components_iblocks/_js/modules/_sticky-taxonomy-menu.js?tlhseu

js intimina.com collected 2026-10-03 22:11:49 UTC 4,010 bytes, 120 lines download raw bytes

1(function ($, Drupal) {
2  if ($(".taxonomy-menu").length) {
3    let taxonomyMenu = $(".taxonomy-menu");
4    let taxMenuPlaceholder = $(".taxonomy-menu-placeholder");
5    let taxonomyMenuHeight = taxonomyMenu.outerHeight();
6    let taxonomyMenuDistance;
7
8    let shopArray = Array.from($(".shop-category-section[id]"));
9    let shopIds = shopArray.map((element) => element.id);
10
11    let taxonomyMenuArray = Array.from($(".taxonomy-menu a[href^='#']"));
12    let taxonomyElements = taxonomyMenuArray.map((element) =>
13      element.innerHTML.split(" ").join("-").toLowerCase()
14    );
15
16    taxonomyElements.forEach((element) => {
17      if (!shopIds.includes(element)) {
18        $(`.taxonomy-menu a[href="#${element}"]`)
19          .parents(".views-row")
20          .remove();
21      }
22    });
23
24    if (window.matchMedia("(max-width: 768px)").matches) {
25      taxonomyMenuDistance = taxonomyMenu.offset().top + 26 - 65;
26    } else {
27      taxonomyMenuDistance = taxonomyMenu.offset().top + 26;
28    }
29    taxMenuPlaceholder.css("height", taxonomyMenuHeight);
30
31    let prevScrollPos = $(window).scrollTop();
32    // Initialize scrollPos with the previous scroll position
33    let scrollPos = prevScrollPos;
34
35    $(window).scroll(function () {
36      scrollPos = $(window).scrollTop();
37
38      if (scrollPos >= taxonomyMenuDistance) {
39        taxonomyMenu.addClass("sticky");
40      } else {
41        taxonomyMenu.removeClass("sticky");
42      }
43
44      // When scrolling down remove first active element to avoid duplication
45      if (scrollPos > prevScrollPos) {
46        let activeElements = $(".taxonomy-menu .views-row a.active");
47        if (activeElements.length > 1) {
48          activeElements.not(":last").removeClass("active");
49        }
50      }
51      // When scrolling up remove second active element to avoid duplication
52      else if (scrollPos < prevScrollPos) {
53        let activeElements = $(".taxonomy-menu .views-row a.active");
54        //if user scrolled up - remove last
55        if (activeElements.length > 1 && !clicked) {
56          activeElements.last().removeClass("active");
57        } else if (activeElements.length > 1 && clicked) {
58          //if user clicked remove class from the element before clicked element
59          activeElements.first().removeClass("active");
60        }
61      }
62
63      // Update the previous scroll position
64      prevScrollPos = scrollPos;
65    });
66
67    //flag for checking if user clicked or scrolled - when user clicked - true, when scrolled - false
68    let clicked = false;
69
70    $(".taxonomy-menu").on("click", 'a[href^="#"]', function (event) {
71      event.preventDefault();
72      clicked = true;
73      let clickedElement = this;
74      $("html, body").animate(
75        {
76          scrollTop:
77            $($.attr(this, "href")).offset().top - 26 - taxonomyMenuHeight - 20,
78        },
79        500,
80        function () {
81          setTimeout(function () {
82            // Toggle flag
83            clicked = false;
84            // if user clicked remove all but clickedElement
85            $(clickedElement).addClass("active");
86            $(".taxonomy-menu a[href^='#']")
87              .not(clickedElement)
88              .removeClass("active");
89          }, 1500);
90        }
91      );
92    });
93
94    let toolbarHeight = taxonomyMenuHeight + 65 + 44;
95    let rootMargString = `${-toolbarHeight}px 0px -500px 0px`;
96
97    let options = {
98      root: null,
99      rootMargin: rootMargString,
100      threshold: 0,
101    };
102
103    const observer = new IntersectionObserver((entries) => {
104      entries.forEach((entry) => {
105        const id = entry.target.getAttribute("id");
106        if (entry.intersectionRatio > 0) {
107          $(`.taxonomy-menu .views-row a[href="#${id}"]`).addClass("active");
108        } else {
109          $(`.taxonomy-menu .views-row a[href="#${id}"]`).removeClass("active");
110        }
111      });
112    }, options);
113
114    document
115      .querySelectorAll(".shop-category-section[id]")
116      .forEach((section) => {
117        observer.observe(section);
118      });
119  }
120})(jQuery, Drupal);

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.