___ ___ _____ _ ( _`\ ( _`\ ( _ ) _ ( ) | (_(_)| |_) )| (_) |(_) ___ | |__ `\__ \ | ,__/'| _ || |/',__)| _ `\ ( )_) || | | | | || |\__, \| | | | `\____)(_) (_) (_)(_)(____/(_) (_) A PicoSSG tool

spaish.details

API for preserving the open/closed state of <details> elements across page loads.

reopen()

Method signature: reopen([{key?: string, nodes?: string[] | NodeList}])

Stores which details elements are open before page unload and reopens them on page load. The entire options object is optional. Can be called as:

Parameters

Description

The function sets up two main behaviors:

Storage (on beforeunload)

Restoration (immediate)

DOM Requirements

Storage Details

Example

// Using selector arrays
spaish.details.reopen('faq-page', [
  '#frequently-asked-questions',
  '#troubleshooting-section',
  '.expandable-info'
]);

// Using NodeList
const detailsElements = document.querySelectorAll('details.collapsible');
spaish.details.reopen('interactive-sections', detailsElements);

// Without selectors - affects all details elements on the page
spaish.details.reopen('all-details');

// Cross-page navigation menu state
spaish.details.reopen({key: 'site-navigation', nodes: [
  '#main-menu',
  '#sidebar-sections'
]});

// Multiple selectors for flexible targeting
spaish.details.reopen({key: 'docs', nodes: [
  '[data-section="api"]',
  '[data-section="examples"]',
  'details.collapsible'
]});

Selector Behavior

Cross-Page Functionality

Error Handling

Browser Events

Performance Notes

autoOpen()

Method signature: autoOpen([{nodes?: string[] | NodeList}])

Automatically opens <details> elements that contain links matching the current page URL.

Parameters

Description

Example

// Auto-open all <details> elements that contain links to the current page
spaish.details.autoOpen();

// Auto-open navigation sections containing current page links
spaish.details.autoOpen({nodes: ['#navigation-menu', '.sidebar-sections']});

// Works with NodeList too
const menuElements = document.querySelectorAll('.nav-details');
spaish.details.autoOpen({nodes: menuElements});

// Combined usage with reopen
spaish.details.reopen({key: 'nav-state', nodes: ['#navigation']});
spaish.details.autoOpen({nodes: ['#navigation']});

Use Cases

Link Matching

DOM Requirements

scrollOnToggle()

Method signature: scrollOnToggle([{nodes?: string[] | NodeList} | ScrollIntoViewOptions])

Scrolls the content of the <details> element(s) into view when toggled. Can be called as:

Parameters

Via the nodes option you can set which <details> elements should be scrolled into view when toggled.

All the options other than nodes are ScrollIntoViewOptions as the DOM method scrollIntoView() method accepts them, they are just passed through.

Example

// Enable smooth scrolling for all <details> elements
spaish.details.scrollOnToggle();
// Or target specific elements
spaish.details.scrollOnToggle({
  nodes: document.querySelectorAll('.collapsible-sections')
});
// Custom scroll behavior
spaish.details.scrollOnToggle({
  behavior: 'smooth',
  block: 'start',
  inline: 'nearest'
});