PageSourceSearch

https://knezha.bg/inc/themes/default/assets/multi-level-accordion-…/main.js?v=876a094ca81205db56181e3ee7421a8d

js knezha.bg collected 2026-10-03 02:28:00 UTC 6,454 bytes, 179 lines download raw bytes

1jQuery(document).ready(function () {
2    let accordionsMenu = $(".cd-accordion-menu");
3
4    accordionsMenu
5        .find("input[type='checkbox']")
6        .prop("checked", false);
7
8    if (accordionsMenu.length > 0) {
9        accordionsMenu.each(function () {
10
11            let accordion = $(this);
12
13            let isHorizontalMenu = accordion
14                .parent()
15                .hasClass("accordion-horizontal");
16
17            if (isHorizontalMenu)
18                InitMenuItemMeasureHandles(accordion);
19
20            const reducedMotionMediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)");
21            const reducedMotion = !reducedMotionMediaQuery || reducedMotionMediaQuery.matches;
22
23            // Detect change in the input[type='checkbox'] value.
24            accordion.on("change", "input[type='checkbox']", function () {
25                let checkbox = $(this);
26
27                if (isHorizontalMenu) {
28                    let otherCheckboxes = checkbox
29                        .parent() // li
30                        .parent() // ul
31                        .find("input[type='checkbox']:checked")
32                        .not(checkbox)
33                        .prop("checked", false)
34                        .siblings("ul");
35
36                    if (reducedMotion)
37                        otherCheckboxes.hide();
38                    else
39                        otherCheckboxes.slideUp(300);
40                }
41
42                let dropdown = checkbox.siblings("ul");
43
44                let parentUL = dropdown
45                    .parent()
46                    .parent();
47
48                if (checkbox.prop("checked")) {
49                    if (isHorizontalMenu)
50                        ResizeMenu(accordion, dropdown);
51                    if (reducedMotion)
52                        dropdown.show();
53                    else
54                        dropdown.slideDown(300);
55                } else {
56                    if (reducedMotion) {
57                        dropdown.hide();
58                        dropdown.removeClass("menu-width-15 menu-width-20 menu-width-25");
59
60                        if (isHorizontalMenu)
61                            ResizeMenu(accordion, parentUL);
62                    } else {
63                        dropdown.slideUp(300, function () {
64                            dropdown.removeClass("menu-width-15 menu-width-20 menu-width-25");
65
66                            if (isHorizontalMenu)
67                                ResizeMenu(accordion, parentUL);
68                        });
69                    }
70                }
71
72                if (isHorizontalMenu && parentUL.hasClass("cd-accordion-menu")) {
73                    const maxPossibleWidth = parseInt($("html").css("font-size")) * 25; /* e.g. 16px * 25rem = 400px */
74                    const rightmostPoint = checkbox.parent().offset().left + maxPossibleWidth + 8; /* Also account for possible left border. */
75
76                    if ($(window).width() <= rightmostPoint)
77                        dropdown.css("right", "0");
78                    else
79                        dropdown.css("left", "0");
80                }
81            });
82
83            accordion.on("keydown", "li.has-children", function (e) {
84                let li = $(this);
85
86                if (e.keyCode === 32 || e.keyCode === 13) {
87                    li.children("input[type='checkbox']").each(function () {
88                        $(this).prop("checked", !$(this).prop("checked")).change();
89                    });
90                    return false;
91                }
92            });
93        });
94    }
95});
96
97function ResizeMenu(accordion, dropdown) {
98    if (dropdown.hasClass("cd-accordion-menu"))
99        return;
100
101    let maxWidthInPx = 0;
102
103    dropdown.children("li").each(function () {
104        let id = $(this).data("measurement-handle-id");
105        let width = $("[data-measurement-id='" + id + "']").width();
106        if (width > maxWidthInPx)
107            maxWidthInPx = width;
108    });
109
110    let widthInRem = maxWidthInPx / parseInt($("html").css("font-size"));
111    const minWidthInRem = 15;
112    const maxWidthInRem = 25;
113    let clampedWidthInRem = Math.max(minWidthInRem, Math.min(widthInRem, maxWidthInRem));
114
115    let classToAdd = "menu-width-20";
116
117    if (widthInRem < 15)
118        classToAdd = "menu-width-15";
119    else if (widthInRem < 20)
120        classToAdd = "menu-width-20";
121    else
122        classToAdd = "menu-width-25";
123
124    let parentUL = dropdown
125        .parent()  // li
126        .parent(); // ul
127    if (!parentUL.hasClass("cd-accordion-menu")) {
128        let parentWidthInRem = parseInt(parentUL.css("width")) / parseInt($("html").css("font-size"));
129
130        if (parentWidthInRem > clampedWidthInRem) {
131            let parentClass = GetMenuWidthClass(parentUL);
132            dropdown.removeClass("menu-width-15 menu-width-20 menu-width-25");
133            dropdown.addClass(parentClass);
134        } else {
135            parentUL.removeClass("menu-width-15 menu-width-20 menu-width-25");
136            parentUL.addClass(classToAdd);
137        }
138    } else {
139        dropdown.removeClass("menu-width-15 menu-width-20 menu-width-25");
140        dropdown.addClass(classToAdd);
141    }
142}
143
144function GetMenuWidthClass(dropdown) {
145    if (dropdown.hasClass("menu-width-15"))
146        return "menu-width-15";
147    if (dropdown.hasClass("menu-width-20"))
148        return "menu-width-20";
149    if (dropdown.hasClass("menu-width-25"))
150        return "menu-width-25";
151    return "";
152}
153
154function InitMenuItemMeasureHandles(accordion) {
155    let dropdownItems = accordion
156        .children(".has-children")
157        .find("li");
158    let handlesContainer = $("<div/>")
159        .css({
160            "width": "100%",
161            "overflow": "hidden",
162            "height": "0"
163        })
164        .appendTo($("body"));
165    dropdownItems.each(function (index) {
166        $(this)
167            .attr("data-measurement-handle-id", index)
168            .data("measurement-handle-id", index);
169        $("<span/>")
170            .text($(this).find("> label, > a").text().trim())
171            .css({
172                "white-space": "nowrap",
173                "visibility": "hidden"
174            })
175            .attr("data-measurement-id", index)
176            .data("measurement-id", index)
177            .appendTo(handlesContainer);
178    });
179}

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.