Skip to content
(function(){
var desc = document.querySelector('.term-description');
if (!desc) return;
// Find the comment node
var moreNode = null;
var moreParent = null;
function findMore(node) {
node.childNodes.forEach(function(child) {
if (child.nodeType === 8 && child.nodeValue.trim() === 'more') {
moreNode = child;
moreParent = node;
} else if (child.childNodes && child.childNodes.length) {
findMore(child);
}
});
}
findMore(desc);
if (!moreNode) return;
// Collect all nodes in .term-description that come after the paragraph containing
var children = Array.from(desc.childNodes);
var moreTopParent = moreParent;
while (moreTopParent && moreTopParent.parentNode !== desc) {
moreTopParent = moreTopParent.parentNode;
}
var foundMore = false;
var toHide = [];
children.forEach(function(child) {
if (child === moreTopParent) { foundMore = true; return; }
if (foundMore) toHide.push(child);
});
if (!toHide.length) return;
// Wrap hidden content
var wrapper = document.createElement('div');
wrapper.className = 'term-description-more';
toHide.forEach(function(node) { wrapper.appendChild(node); });
desc.appendChild(wrapper);
// Add toggle button
var btn = document.createElement('button');
btn.className = 'term-description-toggle';
btn.textContent = 'Read more';
btn.addEventListener('click', function() {
var open = wrapper.classList.toggle('is-open');
btn.textContent = open ? 'Read less' : 'Read more';
});
moreTopParent.appendChild(btn);
})();