-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
108 lines (94 loc) · 2.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
// Initialize AOS (Animate On Scroll)
AOS.init({
once: false,
duration: 500,
delay: 100,
});
// Open URL in a new tab
function openUrl(url) {
window.open(url, "_blank");
}
// Open email client
function openMail() {
window.open("mailto:vs423502@gmail.com");
}
// Initialize theme to light if not set
if (localStorage.getItem("theme") === null) {
setTheme("light");
}
function setCookie(name, value, days=365) {
let expires = "";
if (days) {
const date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = `expires=${date.toUTCString()};`;
}
document.cookie = `${name}=${value};${expires}path=/`;
}
function deleteCookie(name) {
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
}
function getCookie(name) {
const nameEQ = `${name}=`;
const ca = document.cookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) === ' ') c = c.substring(1);
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
// Set theme in localStorage
function setTheme(theme) {
setCookie("theme", theme);
applyTheme(theme);
}
// Get the current theme from localStorage
function getTheme() {
return getCookie("theme");
}
// Apply theme styles based on the theme
function applyTheme(theme) {
const isDark = theme === "dark";
$(".main-container").css("background", isDark ? "#232323" : "#ffffff");
$(".profile").css("background", isDark ? "#1E1E1E" : "#EBEBFA");
$(".bio").css("background", isDark ? "#323232" : "#F7F7FF");
$(".white-text").css("color", isDark ? "black" : "white");
$(".black-text").css("color", isDark ? "white" : "black");
}
// Toggle dark mode
$(".dark-mode-container").click(function () {
var button = $(this).find("li");
// light theme
if(button.hasClass("bi-moon-fill")) {
button.removeClass("bi-moon-fill").addClass("bi-sun-fill");
$(this).css("justify-content", "flex-start");
setTheme("light");
applyTheme(getTheme());
} else if(button.hasClass("bi-sun-fill")) { // dark theme
button.removeClass("bi-sun-fill").addClass("bi-moon-fill");
$(this).css("justify-content", "flex-end");
setTheme("dark");
applyTheme(getTheme());
}
});
// Profile animation on load and touch events
$(document).ready(function () {
setTimeout(function () {
$(".profile").animate({
borderTopLeftRadius: "0px",
borderTopRightRadius: "0px",
borderBottomLeftRadius: "50px",
borderBottomRightRadius: "50px",
}, 500);
}, 800);
$(".profile").on("touchstart touchend", function (event) {
const isTouchStart = event.type === "touchstart";
$(this).stop().animate({
borderTopLeftRadius: isTouchStart ? "0px" : "0px",
borderTopRightRadius: isTouchStart ? "0px" : "0px",
borderBottomLeftRadius: isTouchStart ? "0px" : "50px",
borderBottomRightRadius: isTouchStart ? "0px" : "50px",
}, 500);
});
});