You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
2.0 KiB
52 lines
2.0 KiB
document.querySelectorAll('.more-link').forEach(link => { |
|
link.addEventListener('click', (e) => { |
|
e.preventDefault(); |
|
// Find the parent text-container and then the truncated-text div |
|
const container = link.closest('.text-container').querySelector('.truncated-text'); |
|
container.classList.toggle('full'); |
|
link.textContent = container.classList.contains('full') ? 'Less' : 'More'; |
|
link.setAttribute('aria-expanded', container.classList.contains('full')); |
|
}); |
|
}); |
|
|
|
const p = document.querySelector('.node-6729 .view-abstract-block-for-collections-info-block p'); |
|
if (p) { |
|
const fullText = p.textContent.trim(); |
|
const words = fullText.split(/\s+/); |
|
if (words.length > 100) { |
|
// Truncate to 100 words |
|
const truncated = words.slice(0, 100).join(' ') + '...'; |
|
p.textContent = truncated; |
|
p.dataset.fullText = fullText; // Store full text |
|
p.dataset.isTruncated = 'true'; // Track truncation state |
|
|
|
// Create and append the "More" link in a <p> tag |
|
const linkP = document.createElement('p'); |
|
const link = document.createElement('a'); |
|
link.href = '#'; |
|
link.className = 'more-link'; |
|
link.textContent = 'More'; |
|
link.setAttribute('aria-expanded', 'false'); |
|
link.setAttribute('aria-controls', 'truncated-p-6729'); // Unique ID for ARIA |
|
p.id = 'truncated-p-6729'; // Assign ID to <p> for ARIA |
|
linkP.appendChild(link); |
|
p.parentNode.insertBefore(linkP, p.nextSibling); |
|
|
|
// Add click event to toggle text |
|
link.addEventListener('click', (e) => { |
|
e.preventDefault(); |
|
const isTruncated = p.dataset.isTruncated === 'true'; |
|
if (isTruncated) { |
|
p.textContent = p.dataset.fullText; |
|
link.textContent = 'Less'; |
|
p.dataset.isTruncated = 'false'; |
|
link.setAttribute('aria-expanded', 'true'); |
|
} else { |
|
p.textContent = words.slice(0, 100).join(' ') + '...'; |
|
link.textContent = 'More'; |
|
p.dataset.isTruncated = 'true'; |
|
link.setAttribute('aria-expanded', 'false'); |
|
} |
|
}); |
|
} |
|
}
|
|
|