fisharebest / webtrees

Online genealogy
https://webtrees.net
GNU General Public License v3.0
457 stars 298 forks source link

Individual tabs - initial state of check boxes #4527

Closed ddrury closed 2 years ago

ddrury commented 2 years ago

Since commit https://github.com/fisharebest/webtrees/commit/f0ecc9a9ae19c64e946ac4b65cc1bb4ff475956e all the checkboxes (Associated events, Events of close relatives, Historic events, Date differences, Show all * etc) default to checked whereas prior to this commit the default was unchecked which I preferred.

ddrury commented 2 years ago

The problem in function webtrees.persistentToggle is that localStorage.getItem() returns null for a non-existent item, therefore the line if (previous_state !== current_state) { will be true thus clicking the element.

Changing the line var previous_state = localStorage.getItem(key); to var previous_state = localStorage.getItem(key) || 'false'; solves the problem

(or change the string representation of boolean values to proper booleans)

ddrury commented 2 years ago

Maybe I'm being really stupid (likely!) but why not just use

if (localStorage.getItem(key) === 'true') {
  element.click();
}
fisharebest commented 2 years ago

change the string representation of boolean values to proper booleans

The aria-expanded attribute is a string ("true" or "false"), so we need to convert one way or the other...

but why not just use

I want this to work with with things that are initially expanded as well as initially collapsed.

I think we just need to check whether the previous value is not-null...