-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsourav-inline.js
433 lines (367 loc) · 14.7 KB
/
sourav-inline.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
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
$(document).ready(function() {
var checkscroll = window.scrollY;
if(checkscroll == 0){
// $(".container").hide();
}
$("#sectionToNavigate").hide();
// $(".closeclass, .close-container, .close-btn").hide();
fetch('./blog.json')
.then(response => response.json())
.then(data => {
const blogContainer = document.getElementById('blog-container');
data.forEach(post => {
const article = document.createElement('article');
article.classList.add('blog-post');
article.dataset.fullContent = encodeURIComponent(post.full); // Store full content
article.dataset.title = post.title; // Store title
article.dataset.date = post.date; // Store date
article.innerHTML = `
<header>
<center><h2 class="post-title">${post.title}</h2></center>
<p class="post-meta">Posted on ${post.date} by ${post.author}</p>
</header>
<div class="post-content">
<p style="color:#a89984">${post.content}</p>
</div>
<footer>
<p class="post-tags">Tags: ${post.tags.map(tag => `<a href="#" style="color:#666">${tag}</a>`).join(', ')}</p>
</footer>
`;
blogContainer.appendChild(article);
});
function applyStaggeredAnimation() {
const titles = document.querySelectorAll('.post-title');
titles.forEach((title) => {
const words = title.textContent.split(' ');
title.innerHTML = words.map((word, index) => `<span style="display:inline-block;">${word}</span>`).join(' ');
const spans = title.querySelectorAll('span');
spans.forEach((span, i) => {
span.style.animation = `revolveScale 0.4s forwards`;
span.style.animationDelay = `${i * 0.1}s`; // Stagger the animation delay based on the word index
});
});
}
// Call the function after adding all articles
applyStaggeredAnimation();
// Add event listener to handle clicks on any blog post
blogContainer.addEventListener('click', function(event) {
if (event.target.closest('.blog-post')) {
const post = event.target.closest('.blog-post');
const fullContent = decodeURIComponent(post.dataset.fullContent);
const title = post.dataset.title;
const date = post.dataset.date;
// Show and populate the first .boxclassinfinite div with the full content
const boxclassinfinite = document.querySelector('.boxclassinfinite');
if (boxclassinfinite) {
boxclassinfinite.innerHTML = `
<div class="close-container close-btn">
<div class="leftright"></div>
<div class="rightleft"></div>
<label class="close">close</label>
</div>
<header>
<h1 style="text-align: center;">${title}</h1>
<p style="text-align: center; font-style: italic;">Posted on ${date}</p>
</header>
<div class="full-content">
<p>${fullContent}</p>
</div>
`;
boxclassinfinite.removeAttribute('hidden');
boxclassinfinite.classList.remove('hide-animation');
// Optional: Close the .boxclassinfinite div when clicking outside of it
document.addEventListener('click', function(e) {
if (!boxclassinfinite.contains(e.target) && !e.target.closest('.blog-post')) {
boxclassinfinite.setAttribute('hidden', true);
}
});
document.addEventListener('click', function(event) {
const closeButton = event.target.closest('.close-container');
const boxclassinfinite = document.querySelector('.boxclassinfinite');
if (closeButton && boxclassinfinite) {
boxclassinfinite.classList.add('hide-animation');
boxclassinfinite.addEventListener('animationend', function() {
boxclassinfinite.setAttribute('hidden', true);
}, { once: true });
}
});
}
}
});
})
.catch(error => console.error('Error loading blog posts:', error));
});
(function () {
var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || function (callback) {
window.setTimeout(callback, 1000 / 60);
};
window.requestAnimationFrame = requestAnimationFrame;
})();
// Terrain stuff.
var background = document.getElementById("bgCanvas"),
bgCtx = background.getContext("2d"),
width = window.innerWidth,
height = document.body.offsetHeight;
(height < 800) ? height = 800 : height;
background.width = width;
background.height = height;
function Terrain(options) {
options = options || {};
this.terrain = document.createElement("canvas");
this.terCtx = this.terrain.getContext("2d");
this.scrollDelay = options.scrollDelay || 90;
this.lastScroll = new Date().getTime();
this.terrain.width = width;
this.terrain.height = height;
this.fillStyle = options.fillStyle || "#3c3836";
this.mHeight = options.mHeight || height;
// generate
this.points = [];
var displacement = options.displacement || 140,
power = Math.pow(2, Math.ceil(Math.log(width) / (Math.log(2))));
// set the start height and end height for the terrain
this.points[0] = this.mHeight;//(this.mHeight - (Math.random() * this.mHeight / 2)) - displacement;
this.points[power] = this.points[0];
// create the rest of the points
for (var i = 1; i < power; i *= 2) {
for (var j = (power / i) / 2; j < power; j += power / i) {
this.points[j] = ((this.points[j - (power / i) / 2] + this.points[j + (power / i) / 2]) / 2) + Math.floor(Math.random() * -displacement + displacement);
}
displacement *= 0.6;
}
document.body.appendChild(this.terrain);
}
Terrain.prototype.update = function () {
// draw the terrain
this.terCtx.clearRect(0, 0, width, height);
this.terCtx.fillStyle = this.fillStyle;
if (new Date().getTime() > this.lastScroll + this.scrollDelay) {
this.lastScroll = new Date().getTime();
this.points.push(this.points.shift());
}
this.terCtx.beginPath();
for (var i = 0; i <= width; i++) {
if (i === 0) {
this.terCtx.moveTo(0, this.points[0]);
} else if (this.points[i] !== undefined) {
this.terCtx.lineTo(i, this.points[i]);
}
}
this.terCtx.lineTo(width, this.terrain.height);
this.terCtx.lineTo(0, this.terrain.height);
this.terCtx.lineTo(0, this.points[0]);
this.terCtx.fill();
}
// Second canvas used for the stars
bgCtx.fillStyle = '#282828';
bgCtx.fillRect(0, 0, width, height);
// stars
function Star(options) {
this.size = Math.random() * 2;
this.speed = Math.random() * .05;
this.x = options.x;
this.y = options.y;
}
Star.prototype.reset = function () {
this.size = Math.random() * 2;
this.speed = Math.random() * .05;
this.x = width;
this.y = Math.random() * height;
}
Star.prototype.update = function () {
this.x -= this.speed;
if (this.x < 0) {
this.reset();
} else {
bgCtx.fillRect(this.x, this.y, this.size, this.size);
}
}
function ShootingStar() {
this.reset();
}
ShootingStar.prototype.reset = function () {
this.x = Math.random() * width;
this.y = 0;
this.len = (Math.random() * 80) + 10;
this.speed = (Math.random() * 10) + 6;
this.size = (Math.random() * 1) + 0.1;
// this is used so the shooting stars arent constant
this.waitTime = new Date().getTime() + (Math.random() * 3000) + 500;
this.active = false;
}
ShootingStar.prototype.update = function () {
if (this.active) {
this.x -= this.speed;
this.y += this.speed;
if (this.x < 0 || this.y >= height) {
this.reset();
} else {
bgCtx.lineWidth = this.size;
bgCtx.beginPath();
bgCtx.moveTo(this.x, this.y);
bgCtx.lineTo(this.x + this.len, this.y - this.len);
bgCtx.stroke();
}
} else {
if (this.waitTime < new Date().getTime()) {
this.active = true;
}
}
}
var entities = [];
// init the stars
for (var i = 0; i < height; i++) {
entities.push(new Star({
x: Math.random() * width,
y: Math.random() * height
}));
}
// Add 2 shooting stars that just cycle.
entities.push(new ShootingStar());
entities.push(new ShootingStar());
entities.push(new Terrain({mHeight : (height/2)-120}));
entities.push(new Terrain({displacement : 120, scrollDelay : 50, fillStyle : "#282828", mHeight : (height/2)-60}));
entities.push(new Terrain({displacement : 100, scrollDelay : 20, fillStyle : "#1d2021", mHeight : height/2}));
//animate background
function animate() {
bgCtx.fillStyle = '#1d2021';
bgCtx.fillRect(0, 0, width, height);
bgCtx.fillStyle = '#ffffff';
bgCtx.strokeStyle = '#ffffff';
var entLen = entities.length;
while (entLen--) {
entities[entLen].update();
}
requestAnimationFrame(animate);
}
animate();
// cursor
document.getElementsByTagName("body")[0].addEventListener("mousemove", function(n) {
i = document.getElementById("cursor3");
t.style.left = n.clientX + "px",
t.style.top = n.clientY + "px",
e.style.left = n.clientX + "px",
e.style.top = n.clientY + "px",
i.style.left = n.clientX + "px",
i.style.top = n.clientY + "px"
});
var t = document.getElementById("cursor"),
e = document.getElementById("cursor2"),
i = document.getElementById("cursor3");
function n(t) {
e.classList.add("hover"), i.classList.add("hover")
}
function s(t) {
e.classList.remove("hover"), i.classList.remove("hover")
}
s();
for (var r = document.querySelectorAll(".hover-target"), a = r.length - 1; a >= 0; a--) {
o(r[a])
}
function o(t) {
t.addEventListener("mouseover", n), t.addEventListener("mouseout", s)
}
document.getElementById("downloadCV").addEventListener("mouseover", function() {
this.innerHTML = "CV";
});
document.getElementById("downloadCV").addEventListener("mouseout", function() {
this.innerHTML = '<i class="fas fa-id-card"></i>';
});
document.getElementById('downloadCV').addEventListener('click', function() {
// Create a link element
const a = document.createElement('a');
a.href = './resume.pdf'; // Path to the file
a.download = 'resume.pdf'; // Name of the downloaded file
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
});
document.querySelectorAll('.chevron').forEach(function(chevron) {
chevron.addEventListener('click', function() {
$("#sectionToNavigate").show();
var target = this.getAttribute('data-scroll-to');
var targetElement = document.querySelector(target);
if (targetElement) {
const targetPosition = targetElement.getBoundingClientRect().top + window.pageYOffset - 450; // 10px above
window.scrollTo({
top: targetPosition,
behavior: 'smooth' // For smooth scrolling
});
}
});
applyStaggeredAnimationProjects();
});
let hasClickedChevron = false;
document.querySelector('.scrollable-content').addEventListener('scroll', function() {
jquery(".post-title").removeClass("realname");
});
let lastScrollY = window.scrollY; // Track the previous scroll position
window.addEventListener('scroll', function() {
const container = document.querySelector('.container');
const currentScrollY = window.scrollY;
// Check if the user is scrolling up
if (currentScrollY < lastScrollY) {
// Scroll up detected
$("#boxcontainer").fadeIn(500);
$("#sectionToNavigate").fadeOut(50);
$("#sectionToNavigate").hide();
// $(".container").hide();
window.scrollTo({
top: 0,
behavior: 'smooth' // For smooth scrolling to the top
});
hasClickedChevron = false; // Reset the flag
} else if (currentScrollY > 10) {
// Check if the scroll position is greater than 10px
if (!hasClickedChevron) {
document.querySelector(".chevron").click();
$("#sectionToNavigate").fadeIn(500);
$("#boxcontainer").fadeOut(50);
$("#boxcontainer").hide();
hasClickedChevron = true; // Set the flag to true after clicking
}
} else {
hasClickedChevron = false; // Reset the flag
}
// Update the last scroll position
lastScrollY = currentScrollY;
});
function openGithub() {
window.open("${project.codeLink}", "_blank");
}
// Fetch project data from projects.json
fetch('./projects.json')
.then(response => response.json())
.then(data => {
const projectContainer = document.querySelector('.boxclass3');
data.forEach(project => {
const projectElement = document.createElement('div');
projectElement.classList.add('project-card');
projectElement.innerHTML = `
<div class="project-header">
<center> <h3>${project.title}</h3></center>
<center><p>${project.date}</p></center>
</div>
<div class="project-content">
<center> <p>${project.description}</p></center>
</div>
<div class="project-footer">
<center><button target="_blank" onclick="window.open('${project.codeLink}', '_blank')" id='somebutton' class="button-2">Github</button></center>
</div>
`;
projectContainer.appendChild(projectElement);
});
})
.catch(error => console.error('Error loading project data:', error));
function applyStaggeredAnimationProjects() {
const projectTitles = document.querySelectorAll('.project-header h3');
projectTitles.forEach((title) => {
const words = title.textContent.split(' ');
title.innerHTML = words.map((word, index) => `<span style="display:inline-block;">${word}</span>`).join(' ');
const spans = title.querySelectorAll('span');
spans.forEach((span, i) => {
span.style.animation = `revolveScaleP 0.4s forwards`;
span.style.animationDelay = `${i * 0.1}s`; // Stagger the animation delay based on the word index
});
});
}