-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
73 lines (66 loc) · 2.89 KB
/
Copy pathscript.js
File metadata and controls
73 lines (66 loc) · 2.89 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
// ...existing code...
"use strict";
var tablinks = document.getElementsByClassName("tab-links");
var tabcontents = document.getElementsByClassName("tab-contents");
function opentab(tabname, el) {
for (let tablink of tablinks) {
tablink.classList.remove("active-links");
}
for (let tabcontent of tabcontents) {
tabcontent.classList.remove("active-tab");
}
// prefer the passed element (from an event handler), otherwise try to find a link matching data-tab attribute
if (el && el.classList) {
el.classList.add("active-links");
} else {
const link = document.querySelector(`.tab-links[data-tab="${tabname}"]`);
if (link) link.classList.add("active-links");
}
const target = document.getElementById(tabname);
if (target) target.classList.add("active-tab");
}
var sidemenu = document.getElementById("sidemenu");
function openmenu() {
if (sidemenu) sidemenu.style.right = "0";
}
function closemenu() {
if (sidemenu) sidemenu.style.right = "-200px";
}
const scriptURL = 'https://script.google.com/macros/s/AKfycbzzaCNU_ZxXdJAFruvOHhE6-B0iK9yyDbAxVk0onJIKPtqQrEfSYupy6LzdcEXDIQLGPw/exec';
const form = document.forms['submit-to-google-sheet'];
const msg = document.getElementById("msg");
if (form) {
form.addEventListener('submit', e => {
e.preventDefault();
fetch(scriptURL, { method: 'POST', body: new FormData(form) })
.then(response => {
// response may be opaque if CORS is restricted; still show success message
msg.innerHTML = "Message sent successfully";
setTimeout(function () { msg.innerHTML = ""; }, 5000);
form.reset();
})
.catch(error => {
console.error('Error!', error.message);
msg.innerHTML = "Error sending message";
setTimeout(function () { msg.innerHTML = ""; }, 5000);
});
});
}
// --- Highlight active section link on scroll ---
const sections = document.querySelectorAll("section, div[id]");
const navLinks = document.querySelectorAll("nav ul li a");
window.addEventListener("scroll", () => {
let current = "";
sections.forEach((section) => {
const sectionTop = section.offsetTop - 100;
if (scrollY >= sectionTop) {
current = section.getAttribute("id");
}
});
navLinks.forEach((link) => {
link.classList.remove("active");
if (link.getAttribute("href") === `#${current}`) {
link.classList.add("active");
}
});
});