|
|
|
@ -8,3 +8,45 @@ document.querySelectorAll('.more-link').forEach(link => { |
|
|
|
link.setAttribute('aria-expanded', container.classList.contains('full')); |
|
|
|
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'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|