-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
554 lines (470 loc) · 18.3 KB
/
Copy pathscript.js
File metadata and controls
554 lines (470 loc) · 18.3 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
// Calendar functionality for mood tracking
class MoodCalendar {
constructor() {
this.currentDate = new Date();
this.selectedDate = null;
this.selectedMood = null;
this.moods = JSON.parse(localStorage.getItem('moodData')) || {};
this.initializeElements();
this.bindEvents();
this.renderCalendar();
}
initializeElements() {
this.monthYearEl = document.getElementById('monthYear');
this.calendarDaysEl = document.getElementById('calendarDays');
this.prevMonthBtn = document.getElementById('prevMonth');
this.nextMonthBtn = document.getElementById('nextMonth');
this.moodModal = document.getElementById('moodModal');
this.modalDateEl = document.getElementById('modalDate');
this.saveMoodBtn = document.getElementById('saveMood');
this.cancelMoodBtn = document.getElementById('cancelMood');
this.deleteMoodBtn = document.getElementById('deleteMood');
this.moodOptions = document.querySelectorAll('.mood-option');
}
bindEvents() {
this.prevMonthBtn.addEventListener('click', () => this.previousMonth());
this.nextMonthBtn.addEventListener('click', () => this.nextMonth());
this.saveMoodBtn.addEventListener('click', () => this.saveMood());
this.cancelMoodBtn.addEventListener('click', () => this.closeMoodModal());
this.deleteMoodBtn.addEventListener('click', () => this.deleteMood());
// Mood option selection
this.moodOptions.forEach(option => {
option.addEventListener('click', () => this.selectMood(option));
});
// Close modal when clicking outside
this.moodModal.addEventListener('click', (e) => {
if (e.target === this.moodModal) {
this.closeMoodModal();
}
});
}
renderCalendar() {
const year = this.currentDate.getFullYear();
const month = this.currentDate.getMonth();
// Set month/year title
this.monthYearEl.textContent = this.currentDate.toLocaleDateString('en-US', {
month: 'long',
year: 'numeric'
});
// Clear previous calendar
this.calendarDaysEl.innerHTML = '';
// Get first day of month and number of days
const firstDay = new Date(year, month, 1).getDay();
const daysInMonth = new Date(year, month + 1, 0).getDate();
const daysInPrevMonth = new Date(year, month, 0).getDate();
// Previous month's trailing days
for (let i = firstDay - 1; i >= 0; i--) {
const dayNum = daysInPrevMonth - i;
const dayEl = this.createDayElement(dayNum, true, year, month - 1);
this.calendarDaysEl.appendChild(dayEl);
}
// Current month's days
for (let day = 1; day <= daysInMonth; day++) {
const dayEl = this.createDayElement(day, false, year, month);
this.calendarDaysEl.appendChild(dayEl);
}
// Next month's leading days
const totalCells = this.calendarDaysEl.children.length;
const remainingCells = 42 - totalCells; // 6 rows × 7 days
for (let day = 1; day <= remainingCells; day++) {
const dayEl = this.createDayElement(day, true, year, month + 1);
this.calendarDaysEl.appendChild(dayEl);
}
}
createDayElement(dayNum, isOtherMonth, year, month) {
const dayEl = document.createElement('div');
dayEl.classList.add('calendar-day');
if (isOtherMonth) {
dayEl.classList.add('other-month');
}
// Check if it's today
const today = new Date();
if (year === today.getFullYear() &&
month === today.getMonth() &&
dayNum === today.getDate() &&
!isOtherMonth) {
dayEl.classList.add('today');
}
// Create day number element
const dayNumberEl = document.createElement('div');
dayNumberEl.classList.add('day-number');
dayNumberEl.textContent = dayNum;
dayEl.appendChild(dayNumberEl);
// Check for mood data
const dateKey = `${year}-${String(month + 1).padStart(2, '0')}-${String(dayNum).padStart(2, '0')}`;
if (this.moods[dateKey]) {
dayEl.classList.add('has-mood');
const moodEl = document.createElement('div');
moodEl.classList.add('day-mood');
moodEl.textContent = this.moods[dateKey].emoji;
dayEl.appendChild(moodEl);
}
// Add click event
if (!isOtherMonth) {
dayEl.addEventListener('click', () => {
this.openMoodModal(year, month, dayNum);
});
}
return dayEl;
}
previousMonth() {
this.currentDate.setMonth(this.currentDate.getMonth() - 1);
this.renderCalendar();
this.addTransitionEffect();
}
nextMonth() {
this.currentDate.setMonth(this.currentDate.getMonth() + 1);
this.renderCalendar();
this.addTransitionEffect();
}
addTransitionEffect() {
this.calendarDaysEl.style.opacity = '0';
setTimeout(() => {
this.calendarDaysEl.style.opacity = '1';
}, 150);
}
openMoodModal(year, month, day) {
this.selectedDate = `${year}-${String(month + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
// Set modal date
const date = new Date(year, month, day);
this.modalDateEl.textContent = date.toLocaleDateString('en-US', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric'
});
// Clear previous selection
this.moodOptions.forEach(option => option.classList.remove('selected'));
this.selectedMood = null;
// Check if date already has a mood
if (this.moods[this.selectedDate]) {
const existingMood = this.moods[this.selectedDate].mood;
const existingOption = document.querySelector(`[data-mood="${existingMood}"]`);
if (existingOption) {
existingOption.classList.add('selected');
this.selectedMood = {
mood: existingMood,
emoji: existingOption.dataset.emoji
};
}
this.deleteMoodBtn.style.display = 'inline-block';
} else {
this.deleteMoodBtn.style.display = 'none';
}
// Show modal
this.moodModal.classList.add('active');
this.createFloatingEmojis();
}
closeMoodModal() {
this.moodModal.classList.remove('active');
this.selectedDate = null;
this.selectedMood = null;
}
selectMood(option) {
// Clear previous selection
this.moodOptions.forEach(opt => opt.classList.remove('selected'));
// Select current option
option.classList.add('selected');
this.selectedMood = {
mood: option.dataset.mood,
emoji: option.dataset.emoji
};
// Add selection animation
option.style.animation = 'none';
setTimeout(() => {
option.style.animation = 'bounce 0.5s ease-in-out';
}, 10);
}
saveMood() {
if (this.selectedMood && this.selectedDate) {
this.moods[this.selectedDate] = {
...this.selectedMood,
timestamp: Date.now()
};
// Save to localStorage
localStorage.setItem('moodData', JSON.stringify(this.moods));
// Show success notification
this.showNotification(`Mood saved for ${this.selectedDate}! 💕`, 'success');
// Close modal and refresh calendar
this.closeMoodModal();
this.renderCalendar();
// Add celebration effect
this.createCelebrationEffect();
} else {
this.showNotification('Please select a mood first!', 'error');
}
}
deleteMood() {
if (this.selectedDate && this.moods[this.selectedDate]) {
delete this.moods[this.selectedDate];
localStorage.setItem('moodData', JSON.stringify(this.moods));
this.showNotification(`Mood deleted for ${this.selectedDate}`, 'info');
this.closeMoodModal();
this.renderCalendar();
}
}
showNotification(message, type = 'info') {
const notification = document.createElement('div');
notification.className = `notification ${type}`;
notification.textContent = message;
notification.style.cssText = `
position: fixed;
top: 100px;
right: 20px;
background: ${type === 'error' ? '#ff6b6b' : type === 'success' ? '#51cf66' : '#ff69b4'};
color: white;
padding: 1rem 1.5rem;
border-radius: 20px;
box-shadow: 0 12px 40px rgba(255, 105, 180, 0.2);
z-index: 10000;
transform: translateX(400px);
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
font-weight: 500;
`;
document.body.appendChild(notification);
setTimeout(() => {
notification.style.transform = 'translateX(0)';
}, 100);
setTimeout(() => {
notification.style.transform = 'translateX(400px)';
setTimeout(() => {
document.body.removeChild(notification);
}, 300);
}, 3000);
}
createFloatingEmojis() {
const emojis = ['💕', '🌟', '✨', '🦋', '🌸'];
for (let i = 0; i < 5; i++) {
setTimeout(() => {
const emoji = document.createElement('div');
emoji.textContent = emojis[Math.floor(Math.random() * emojis.length)];
emoji.style.cssText = `
position: fixed;
left: ${Math.random() * window.innerWidth}px;
top: ${window.innerHeight + 50}px;
font-size: 1.5rem;
pointer-events: none;
z-index: 9999;
animation: floatUp 4s ease-out forwards;
`;
document.body.appendChild(emoji);
setTimeout(() => {
if (emoji.parentNode) {
emoji.parentNode.removeChild(emoji);
}
}, 4000);
}, i * 200);
}
}
createCelebrationEffect() {
const celebration = ['🎉', '🎊', '✨', '🌟', '💫'];
const center = {
x: window.innerWidth / 2,
y: window.innerHeight / 2
};
for (let i = 0; i < 12; i++) {
setTimeout(() => {
const particle = document.createElement('div');
particle.textContent = celebration[Math.floor(Math.random() * celebration.length)];
const angle = (i * 30) * Math.PI / 180;
const distance = 100 + Math.random() * 100;
particle.style.cssText = `
position: fixed;
left: ${center.x}px;
top: ${center.y}px;
font-size: ${1 + Math.random()}rem;
pointer-events: none;
z-index: 9999;
animation: explode 2s ease-out forwards;
--end-x: ${Math.cos(angle) * distance}px;
--end-y: ${Math.sin(angle) * distance}px;
`;
document.body.appendChild(particle);
setTimeout(() => {
if (particle.parentNode) {
particle.parentNode.removeChild(particle);
}
}, 2000);
}, i * 50);
}
}
}
// Dynamically inject all necessary CSS animations and styles
const styleSheet = document.createElement('style');
styleSheet.textContent = `
@keyframes floatUp {
0% {
opacity: 1;
transform: translateY(0) scale(0.5) rotate(0deg);
}
100% {
opacity: 0;
transform: translateY(-200px) scale(1.2) rotate(360deg);
}
}
@keyframes explode {
0% {
opacity: 1;
transform: translate(0, 0) scale(0.5);
}
100% {
opacity: 0;
transform: translate(var(--end-x), var(--end-y)) scale(1.5);
}
}
@keyframes welcomeFloat {
0% {
opacity: 0;
transform: translateY(50px) scale(0.5);
}
50% {
opacity: 1;
transform: translateY(-20px) scale(1.2);
}
100% {
opacity: 0;
transform: translateY(-100px) scale(0.8) rotate(360deg);
}
}
.calendar-days {
transition: opacity 0.3s ease-in-out;
}
.mood-option {
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.mood-option:hover {
transform: translateY(-5px) scale(1.05);
}
.mood-option.selected {
background: linear-gradient(135deg, #ffb6c1, #ff69b4);
color: white;
box-shadow: 0 8px 30px rgba(255, 105, 180, 0.3);
}
.calendar-day {
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.calendar-day:hover:not(.other-month) {
background: linear-gradient(135deg, #ffe4e1, #ffb6c1);
transform: scale(1.05);
box-shadow: 0 4px 20px rgba(255, 105, 180, 0.2);
}
.calendar-day.today {
animation: todayPulse 2s ease-in-out infinite;
}
@keyframes todayPulse {
0%, 100% {
box-shadow: 0 0 0 0 rgba(255, 105, 180, 0.7);
}
50% {
box-shadow: 0 0 0 10px rgba(255, 105, 180, 0);
}
}
.has-mood .day-mood {
animation: moodBounce 1s ease-in-out;
}
@keyframes moodBounce {
0%, 20%, 50%, 80%, 100% {
transform: translateY(0);
}
40% {
transform: translateY(-10px);
}
60% {
transform: translateY(-5px);
}
}
`;
document.head.appendChild(styleSheet);
// Initialize the app once the DOM is fully loaded
document.addEventListener('DOMContentLoaded', function () {
// Initialize mobile menu toggle if it exists
const menuToggle = document.getElementById('menuToggle');
const nav = document.querySelector('.nav');
if (menuToggle && nav) {
menuToggle.addEventListener('click', function () {
nav.classList.toggle('active');
});
}
// Initialize the main mood calendar application
new MoodCalendar();
// Trigger a welcome animation on page load
setTimeout(() => {
const welcomeEmojis = ['🌱', '💕', '✨', '🌟', '🦋'];
welcomeEmojis.forEach((emoji, index) => {
setTimeout(() => {
const el = document.createElement('div');
el.textContent = emoji;
el.style.cssText = `
position: fixed;
left: ${20 + index * 80}px;
top: 150px;
font-size: 2rem;
pointer-events: none;
z-index: 1000;
animation: welcomeFloat 3s ease-out forwards;
`;
document.body.appendChild(el);
setTimeout(() => {
if (el.parentNode) {
el.parentNode.removeChild(el);
}
}, 3000);
}, index * 200);
});
}, 500);
// ===== START: CHATBOT LOGIC (User Input Only) =====
const chatbotContainer = document.getElementById('chatbotContainer');
const startChatBtn = document.getElementById('startChatBtn');
const chatToggleBtn = document.getElementById('chatToggleBtn');
const closeChatbotBtn = document.getElementById('closeChatbotBtn');
const chatbotMessages = document.getElementById('chatbotMessages');
const chatbotInput = document.getElementById('chatbotInput');
const chatbotSendBtn = document.getElementById('chatbotSendBtn');
/**
* Toggles the visibility of the chatbot window with a CSS class.
*/
const toggleChatbot = () => {
chatbotContainer.classList.toggle('active');
};
// Event listeners to open and close the chatbot
startChatBtn.addEventListener('click', toggleChatbot);
chatToggleBtn.addEventListener('click', toggleChatbot);
closeChatbotBtn.addEventListener('click', toggleChatbot);
/**
* Creates a new message bubble and adds it to the chat window.
* @param {string} message - The text content of the message.
* @param {string} sender - The sender of the message ('user' or 'bot').
*/
const addMessage = (message, sender) => {
const messageWrapper = document.createElement('div');
messageWrapper.classList.add(`${sender}-message`);
const messageBubble = document.createElement('p');
messageBubble.textContent = message;
messageWrapper.appendChild(messageBubble);
chatbotMessages.appendChild(messageWrapper);
// Automatically scroll to the latest message
chatbotMessages.scrollTop = chatbotMessages.scrollHeight;
};
/**
* Handles the sending of a message from the user input field.
* This version ONLY displays the user's message.
*/
const handleSendMessage = () => {
const message = chatbotInput.value;
if (message.trim() === "") return; // Do nothing if the input is empty
// Add the user's message to the chat window
addMessage(message, 'user');
// Clear the input field after sending
chatbotInput.value = '';
};
// Event listener for the send button
chatbotSendBtn.addEventListener('click', handleSendMessage);
// Event listener for pressing "Enter" in the input field
chatbotInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
handleSendMessage();
}
});
// ===== END: CHATBOT LOGIC =====
console.log('🌱💕 Mood Calendar loaded! Ready to track your emotional journey! ✨');
});