2019-02-19 14:29:06 +01:00
|
|
|
import { delegate, toggle } from '@utils';
|
|
|
|
|
|
|
|
// Unobtrusive Javascript for allowing an element to toggle
|
|
|
|
// the visibility of another element.
|
|
|
|
//
|
|
|
|
// Usage:
|
|
|
|
// <button data-toggle-target="#target">Toggle</button>
|
|
|
|
// <div id="target">Content</div>
|
|
|
|
|
|
|
|
const TOGGLE_SOURCE_SELECTOR = '[data-toggle-target]';
|
|
|
|
|
2020-04-30 15:42:29 +02:00
|
|
|
delegate('click', TOGGLE_SOURCE_SELECTOR, (evt) => {
|
2019-02-19 14:29:06 +01:00
|
|
|
evt.preventDefault();
|
|
|
|
|
|
|
|
const targetSelector = evt.target.dataset.toggleTarget;
|
|
|
|
const targetElements = document.querySelectorAll(targetSelector);
|
|
|
|
for (let target of targetElements) {
|
|
|
|
toggle(target);
|
2021-03-16 11:33:39 +01:00
|
|
|
target.focus();
|
2019-02-19 14:29:06 +01:00
|
|
|
}
|
|
|
|
});
|