-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
115 lines (94 loc) · 3.29 KB
/
script.js
File metadata and controls
115 lines (94 loc) · 3.29 KB
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
// EmailJS initialization
(function () {
emailjs.init("FbcccHWRjmInOlwSO");
})();
document.addEventListener("DOMContentLoaded", function () {
const form = document.getElementById("contactForm");
const burger = document.getElementById("burger");
const nav = document.querySelector("nav");
const navLinks = document.querySelectorAll(".nav a");
const checkboxes = document.querySelectorAll(".filters input");
const items = document.querySelectorAll(".project-gallery .item");
const lightbox = document.getElementById("lightbox");
const lightboxImage = document.getElementById("lightbox-image");
const closeButton = document.getElementById("lightbox-close");
// Toggle navigation menu on burger click
burger.addEventListener("click", () => {
nav.classList.toggle("active");
});
// set burger to inactive when a nav link is clicked
navLinks.forEach(link => {
link.addEventListener("click", () => {
nav.classList.remove("active");
});
});
// Send contact form using EmailJS
form.addEventListener("submit", function (event) {
event.preventDefault();
emailjs.sendForm("service_swj6m08", "template_of9jjc8", this)
.then(function () {
alert("Nachricht wurde erfolgreich gesendet!");
form.reset();
})
.catch(function (error) {
alert("Fehler beim Senden: " + error.text);
});
emailjs.sendForm("service_swj6m08", "template_18chji6", this)
.then(function () {
alert("Auto-Response wurde erfolgreich gesendet!");
})
.catch(function (error) {
alert("Fehler beim Senden der Auto-Response: " + error.text);
});
});
// Lightbox-Function for project images
document.querySelectorAll(".lightbox-img").forEach(img => {
img.addEventListener("click", () => {
lightboxImage.src = img.src;
lightbox.classList.add("active");
});
});
// Close lightbox on close button click
closeButton.addEventListener("click", () => {
lightbox.classList.remove("active");
});
// Close lightbox when clicking outside the image
lightbox.addEventListener("click", event => {
if (event.target === lightbox) lightbox.classList.remove("active");
});
// Filter project items based on selected checkboxes
checkboxes.forEach(checkbox => {
checkbox.addEventListener("change", () => {
// If one checkbox is checked, uncheck all other checkboxes
if (checkbox.checked) {
checkboxes.forEach(other => {
if (other !== checkbox) {
other.checked = false;
}
});
}
// If no checkbox is checked, check "All"
if (![...checkboxes].some(checkbox => checkbox.checked)) {
document
.querySelector('input[value="all"]')
.checked = true;
}
filterItems();
});
});
// Filter-Function for project gallery
function filterItems() {
const active = [...checkboxes].find(cb => cb.checked);
// If "All" is selected, show all items
if (active.value === "all") {
items.forEach(item => item.classList.remove("hide"));
return;
}
// Otherwise, show only items that match the selected tag
const tag = active.value;
items.forEach(item => {
const match = item.classList.contains(tag);
item.classList.toggle("hide", !match);
});
}
});