-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
189 lines (165 loc) · 5.92 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*=============== LODING SCREEN ===============*/
window.addEventListener("load", function () {
const loader = document.querySelector(".loader");
loader.className += " hidden";
});
/*=============== SILDE MENU ===============*/
$(document).ready(function () {
// Variables for dragging
var isDragging = false;
var startX, scrollLeft;
// Variables for long press
var pressTimer;
var scrollSpeed = 20;
// Handle mousedown/touchstart event on tabs-box
$(".tabs-box").on("mousedown touchstart", function (event) {
// Set isDragging to true and record initial values
isDragging = true;
startX =
event.type === "touchstart"
? event.touches[0].pageX - $(".tabs-box").offset().left
: event.pageX - $(".tabs-box").offset().left;
scrollLeft = $(".tabs-box").scrollLeft();
// Set press timer to increase scroll speed if button is long pressed
pressTimer = setTimeout(function () {
scrollSpeed = 40; // Increase scroll speed
}, 500); // Change time as needed
});
// Handle mousemove/touchmove event on tabs-box
$(".tabs-box").on("mousemove touchmove", function (event) {
// If isDragging is true, calculate the new scroll position and set it
if (isDragging) {
var mousePos =
event.type === "touchmove"
? event.touches[0].pageX - $(".tabs-box").offset().left
: event.pageX - $(".tabs-box").offset().left;
var scrollPos = scrollLeft - (mousePos - startX);
$(".tabs-box").scrollLeft(scrollPos);
}
});
// Handle mouseup/touchend event on tabs-box
$(".tabs-box").on("mouseup touchend", function () {
isDragging = false;
// Reset scroll speed and press timer
scrollSpeed = 20;
clearTimeout(pressTimer);
});
// Handle click event on filter items
$(".filter-item").click(function () {
const value = $(this).attr("data-filter");
if (value == "all") {
$(".cards").show("1000");
} else {
$(".cards")
.not("." + value)
.hide("1000");
$(".cards")
.filter("." + value)
.show("cards");
}
// Add active class to clicked filter item
$(this).addClass("active-filter").siblings().removeClass("active-filter");
});
// Handle keydown event on wrapper12 to move left or right using keyboard
$(".wrapper12").on("keydown", function (event) {
// Check if wrapper12 is being hovered over
if ($(this).is(":hover")) {
// Move left if left arrow key is pressed
if (event.keyCode === 37) {
$(".tabs-box").animate({ scrollLeft: "-=" + scrollSpeed }, 100);
}
// Move right if right arrow key is pressed
else if (event.keyCode === 39) {
$(".tabs-box").animate({ scrollLeft: "+=" + scrollSpeed }, 100);
}
}
});
});
/*=============== MENU ===============*/
// Get all the <a> tags within the menu
const menuLinks = document.querySelectorAll(
".header .nav .nav__menu .nav__list .nav__item .nav__link"
);
// Get all the div elements
const mapDiv = document.getElementById("map");
const placeDiv = document.getElementById("place");
const aidDiv = document.getElementById("aid");
const infoDiv = document.getElementById("info");
// Add click event listener to each <a> tag
menuLinks.forEach(function (link) {
link.addEventListener("click", function () {
// Remove "active" class from all <a> tags
menuLinks.forEach(function (link) {
link.classList.remove("active-link");
});
// Add "active" class to the clicked <a> tag
this.classList.add("active-link");
// Hide all div elements
mapDiv.style.display = "none";
placeDiv.style.display = "none";
aidDiv.style.display = "none";
infoDiv.style.display = "none";
// Show the corresponding div based on the clicked link
if (this.id === "nav-map") {
mapDiv.style.display = "block";
} else if (this.id === "nav-place") {
placeDiv.style.display = "block";
} else if (this.id === "nav-aid") {
aidDiv.style.display = "block";
} else if (this.id === "nav-info") {
infoDiv.style.display = "block";
}
});
});
/*=============== HAMBURGET MENU ===============*/
const toggleBtn = document.querySelector(".toggle_btn");
const toggleBtnIcon = document.querySelector(".toggle_btn i");
const dropDownMenu = document.querySelector(".dropdown_menu");
const menuItems = document.querySelectorAll(".dropdown_menu li");
toggleBtn.onclick = function () {
dropDownMenu.classList.toggle("open");
const isOpen = dropDownMenu.classList.contains("open");
toggleBtnIcon.classList = isOpen ? "bx bx-x" : "bx bx-menu";
};
menuItems.forEach(function (menuItem) {
menuItem.addEventListener("click", function () {
dropDownMenu.classList.remove("open");
toggleBtnIcon.classList = "bx bx-menu";
});
});
window.addEventListener("scroll", function () {
if (dropDownMenu.classList.contains("open")) {
dropDownMenu.classList.remove("open");
toggleBtnIcon.classList = "bx bx-menu";
}
});
document.addEventListener("keydown", function (event) {
if (event.key === "Escape" && dropDownMenu.classList.contains("open")) {
dropDownMenu.classList.remove("open");
toggleBtnIcon.classList = "bx bx-menu";
}
});
$(document).ready(function () {
$("#searchInput").on("keyup", function () {
var value = $(this).val().toLowerCase();
$(".card").filter(function () {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1);
});
});
});
/*=============== input ===============*/
function makeEditable(element) {
const text = element.innerText;
element.style.display = "none";
const inputField = document.createElement("input");
inputField.setAttribute("type", "text");
inputField.setAttribute("class", "input-field");
inputField.value = text;
inputField.addEventListener("blur", function () {
element.innerText = this.value;
this.parentNode.removeChild(this);
element.style.display = "block";
});
element.parentNode.insertBefore(inputField, element.nextSibling);
inputField.focus();
}