openvibers/openvibe.services Commits

A fold says what it holds, counted, not "tap to open" (#187)

OP OpenVibers committed 11 days ago · 4a0b1d257c · 1 file, +16 −2

Changes

ddiff --git a/server/render/short.js b/server/render/short.js
iindex 5a17682..4cd62f2 100644
---- a/server/render/short.js
++++ b/server/render/short.js
@@@ -33,13 +33,27 @@ function pickRules(key, ids) {
return ids.map((id) => `.pick:has(#pk-${key}-${id}:checked) #pp-${key}-${id}{display:block}`).join('');
}
++/**
++ * What a fold holds, counted, for its title row (the owner, 2026-10-31: a fold that shortens a page shows its count):
++ * "6 questions", "12 items", "latest 5" for the shipped list, or nothing when there is nothing to count. Replaces the
++ * old "tap to open".
++ */
++function foldMeta(body, cls = '') {
++ const s = typeof body === 'string' ? body : String((body && (body.s || body.html || body.value)) || body || '');
++ const n = (re) => (s.match(re) || []).length;
++ const shipped = /data-ov-shipped="list"[^>]*?data-limit="(\d+)"|data-limit="(\d+)"[^>]*?data-ov-shipped="list"/.exec(s);
++ const q = n(/<details[\s>]/g), li = n(/<li[\s>]/g), a = n(/<a\s/g);
++ const text = shipped ? `latest ${shipped[1] || shipped[2]}` : q > 1 ? `${q} questions` : li > 1 ? `${li} items` : a > 1 ? `${a} links` : '';
++ return text ? `<span${cls ? ` class="${cls}"` : ''}>${text}</span>` : '';
++}
++
/**
* A fold. The head is the heading the block had; the html is what it holds.
*
* foldBlock({ id, head, html })
*/
function foldBlock({ id, head, html }) {
-- return `<details class="svc-fold svc-fold-block" id="${esc(id)}" open><summary>${head}<span>tap to open</span></summary>${html}</details>${foldScript(id)}`;
++ return `<details class="svc-fold svc-fold-block" id="${esc(id)}" open><summary>${head}${foldMeta(html)}</summary>${html}</details>${foldScript(id)}`;
}
/** The script a fold carries: closed on a phone unless the reader opened it before, and it remembers that. */
@@@ -47,4 +61,4 @@ function foldScript(id) {
return `<script>(function(){var d=document.getElementById(${JSON.stringify(id)});if(!d)return;var k='ov_fold_'+${JSON.stringify(id)};var s=null;try{s=localStorage.getItem(k)}catch(e){}if(s==='open'){d.open=true;return}if(s==='closed'){d.open=false;return}var t=0;if(window.matchMedia&&window.matchMedia('(max-width:640px)').matches){t=Date.now();d.open=false}d.addEventListener('toggle',function(){if(Date.now()-t<300)return;try{localStorage.setItem(k,d.open?'open':'closed')}catch(e){}})})();</script>`;
}
--module.exports = { pickBlock, pickRules, foldBlock, foldScript };
++module.exports = { pickBlock, pickRules, foldBlock, foldMeta, foldScript };