-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlisttemplatefooter.html
29 lines (29 loc) · 1.25 KB
/
listtemplatefooter.html
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
</div>
<script>
const cardTriggerMoreLess = function(ev) {
ev.preventDefault();
ev.target.classList.add('hidden');
const container = ev.target.parentElement;
const content = container.querySelector('.card-content');
if (content.classList.contains('line-clamp')) {
content.classList.remove('line-clamp');
container.querySelector('button.read-less').classList.remove('hidden');
} else {
content.classList.add('line-clamp');
container.querySelector('button.read-more').classList.remove('hidden');
}
};
document.addEventListener("DOMContentLoaded", (event) => {
const cards = document.querySelectorAll('div.card-content');
cards.forEach((el) => {
if (el.offsetHeight < el.scrollHeight || el.offsetWidth < el.scrollWidth) {
// element has overflow and is truncated, add event listener to read more / read less button
el.parentElement.querySelectorAll('button').forEach((b) => b.addEventListener("click", cardTriggerMoreLess, false));
} else {
// Remove the line-clamp class and hide the read more button because the content fits in the container.
el.classList.remove('line-clamp');
el.parentElement.querySelector('button.read-more').classList.add('hidden');
}
});
});
</script>