-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.js
More file actions
162 lines (136 loc) · 5.4 KB
/
main.js
File metadata and controls
162 lines (136 loc) · 5.4 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
document.addEventListener('DOMContentLoaded', function() {
const meetupContainer = document.getElementById('meetups-container');
const scrollLeftBtn = document.getElementById('meetups-scroll-left');
const scrollRightBtn = document.getElementById('meetups-scroll-right');
if (scrollLeftBtn && scrollRightBtn && meetupContainer) {
const leftmostElemIsShown = () => {
let { clientWidth, scrollLeft, scrollWidth } = meetupContainer
scrollLeft = Math.abs(scrollLeft)
errorMargin = scrollWidth * 0.01
res = (scrollLeft > scrollWidth - clientWidth - errorMargin)
return res
}
const rightmostElemIsShown = () => {
let { scrollLeft, scrollWidth } = meetupContainer
scrollLeft = Math.abs(scrollLeft)
errorMargin = scrollWidth * 0.01
res = (scrollLeft < errorMargin)
return res
}
const deactivate = (button) => {
button.classList.add('opacity-0');
button.classList.remove('opacity-100', 'hover:cursor-pointer', 'hover:scale-125');
button.disabled = true;
}
const activate = (button) => {
button.classList.add('opacity-100', 'hover:cursor-pointer', 'hover:scale-125');
button.classList.remove('opacity-0');
button.disabled = false;
}
// Function to update button visibility
const updateButtonVisibility = () => {
// Check if the container is scrolled to the left
if (leftmostElemIsShown()) {
deactivate(scrollLeftBtn)
} else {
activate(scrollLeftBtn)
}
// Check if the container is scrolled to the right
if (rightmostElemIsShown()) {
deactivate(scrollRightBtn)
} else {
activate(scrollRightBtn)
}
};
// Initial check on page load
updateButtonVisibility();
// Scroll Left Button
scrollLeftBtn.addEventListener('click', () => {
const containerWidth = meetupContainer.clientWidth;
meetupContainer.scrollBy({
left: -containerWidth,
behavior: 'smooth'
});
});
// Scroll Right Button
scrollRightBtn.addEventListener('click', () => {
const containerWidth = meetupContainer.clientWidth;
meetupContainer.scrollBy({
left: containerWidth,
behavior: 'smooth'
});
});
// Update buttons after scrolling
meetupContainer.addEventListener('scroll', () => {
// Throttle the updates to improve performance
clearTimeout(meetupContainer.updateTimer);
meetupContainer.updateTimer = setTimeout(updateButtonVisibility, 100);
});
// Also update on window resize in case the container size changes
window.addEventListener('resize', updateButtonVisibility);
} else {
console.error('One or more required elements are missing from the DOM');
}
});
document.addEventListener('DOMContentLoaded', () => {
const abstracts = document.querySelectorAll('.abstract-wrapper');
abstracts.forEach(abstract => {
const content = abstract.querySelector('.abstract-content');
const button = abstract.querySelector('.toggle-button');
const fadeOverlay = abstract.querySelector('.fade-overlay');
// Function to determine if the content is truncated
const isTruncated = () => {
return content.scrollHeight > content.clientHeight;
};
// Show or hide the toggle button and fade overlay based on truncation
if (isTruncated()) {
button.classList.remove('hidden');
fadeOverlay.classList.remove('hidden');
} else {
button.classList.add('hidden');
fadeOverlay.classList.add('hidden');
}
});
const toggleButtons = document.querySelectorAll('.toggle-button');
toggleButtons.forEach(button => {
button.addEventListener('click', () => {
const abstract = button.closest('.abstract-wrapper');
const content = abstract.querySelector('.abstract-content');
const fadeOverlay = abstract.querySelector('.fade-overlay');
// Toggle the line-clamp class
content.classList.toggle('line-clamp-[8]');
if (content.classList.contains('line-clamp-[8]')) {
// If content is clamped, show the fade overlay and set button to "Show More"
fadeOverlay.classList.remove('hidden');
button.querySelector('.button-text').textContent = 'Show More';
} else {
// If content is expanded, hide the fade overlay and set button to "Show Less"
fadeOverlay.classList.add('hidden');
button.querySelector('.button-text').textContent = 'Show Less';
}
});
});
// Re-evaluate on window resize
window.addEventListener('resize', () => {
abstracts.forEach(abstract => {
const content = abstract.querySelector('.abstract-content');
const button = abstract.querySelector('.toggle-button');
const fadeOverlay = abstract.querySelector('.fade-overlay');
// Reset line-clamp to check truncation accurately
content.classList.add('line-clamp-[8]');
fadeOverlay.classList.add('hidden');
if (content.scrollHeight > content.clientHeight) {
button.classList.remove('hidden');
fadeOverlay.classList.remove('hidden');
// Reset content to clamped state if it was expanded
if (!content.classList.contains('line-clamp-[8]')) {
content.classList.add('line-clamp-[8]');
button.querySelector('.button-text').textContent = 'Show More';
}
} else {
button.classList.add('hidden');
fadeOverlay.classList.add('hidden');
}
});
});
});