Changes for page Alder Support Center scripts
Last modified by wiki admin on 2026/08/26 01:04
From version 6.1
edited by wiki admin
on 2026/08/24 22:13
on 2026/08/24 22:13
Change comment:
There is no comment for this version
To version 1.1
edited by wiki admin
on 2026/08/24 21:04
on 2026/08/24 21:04
Change comment:
There is no comment for this version
Summary
-
Page properties (1 modified, 0 added, 0 removed)
-
Objects (0 modified, 0 added, 1 removed)
Details
- Page properties
-
- Content
-
... ... @@ -1,1 +1,1 @@ 1 -Article accordion. Edit the object, not this text. 1 +Article accordion for the customer-facing design. Edit the object, not this text.
- XWiki.JavaScriptExtension[0]
-
- Code
-
... ... @@ -1,145 +1,0 @@ 1 -/* =========================================================================== 2 - Alder Support Center - article accordion 3 - Goes in an XWiki.JavaScriptExtension object on AlderTheme.Scripts (alder wiki). 4 - 5 - Turns each top-level H2 inside #xwikicontent into a collapsible section, so a 6 - long omnibus article becomes a short list of section titles. No article needs 7 - editing: the sections come from headings the content already has. 8 - 9 - Deliberate behaviours, all reversible by disabling this object: 10 - * Sections open independently. Opening one does not close another. 11 - * The first section starts open, so the page never looks empty. 12 - * Fewer than two H2s: nothing happens, the article renders normally. 13 - * Edit/preview modes are skipped, or authors would be editing generated 14 - markup. 15 - * A link to a heading inside a collapsed section opens that section and 16 - scrolls to it, including on first load and on later hash changes. 17 - =========================================================================== */ 18 -(function () { 19 - 'use strict'; 20 - 21 - var MIN_SECTIONS = 2; 22 - 23 - function ready(fn) { 24 - if (document.readyState === 'loading') { 25 - document.addEventListener('DOMContentLoaded', fn); 26 - } else { 27 - fn(); 28 - } 29 - } 30 - 31 - function chevron() { 32 - var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); 33 - svg.setAttribute('class', 'alder-chev'); 34 - svg.setAttribute('viewBox', '0 0 24 24'); 35 - var path = document.createElementNS('http://www.w3.org/2000/svg', 'path'); 36 - path.setAttribute('d', 'M6 9l6 6 6-6'); 37 - svg.appendChild(path); 38 - return svg; 39 - } 40 - 41 - function isWikiHome() { 42 - // The employees home page has several H2s (departments, article status, 43 - // publishing workflow). Collapsing a landing page into rows hides the 44 - // thing people came for, so skip it. Matches both URL schemes this 45 - // deployment serves: /bin/view/Main/ and /wiki/<name>/view/Main/. 46 - var path = (window.location.pathname || '').replace(/\/+$/, ''); 47 - return /\/view\/Main(\/WebHome)?$/.test(path); 48 - } 49 - 50 - function build() { 51 - var body = document.body; 52 - if (!body || body.className.indexOf('viewbody') === -1) { 53 - return; // edit, preview, or anything that is not a rendered page 54 - } 55 - if (isWikiHome()) { return; } 56 - var content = document.getElementById('xwikicontent'); 57 - if (!content) { return; } 58 - 59 - // Only top-level headings. An h2 nested inside a table or a macro box is 60 - // part of that structure and must not be torn out of it. 61 - var headings = []; 62 - for (var i = 0; i < content.children.length; i++) { 63 - if (content.children[i].tagName === 'H2') { headings.push(content.children[i]); } 64 - } 65 - if (headings.length < MIN_SECTIONS) { return; } 66 - 67 - var made = []; 68 - headings.forEach(function (h2, index) { 69 - var details = document.createElement('details'); 70 - details.className = 'alder-sec'; 71 - if (index === 0) { details.open = true; } 72 - 73 - var summary = document.createElement('summary'); 74 - var title = document.createElement('span'); 75 - title.className = 'alder-sec-title'; 76 - title.textContent = (h2.textContent || '').trim(); 77 - summary.appendChild(title); 78 - summary.appendChild(chevron()); 79 - details.appendChild(summary); 80 - 81 - var wrap = document.createElement('div'); 82 - wrap.className = 'alder-sec-body'; 83 - details.appendChild(wrap); 84 - 85 - // Keep the heading's id on the details element so existing anchors and 86 - // the table-of-contents macro still resolve to something. 87 - if (h2.id) { details.id = h2.id; h2.removeAttribute('id'); } 88 - 89 - content.insertBefore(details, h2); 90 - 91 - // Move the heading and everything up to the next h2 into the body. 92 - var node = h2; 93 - while (node && !(node !== h2 && node.tagName === 'H2')) { 94 - var next = node.nextSibling; 95 - wrap.appendChild(node); 96 - node = next; 97 - if (node && node.nodeType === 1 && node.tagName === 'H2') { break; } 98 - } 99 - made.push(details); 100 - }); 101 - 102 - if (!made.length) { return; } 103 - 104 - var tools = document.createElement('div'); 105 - tools.className = 'alder-tools'; 106 - tools.appendChild(button('Expand all', true, made)); 107 - tools.appendChild(button('Collapse all', false, made)); 108 - content.insertBefore(tools, made[0]); 109 - 110 - openFromHash(); 111 - window.addEventListener('hashchange', openFromHash); 112 - } 113 - 114 - function button(label, open, sections) { 115 - var b = document.createElement('button'); 116 - b.type = 'button'; 117 - b.textContent = label; 118 - b.addEventListener('click', function () { 119 - sections.forEach(function (d) { d.open = open; }); 120 - }); 121 - return b; 122 - } 123 - 124 - function openFromHash() { 125 - var hash = window.location.hash; 126 - if (!hash || hash.length < 2) { return; } 127 - var id = hash.slice(1); 128 - var target = null; 129 - try { 130 - target = document.getElementById(id); 131 - } catch (e) { 132 - return; 133 - } 134 - if (!target) { return; } 135 - // Open the target itself if it is a section, plus any collapsed ancestor. 136 - var node = target; 137 - while (node && node !== document.body) { 138 - if (node.tagName === 'DETAILS') { node.open = true; } 139 - node = node.parentNode; 140 - } 141 - if (target.scrollIntoView) { target.scrollIntoView(); } 142 - } 143 - 144 - ready(build); 145 -})(); - Name
-
... ... @@ -1,1 +1,0 @@ 1 -Article accordion - Parse content
-
... ... @@ -1,1 +1,0 @@ 1 -No - Use this extension
-
... ... @@ -1,1 +1,0 @@ 1 -always