lavkach3

Форк
0
184 строки · 7.4 Кб
1
const SideBarMenu = {
2
    sidebarMenu,
3
}
4

5
function sidebarMenu() {
6
    var at = document.documentElement.getAttribute("data-layout");
7
    if ((at = "vertical")) {
8
        // ==============================================================
9
        // Auto select left navbar
10
        // ==============================================================
11
        function loadSidebarPagesVertical() {
12
            "use strict";
13
            var isSidebar = document.getElementsByClassName("side-mini-panel");
14
            if (isSidebar.length > 0) {
15
                var url = window.location + "";
16
                var path = url.replace(
17
                    window.location.protocol + "//" + window.location.host + "/",
18
                    ""
19
                );
20

21
                //****************************
22
                // This is for
23
                //****************************
24

25
                function findMatchingElement() {
26
                    var currentUrl = window.location.href;
27
                    var anchors = document.querySelectorAll("#sidebarnav a");
28

29
                    for (var i = 0; i < anchors.length; i++) {
30
                        if (anchors[i].href === currentUrl) {
31
                            return anchors[i];
32
                        }
33
                    }
34

35
                    document.location.replace('/inventory/order'); // Return null if no matching element is found
36
                }
37

38
                var elements = findMatchingElement();
39

40
                if (elements) {
41
                    // Do something with the matching element
42
                    elements.classList.add("active");
43
                }
44

45
                //****************************
46
                // This is for the multilevel menu
47
                //****************************
48
                document.querySelectorAll("#sidebarnav a").forEach(function (link) {
49
                    link.addEventListener("click", function (e) {
50
                        const isActive = this.classList.contains("active");
51
                        const parentUl = this.closest("ul");
52

53
                        if (!isActive) {
54
                            // hide any open menus and remove all other classes
55
                            parentUl.querySelectorAll("ul").forEach(function (submenu) {
56
                                submenu.classList.remove("in");
57
                            });
58
                            parentUl.querySelectorAll("a").forEach(function (navLink) {
59
                                navLink.classList.remove("active");
60
                            });
61

62
                            // open our new menu and add the open class
63
                            const submenu = this.nextElementSibling;
64
                            if (submenu) {
65
                                submenu.classList.add("in");
66
                            }
67

68
                            this.classList.add("active");
69
                        } else {
70
                            this.classList.remove("active");
71
                            parentUl.classList.remove("active");
72
                            const submenu = this.nextElementSibling;
73
                            if (submenu) {
74
                                submenu.classList.remove("in");
75
                            }
76
                        }
77
                    });
78
                });
79

80
                document
81
                    .querySelectorAll("#sidebarnav > li > a.has-arrow")
82
                    .forEach(function (link) {
83
                        link.addEventListener("click", function (e) {
84
                            e.preventDefault();
85
                        });
86
                    });
87

88
                //****************************
89
                // This is for show menu
90
                //****************************
91

92
                var closestNav = elements.closest("nav[class^=sidebar-nav]");
93
                var menuid = (closestNav && closestNav.id) || "menu-right-mini-1";
94
                var menu = menuid.split('-').pop()
95

96

97

98
                document
99
                    .getElementById("menu-right-" + menu)
100
                    .classList.add("d-block");
101
                document.getElementById("mini-" + menu).classList.add("selected");
102

103
                //****************************
104
                // This is for mini sidebar
105
                //****************************
106
                document
107
                    .querySelectorAll("ul#sidebarnav ul li a.active")
108
                    .forEach(function (link) {
109
                        link.closest("ul").classList.add("in");
110
                        link.closest("ul").parentElement.classList.add("selected");
111
                    });
112
                document
113
                    .querySelectorAll(".mini-nav .mini-nav-item")
114
                    .forEach(function (item) {
115
                        item.addEventListener("click", function () {
116
                            var id = this.id.split('-').pop();
117
                            document
118
                                .querySelectorAll(".mini-nav .mini-nav-item")
119
                                .forEach(function (navItem) {
120
                                    navItem.classList.remove("selected");
121
                                });
122
                            this.classList.add("selected");
123
                            document
124
                                .querySelectorAll(".sidebarmenu nav")
125
                                .forEach(function (nav) {
126
                                    nav.classList.remove("d-block");
127
                                });
128
                            document.getElementById("menu-right-" + id)
129
                                .classList.add("d-block");
130
                            document.body.setAttribute("data-sidebartype", "full");
131
                        });
132
                    });
133
            }
134
        }
135
    }
136
    loadSidebarPagesVertical()
137

138
    if ((at = "horizontal")) {
139
        function loadSidebarPagesHorizontal() {
140
            function findMatchingElement() {
141
                var currentUrl = window.location.href;
142
                var anchors = document.querySelectorAll("#sidebarnavh ul#sidebarnav a");
143
                for (var i = 0; i < anchors.length; i++) {
144
                    if (anchors[i].href === currentUrl) {
145
                        return anchors[i];
146
                    }
147
                }
148

149
                return null; // Return null if no matching element is found
150
            }
151

152
            var elements = findMatchingElement();
153

154
            if (elements) {
155
                elements.classList.add("active");
156
            }
157
            document
158
                .querySelectorAll("#sidebarnavh ul#sidebarnav a.active")
159
                .forEach(function (link) {
160
                    link.closest("a").parentElement.classList.add("selected");
161
                    link.closest("ul").parentElement.classList.add("selected");
162
                });
163
        }
164
      loadSidebarPagesHorizontal()
165
    }
166
// ----------------------------------------
167
// Active 2 file at same time 
168
// ----------------------------------------
169

170
    var currentURL =
171
        window.location != window.parent.location
172
            ? document.referrer
173
            : document.location.href;
174

175
    var link = document.getElementById("get-url");
176

177
    if (currentURL.includes("/main/index.html")) {
178
        link.setAttribute("href", "../main/index.html");
179
    } else if (currentURL.includes("/index.html")) {
180
        link.setAttribute("href", "./index.html");
181
    } else {
182
        link.setAttribute("href", "./");
183
    }
184
}

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.