Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const doc: Document = getRoot();
const targetElement: ?Element = doc.getElementById(targetId);
if (!targetElement) {
return;
}
// Toggle the hide attribute of the target
const isCurrentlyHidden: boolean =
targetElement.getAttribute('hide') === 'true';
const newToggleState: string = isCurrentlyHidden ? 'false' : 'true';
targetElement.setAttribute('hide', newToggleState);
let newRoot: Document = shallowCloneToRoot(targetElement);
// If using the delay, we need to undo the indicators shown earlier.
if (delay > 0) {
newRoot = Behaviors.setIndicatorsAfterLoad(
showIndicatorIds,
hideIndicatorIds,
newRoot,
);
}
// Update the DOM with the new toggle state and finished indicators.
updateRoot(newRoot);
};
const showElement = () => {
const doc: Document = getRoot();
const targetElement: ?Element = doc.getElementById(targetId);
if (!targetElement) {
return;
}
// Show the target
targetElement.setAttribute('hide', 'false');
let newRoot: Document = shallowCloneToRoot(targetElement);
// If using delay, we need to undo the indicators shown earlier.
if (delay > 0) {
newRoot = Behaviors.setIndicatorsAfterLoad(
showIndicatorIds,
hideIndicatorIds,
newRoot,
);
}
// Update the DOM with the new shown state and finished indicators.
updateRoot(newRoot);
};
const hideElement = () => {
const doc: Document = getRoot();
const targetElement: ?Element = doc.getElementById(targetId);
if (!targetElement) {
return;
}
// Hide the target
targetElement.setAttribute('hide', 'true');
let newRoot: Document = shallowCloneToRoot(targetElement);
// If using delay, we need to undo the indicators shown earlier.
if (delay > 0) {
newRoot = Behaviors.setIndicatorsAfterLoad(
showIndicatorIds,
hideIndicatorIds,
newRoot,
);
}
// Update the DOM with the new hidden state and finished indicators.
updateRoot(newRoot);
};