-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
181 lines (161 loc) · 5.24 KB
/
main.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
//Print this in console as well.
console.log(`/*
*
* Oh hello there, Mr. Hacker !! , so you want to see some code?
* Sure thing,
* Drop an email at [email protected]
~ Made by Abhishek Kashyap
*
*
*/
`);
let lastWindowWidth = document.documentElement.clientWidth;
const scrollAndResizeHandler = (e) => {
if (
(lastWindowWidth >= 560 && document.documentElement.clientWidth < 560) ||
(lastWindowWidth < 560 && document.documentElement.clientWidth >= 560)
) {
document.getElementsByClassName("nav-icon")[0].classList.remove("open");
document.getElementById("navbar").classList.remove("shown");
document.getElementById("navbar2").classList.add("shown");
}
if (document.documentElement.clientWidth < 560) {
document
.querySelectorAll("nav ul li", "nav2 ul li")
.forEach((e) => e.classList.remove("selected"));
return;
}
if (
document.body.scrollTop > window.innerHeight * 0.95 ||
document.documentElement.scrollTop > window.innerHeight * 0.95
) {
document.getElementById("navbar").classList.add("shown");
document.getElementById("navbar2").classList.remove("shown");
} else {
document.getElementById("navbar").classList.remove("shown");
document.getElementById("navbar2").classList.add("shown");
}
setSelectedNavLink();
lastWindowWidth = document.documentElement.clientWidth;
};
const setSelectedNavLink = () => {
let sections = [
"community",
"Extra",
"projects",
"education",
"experience",
"introduction",
];
let sectionScrolls = sections.map((v) => ({
name: v,
visible:
document.getElementById(v).offsetTop <=
document.documentElement.scrollTop +
0.34 * document.documentElement.clientHeight,
}));
sectionScrolls.sort((a, b) => b.visible - a.visible);
// console.log(JSON.stringify(sectionScrolls));
document
.querySelectorAll("nav ul li", "nav2 ul li")
.forEach((e) => e.classList.remove("selected"));
document
.getElementById(`${sectionScrolls[0].name}Link`)
.classList.add("selected");
};
document.addEventListener("scroll", scrollAndResizeHandler);
window.addEventListener("resize", scrollAndResizeHandler);
document
.getElementsByClassName("nav-icon")[0]
.addEventListener("click", (e) => {
document.getElementsByClassName("nav-icon")[0].classList.toggle("open");
document.getElementById("navbar").classList.toggle("shown");
document.getElementById("navbar2").classList.toggle("shown");
});
document.querySelectorAll("nav ul li", "nav2 ul li").forEach((el) =>
el.addEventListener("click", function (e) {
if (document.documentElement.clientWidth < 560) {
document.getElementsByClassName("nav-icon")[0].classList.remove("open");
document.getElementById("navbar").classList.remove("shown");
document.getElementById("navbar2").classList.remove("shown");
}
})
);
//document.getElementById('age').innerHTML = (new Date(new Date() - new Date('1993-12-08')).getFullYear() - 1970);
$(document).ready(function () {
setInterval("cursorAnimation()", 600);
});
function cursorAnimation() {
$("#logo__cursor")
.animate(
{
opacity: 0,
},
"fast",
"swing"
)
.animate(
{
opacity: 1,
},
"fast",
"swing"
);
}
$(document).ready(function () {
// Add class to mailto link
// Needed to separate the disabling of the default action AND copy email to clipboard
$("a[hreff^=mailto]").addClass("mailto-link");
var mailto = $(".mailto-link");
var messageCopy = "Click to copy email address";
var messageSuccess = "Email address copied";
mailto.append('<span class="mailto-message"></span>');
$(".mailto-message").append(messageCopy);
// Disable default action (opening your email client.)
$("a[hreff^=mailto]").click(function () {
return false;
});
// On click, get href and remove 'mailto:'
// Store email address in a variable.
mailto.click(function () {
var href = $(this).attr("hreff");
var email = href.replace("mailto:", "");
copyToClipboard(email);
$(".mailto-message").empty().append(messageSuccess);
setTimeout(function () {
$(".mailto-message").empty().append(messageCopy);
}, 2000);
});
});
// Grabbed this from Stack Overflow.
// Copies the email variable to clipboard
function copyToClipboard(text) {
var dummy = document.createElement("input");
document.body.appendChild(dummy);
dummy.setAttribute("value", text);
dummy.select();
document.execCommand("copy");
document.body.removeChild(dummy);
}
function ExpandShrink() {
var dots = document.getElementById("dots");
var moreText = document.getElementById("more");
var btnText = document.getElementById("myBtn");
if (dots.style.display === "none") {
dots.style.display = "inline";
btnText.innerHTML = "Read more";
moreText.style.display = "none";
} else {
dots.style.display = "none";
btnText.innerHTML = " Read less";
moreText.style.display = "inline";
// window.open("https://amzn.to/3jujImr","_self");
// window.open("https://abhi3566.github.io/#community", "_blank");
}
}
function newRedirect() {
if (window.location.href == "https://abhi3566.github.io/github") {
window.location.href = "https://github.com/abhi3566";
}
}
// This website is made by Abhishek Kashyap