-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
649 lines (550 loc) · 20.1 KB
/
script.js
File metadata and controls
649 lines (550 loc) · 20.1 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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
// Navbar Functionality
const navbar = document.getElementById("navbar");
const navItems = document.querySelectorAll("#navbar .nav-items li a");
const checkbox = document.querySelector("#nav-toggle");
// Smooth scroll for nav links
navItems.forEach(item => {
item.addEventListener("click", function(e) {
e.preventDefault();
checkbox.checked = false;
const targetId = this.getAttribute("href");
const targetSection = document.querySelector(targetId);
if (targetSection) {
targetSection.scrollIntoView({ behavior: "smooth" });
}
});
});
// Navbar background on scroll
let lastScrollTop = 0;
window.addEventListener("scroll", () => {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
if (scrollTop > 100) {
navbar.classList.add("fixed");
} else {
navbar.classList.remove("fixed");
}
// Hide navbar on scroll down, show on scroll up
if (scrollTop > lastScrollTop && scrollTop > 100) {
navbar.style.transform = "translateY(-100%)";
} else {
navbar.style.transform = "translateY(0)";
}
lastScrollTop = scrollTop;
});
// Close mobile menu when clicking outside
document.addEventListener("click", (e) => {
if (!navbar.contains(e.target) && checkbox.checked) {
checkbox.checked = false;
}
});
// Portfolio Gallery
let filterContainer = document.querySelector(".gallery-filter");
let galleryItems = document.querySelectorAll(".gallery-item");
// Function to filter gallery items
function filterGallery(filterValue) {
galleryItems.forEach((item) => {
if (item.classList.contains(filterValue)) {
item.classList.remove("hide");
item.classList.add("show");
} else {
item.classList.remove("show");
item.classList.add("hide");
}
});
}
filterContainer.addEventListener("click", (event) => {
if (event.target.classList.contains("filter-item")) {
// Deactivate existing active filter item
filterContainer.querySelector(".active").classList.remove("active");
// Activate new filter item
event.target.classList.add("active");
let filterValue = event.target.getAttribute("data-filter");
filterGallery(filterValue); // Call the filter function
}
});
// Initial filtering on page load (Hide all but the active filter's items)
const activeFilter = filterContainer.querySelector(".active");
if (activeFilter) {
const initialFilterValue = activeFilter.getAttribute("data-filter");
filterGallery(initialFilterValue);
}
// Review Carousel
$(".owl-carousel").owlCarousel({
loop: true,
margin: 10,
responsive: {
0: {
items: 1,
},
600: {
items: 1,
},
1200: {
items: 2,
},
},
});
//SubText
const subTextElement = document.getElementById("subText");
const subTextOptions = [
"Cyber Security Analyst",
"Security Consultant",
"Cyber Security Instructor",
];
let currentSubTextIndex = 0;
function updateSubText() {
subTextElement.classList.add("fade-out"); // Start fade-out
setTimeout(() => {
subTextElement.textContent = subTextOptions[currentSubTextIndex];
currentSubTextIndex = (currentSubTextIndex + 1) % subTextOptions.length;
subTextElement.classList.remove("fade-out"); // Fade back in
}, 500); // Wait for fade-out (half of transition duration)
}
// Initial display
updateSubText();
setInterval(updateSubText, 3000);
// Scroll to Top Button
const scrollToTopBtn = document.getElementById("scrollToTopBtn");
window.onscroll = function () {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
scrollToTopBtn.style.display = "block";
} else {
scrollToTopBtn.style.display = "none";
}
};
scrollToTopBtn.addEventListener("click", () => {
document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
});
// H1 Hover Effect - Change text content
const mainHeading = document.querySelector("#home .text-holder h1");
let isHovered = false;
let timeoutId = null;
if (mainHeading) {
const originalText = mainHeading.innerHTML;
// Track mouse position relative to heading
const handleMouseMove = (e) => {
const rect = mainHeading.getBoundingClientRect();
const isOverHeading = (
e.clientX >= rect.left &&
e.clientX <= rect.right &&
e.clientY >= rect.top &&
e.clientY <= rect.bottom
);
if (!isOverHeading && isHovered) {
isHovered = false;
clearTimeout(timeoutId);
mainHeading.innerHTML = originalText;
}
};
mainHeading.addEventListener("mouseenter", function() {
isHovered = true;
clearTimeout(timeoutId);
this.innerHTML = "Cyber <span>Armor Knight</span>";
});
mainHeading.addEventListener("mouseleave", function() {
isHovered = false;
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
if (!isHovered) {
this.innerHTML = originalText;
}
}, 100);
});
// Add global mouse tracking
document.addEventListener("mousemove", handleMouseMove);
// Touch event handling for mobile
mainHeading.addEventListener("touchstart", function(e) {
e.preventDefault();
isHovered = true;
clearTimeout(timeoutId);
this.innerHTML = "Cyber <span>Armor Knight</span>";
});
mainHeading.addEventListener("touchend", function() {
isHovered = false;
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
if (!isHovered) {
this.innerHTML = originalText;
}
}, 100);
});
}
// Navbar scroll behavior
const scrollThreshold = 100;
let prevScrollPos = window.pageYOffset;
window.addEventListener("scroll", () => {
const currentScrollPos = window.pageYOffset;
// Show navbar at the top
if (currentScrollPos <= scrollThreshold) {
navbar.classList.remove("fixed");
return;
}
// Handle scroll direction
if (prevScrollPos > currentScrollPos) {
// Scrolling up - show navbar
navbar.classList.add("fixed");
navbar.style.transform = "translateY(0)";
} else {
// Scrolling down - hide navbar
navbar.classList.add("fixed");
navbar.style.transform = "translateY(-100%)";
}
prevScrollPos = currentScrollPos;
});
// Email send
const WEB3FORMS_ACCESS_KEY = "4f375d87-1ffc-42bd-91af-426fd4adedf4";
function sendEmailWithWeb3FormsCustom() {
const form = document.querySelector("form");
form.addEventListener("submit", async function (e) {
e.preventDefault();
const formData = new FormData(form);
const submitBtn = form.querySelector('input[type="submit"]');
// Custom Web3Forms configuration to avoid spam
const emailData = {
access_key: WEB3FORMS_ACCESS_KEY,
name: formData.get("name"),
email: formData.get("email"),
subject: formData.get("subject"),
message: formData.get("message"),
// ANTI-SPAM CONFIGURATION
from_name: formData.get("name"), // Use sender's name
replyto: formData.get("email"), // Set reply-to as sender's email
redirect: window.location.href + "?success=1",
};
submitBtn.value = "Sending...";
submitBtn.disabled = true;
try {
const response = await fetch("https://api.web3forms.com/submit", {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify(emailData),
});
const result = await response.json();
if (result.success) {
showMessage("Message sent successfully!", "success");
form.reset();
} else {
throw new Error(result.message);
}
} catch (error) {
console.error("Error:", error);
showMessage("Failed to send message. Please try again.", "error");
} finally {
submitBtn.value = "Send Your Message";
submitBtn.disabled = false;
}
});
}
function createProfessionalEmailTemplate(formData) {
return `
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px; border: 1px solid #e0e0e0; border-radius: 10px;">
<div style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); padding: 30px; border-radius: 10px 10px 0 0; text-align: center;">
<h1 style="color: white; margin: 0; font-size: 24px;">New Contact Form Message</h1>
</div>
<div style="padding: 30px; background-color: #f9f9f9;">
<div style="background: white; padding: 25px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1);">
<h2 style="color: #333; margin-bottom: 20px; border-bottom: 2px solid #667eea; padding-bottom: 10px;">Contact Details</h2>
<table style="width: 100%; border-collapse: collapse;">
<tr>
<td style="padding: 12px 0; border-bottom: 1px solid #eee; font-weight: bold; color: #555; width: 30%;">Name:</td>
<td style="padding: 12px 0; border-bottom: 1px solid #eee; color: #333;">${formData.get(
"name"
)}</td>
</tr>
<tr>
<td style="padding: 12px 0; border-bottom: 1px solid #eee; font-weight: bold; color: #555;">Email:</td>
<td style="padding: 12px 0; border-bottom: 1px solid #eee; color: #333;"><a href="mailto:${formData.get(
"email"
)}" style="color: #667eea; text-decoration: none;">${formData.get(
"email"
)}</a></td>
</tr>
<tr>
<td style="padding: 12px 0; border-bottom: 1px solid #eee; font-weight: bold; color: #555;">Subject:</td>
<td style="padding: 12px 0; border-bottom: 1px solid #eee; color: #333;">${formData.get(
"subject"
)}</td>
</tr>
</table>
<h3 style="color: #333; margin-top: 25px; margin-bottom: 15px;">Message:</h3>
<div style="background: #f8f9fa; padding: 20px; border-radius: 5px; border-left: 4px solid #667eea; line-height: 1.6; color: #555;">
${formData.get("message").replace(/\n/g, "<br>")}
</div>
</div>
</div>
<div style="text-align: center; padding: 20px; background-color: #f0f0f0; color: #666; font-size: 14px; border-radius: 0 0 10px 10px;">
<p style="margin: 0;">This email was sent from your contact form on ${new Date().toLocaleDateString()}</p>
</div>
</div>
`;
}
// Skills Progress Bar Animation on Scroll
function animateProgressBars() {
const progressBars = document.querySelectorAll(".progress-line");
// Create an intersection observer
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
// Add a small delay to make the animation more noticeable
setTimeout(() => {
entry.target.classList.add("animate");
}, 200);
}
});
},
{
// Trigger when 30% of the element is visible
threshold: 0.3,
// Start observing 100px before the element comes into view
rootMargin: "0px 0px -100px 0px",
}
);
// Observe all progress bars
progressBars.forEach((bar) => {
observer.observe(bar);
});
}
// Initialize form on page load
document.addEventListener("DOMContentLoaded", function () {
sendEmailWithWeb3FormsCustom();
// Initialize progress bar animation
animateProgressBars();
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.get("success") === "1") {
showMessage("Message sent successfully!", "success");
window.history.replaceState({}, document.title, window.location.pathname);
}
});
// Enhanced message display with better styling
function showMessage(message, type) {
const existingMessage = document.querySelector(".form-message");
if (existingMessage) {
existingMessage.remove();
}
const messageDiv = document.createElement("div");
messageDiv.className = `form-message ${type}`;
messageDiv.innerHTML = `
<div style="display: flex; align-items: center; justify-content: center; gap: 10px;">
<span style="font-size: 20px;">${
type === "success" ? "✓" : "✗"
}</span>
<span>${message}</span>
</div>
`;
messageDiv.style.cssText = `
padding: 20px;
margin: 20px 0;
border-radius: 10px;
text-align: center;
font-weight: 600;
font-size: 16px;
animation: slideInBounce 0.5s ease-out;
box-shadow: 0 4px 20px rgba(0,0,0,0.1);
${
type === "success"
? "background: linear-gradient(135deg, #4CAF50, #45a049); color: white;"
: "background: linear-gradient(135deg, #f44336, #d32f2f); color: white;"
}
`;
if (!document.querySelector("#enhancedAnimations")) {
const style = document.createElement("style");
style.id = "enhancedAnimations";
style.textContent = `
@keyframes slideInBounce {
0% { opacity: 0; transform: translateY(-30px) scale(0.9); }
50% { transform: translateY(-5px) scale(1.02); }
100% { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes fadeOutUp {
from { opacity: 1; transform: translateY(0); }
to { opacity: 0; transform: translateY(-20px); }
}
`;
document.head.appendChild(style);
}
const title = document.querySelector(".title");
title.insertAdjacentElement("afterend", messageDiv);
setTimeout(() => {
messageDiv.style.animation = "fadeOutUp 0.4s ease-out forwards";
setTimeout(() => messageDiv.remove(), 400);
}, 4000);
}
// Blog Carousel Functionality
class BlogCarousel {
constructor() {
this.currentSlide = 0;
this.slides = document.querySelectorAll(".blog-slide");
this.indicators = document.querySelectorAll(".indicator");
this.autoplayInterval = null;
this.autoplayDuration = 4000; // 4 seconds
this.init();
}
init() {
if (this.slides.length === 0) return;
// Initialize indicators
this.indicators.forEach((indicator, index) => {
indicator.addEventListener("click", () => {
this.goToSlide(index);
});
});
// Initialize navigation buttons
const prevBtn = document.querySelector(".blog-nav-btn.prev");
const nextBtn = document.querySelector(".blog-nav-btn.next");
if (prevBtn && nextBtn) {
prevBtn.addEventListener("click", () => {
this.prevSlide();
});
nextBtn.addEventListener("click", () => {
this.nextSlide();
});
}
// Start autoplay
this.startAutoplay();
// Pause autoplay on hover
const carousel = document.querySelector(".blog-carousel");
if (carousel) {
carousel.addEventListener("mouseenter", () => this.pauseAutoplay());
carousel.addEventListener("mouseleave", () => this.startAutoplay());
}
// Pause autoplay when user interacts with modal
const readMoreBtns = document.querySelectorAll(".blog-content .btn");
readMoreBtns.forEach((btn) => {
btn.addEventListener("click", () => {
this.pauseAutoplay();
});
});
// Resume autoplay when modal is closed
const modal = document.getElementById("blogModal");
if (modal) {
modal.addEventListener("click", (e) => {
if (e.target === modal) {
this.startAutoplay();
}
});
}
}
goToSlide(index) {
if (index === this.currentSlide) return;
// Remove active classes
this.slides[this.currentSlide].classList.remove("active");
this.indicators[this.currentSlide].classList.remove("active");
// Add transition classes
if (index > this.currentSlide) {
this.slides[this.currentSlide].classList.add("prev");
} else {
this.slides[this.currentSlide].classList.add("next");
}
// Update current slide
this.currentSlide = index;
// Add active classes
this.slides[this.currentSlide].classList.add("active");
this.indicators[this.currentSlide].classList.add("active");
// Clean up transition classes after animation
setTimeout(() => {
this.slides.forEach((slide) => {
slide.classList.remove("prev", "next");
});
}, 600);
}
nextSlide() {
const nextIndex = (this.currentSlide + 1) % this.slides.length;
this.goToSlide(nextIndex);
}
prevSlide() {
const prevIndex =
(this.currentSlide - 1 + this.slides.length) % this.slides.length;
this.goToSlide(prevIndex);
}
startAutoplay() {
this.pauseAutoplay(); // Clear any existing interval
this.autoplayInterval = setInterval(() => {
this.nextSlide();
}, this.autoplayDuration);
}
pauseAutoplay() {
if (this.autoplayInterval) {
clearInterval(this.autoplayInterval);
this.autoplayInterval = null;
}
}
}
// Initialize blog carousel when DOM is loaded
document.addEventListener("DOMContentLoaded", () => {
// Dynamically generate blog indicators based on number of slides
const blogCarouselContainer = document.querySelector(".blog-carousel-container");
const blogIndicators = document.querySelector(".blog-indicators");
if (blogCarouselContainer && blogIndicators) {
const slides = blogCarouselContainer.querySelectorAll(".blog-slide");
blogIndicators.innerHTML = "";
slides.forEach((slide, idx) => {
const indicator = document.createElement("span");
indicator.className = "indicator" + (idx === 0 ? " active" : "");
indicator.setAttribute("data-slide", idx);
blogIndicators.appendChild(indicator);
});
}
// Add a small delay to ensure all elements are properly loaded
setTimeout(() => {
new BlogCarousel();
}, 100);
});
// Service Modal Logic
const serviceModal = document.getElementById("serviceModal");
const serviceModalTitle = serviceModal.querySelector(".service-modal-title");
const serviceModalBody = serviceModal.querySelector(".service-modal-body");
const serviceModalClose = serviceModal.querySelector(".service-modal-close");
// Function to open service modal with smooth animation
function openServiceModal(title, content) {
serviceModalTitle.textContent = title;
serviceModalBody.innerHTML = content;
serviceModal.style.display = "block";
serviceModal.offsetHeight; // Force reflow
serviceModal.classList.add("show");
}
// Function to close service modal with smooth animation
function closeServiceModal() {
serviceModal.classList.remove("show");
setTimeout(() => {
serviceModal.style.display = "none";
}, 300);
}
// Add event listeners to all service read more buttons
document.addEventListener('DOMContentLoaded', function() {
const readMoreBtns = document.querySelectorAll(".service-card .read-more-btn");
readMoreBtns.forEach((btn) => {
btn.addEventListener("click", (e) => {
e.preventDefault();
const serviceId = btn.getAttribute("data-service");
// Find the hidden modal content for this service
const modalContent = document.querySelector(`.modal-content-hidden[data-service="${serviceId}"]`);
if (modalContent) {
const title = modalContent.querySelector("h3").textContent;
const content = modalContent.innerHTML;
openServiceModal(title, content);
}
});
});
// Close service modal when clicking the close button
serviceModalClose.addEventListener("click", closeServiceModal);
// Close service modal when clicking outside the modal content
serviceModal.addEventListener("click", (event) => {
if (event.target === serviceModal) {
closeServiceModal();
}
});
// Close service modal when pressing the Escape key
document.addEventListener("keydown", (event) => {
if (event.key === "Escape" && serviceModal.classList.contains("show")) {
closeServiceModal();
}
});
// Prevent service modal content clicks from closing the modal
document.querySelector(".service-modal-content").addEventListener("click", (e) => {
e.stopPropagation();
});
});