diff options
author | Yorhel <git@yorhel.nl> | 2021-05-16 09:16:52 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2021-05-16 09:18:19 +0200 |
commit | 892af2bbbc9c7b6675708bf01f0ebd304014fa0f (patch) | |
tree | e0df8b9ab5bff01100e07e1c355c5ca8ad051bd5 /elm | |
parent | 9ee8ec09ed595cb024499e2fa67da083cc7edf4c (diff) |
VN::Page: Experiment with collapsable language sections
Fully MTL languages are collapsed by default. The state for languages is
remembered in the browsers' localStorage.
This is essentially a simple language filter and provides a partial
solution to https://vndb.org/t15877
Diffstat (limited to 'elm')
-rw-r--r-- | elm/remember-details.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/elm/remember-details.js b/elm/remember-details.js new file mode 100644 index 00000000..0f3e000a --- /dev/null +++ b/elm/remember-details.js @@ -0,0 +1,18 @@ +/* Simple script to remember the open/closed state of <details> elements. + * Usage: + * + * <details data-remember-id=".."> .. </details> + * + * This does have the downside of causing a DOM reflow if the elements' default + * state differs from the one stored by the user, and the preference is stored + * in the users' browser rather than their account, so it doesn't transfer. + */ +document.querySelectorAll('details[data-remember-id]').forEach(function(el) { + var sid = 'remember-details-'+el.getAttribute('data-remember-id'); + el.addEventListener('toggle', function() { + window.localStorage.setItem(sid, el.open ? '1' : ''); + }); + var val = window.localStorage.getItem(sid); + if(val != null) + el.open = val == '1' ? true : false; +}); |