|
| 1 | +/** |
| 2 | + * Collapsible "Subclassed by" list behavior. |
| 3 | + * Finds paragraphs starting with "Subclassed by" that have more than 5 items, |
| 4 | + * collapses them to a single line, and adds a "See All" / "Hide" toggle button. |
| 5 | + * |
| 6 | + * Breathe/Doxygen renders "Subclassed by" in a <p> tag. The subclass names may |
| 7 | + * be <a> links (when targets exist) or plain text (when they don't). We count |
| 8 | + * both to determine whether to collapse. |
| 9 | + */ |
| 10 | +document.addEventListener('DOMContentLoaded', function() { |
| 11 | + var paragraphs = document.querySelectorAll('p'); |
| 12 | + |
| 13 | + paragraphs.forEach(function(p) { |
| 14 | + var text = p.textContent.trim(); |
| 15 | + if (!text.startsWith('Subclassed by')) return; |
| 16 | + |
| 17 | + // Count items: use <a> links if present, otherwise count comma-separated entries |
| 18 | + var links = p.querySelectorAll('a'); |
| 19 | + var itemCount = links.length; |
| 20 | + if (itemCount <= 5) { |
| 21 | + // Links may not exist (plain text subclass names). Count comma-separated items. |
| 22 | + var afterLabel = text.replace(/^Subclassed by\s*/, ''); |
| 23 | + var commaCount = afterLabel.split(',').filter(function(s) { return s.trim().length > 0; }).length; |
| 24 | + if (commaCount > itemCount) { |
| 25 | + itemCount = commaCount; |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + if (itemCount > 5) { |
| 30 | + p.classList.add('subclassed-by-list', 'collapsed'); |
| 31 | + |
| 32 | + var toggle = document.createElement('button'); |
| 33 | + toggle.className = 'subclassed-by-toggle'; |
| 34 | + toggle.textContent = 'See All (' + itemCount + ')'; |
| 35 | + toggle.type = 'button'; |
| 36 | + |
| 37 | + toggle.addEventListener('click', function(e) { |
| 38 | + e.preventDefault(); |
| 39 | + |
| 40 | + if (p.classList.contains('collapsed')) { |
| 41 | + p.classList.remove('collapsed'); |
| 42 | + p.classList.add('expanded'); |
| 43 | + toggle.textContent = 'Hide'; |
| 44 | + } else { |
| 45 | + p.classList.remove('expanded'); |
| 46 | + p.classList.add('collapsed'); |
| 47 | + toggle.textContent = 'See All (' + itemCount + ')'; |
| 48 | + } |
| 49 | + }); |
| 50 | + |
| 51 | + p.appendChild(toggle); |
| 52 | + } |
| 53 | + }); |
| 54 | +}); |
0 commit comments