mirror of
https://github.com/Snigdha-OS/documentation.git
synced 2025-09-13 20:14:56 +02:00
22 lines
705 B
JavaScript
22 lines
705 B
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
function makeRadioBehavior(eventName, itemClass, activeItemClass) {
|
|
return function radioBehavior($elements) {
|
|
$elements.forEach(($element) => {
|
|
$element.addEventListener(eventName, (event) => {
|
|
if (event.target && event.target.classList.contains(itemClass)) {
|
|
$element
|
|
.querySelectorAll('.' + itemClass)
|
|
.forEach(($elItem) => $elItem.classList.remove(activeItemClass));
|
|
event.target.classList.add(activeItemClass);
|
|
}
|
|
});
|
|
});
|
|
};
|
|
}
|