Add initState parameter

main
Alex P 3 years ago
parent bb0370b027
commit 5e8c212c9d

@ -20,6 +20,12 @@ If one of the sections (`above`/`below`) contains HTML (e.g. from another shortc
unsafe = true
```
# Parameters
| Name | Accepted values | Default | Description |
| ---- | --- | --- | --- |
| `initState` | `closed`, `open` | `closed` | The initial state of the collapsible |
# Demo
```

@ -1,4 +1,10 @@
<div class="hugo-collapse-parent">
<!-- parameter sanity check -->
{{ if not (in "open closed" (default "closed" (.Get "initState"))) }}
{{ errorf "Failed to handle page %q: param \"initState\" only takes [open, closed]; got %s" .Page.Path (.Get "init")}}
{{ end }}
<div class="hugo-collapse-parent {{ if eq (default "closed" (.Get "initState")) "closed" }}closed{{ end }}">
<!-- prevent common resources from being loaded more than once per page -->
{{ if not ($.Page.Scratch.Get "collapseLoaded") }}
{{ $.Page.Scratch.Set "collapseLoaded" 1 }}

@ -12,7 +12,7 @@ var callback = function() {
a.addEventListener('click', toggleCollapse, false);
a.className = 'collapseAnchor';
a.href="#"; /* without this it's not keyboard focusable */
wrap.classList.add('closed', 'collapseWrap');
wrap.classList.add('collapseWrap');
} // for hook
function toggleCollapse(e) {
e.preventDefault();

Loading…
Cancel
Save