avoid mutating DOM unnecessarily in toggleDataset()

This commit is contained in:
tophf 2021-08-13 12:15:58 +03:00
parent 598735fc7b
commit 54427c498d

View File

@ -337,10 +337,11 @@ async function showSpinner(parent) {
}
function toggleDataset(el, prop, state) {
const wasEnabled = el.dataset[prop] != null; // avoids mutating DOM unnecessarily
if (state) {
el.dataset[prop] = '';
if (!wasEnabled) el.dataset[prop] = '';
} else {
delete el.dataset[prop];
if (wasEnabled) delete el.dataset[prop];
}
}