diff options
author | Guilhem Moulin <guilhem@fripost.org> | 2024-01-21 05:00:43 +0100 |
---|---|---|
committer | Guilhem Moulin <guilhem@fripost.org> | 2024-01-21 14:11:23 +0100 |
commit | 88f11622bb09f742248b8ea5593ec81718275f50 (patch) | |
tree | f242fe2fc8ad08bd5837f9cf6cea162b9e91e24f | |
parent | f2490078f0377fb93cd340404983b02ff4494168 (diff) |
Use .classList.replace() not .classList.remove() + .classList.add() for button toggling.
-rw-r--r-- | main.js | 24 |
1 files changed, 8 insertions, 16 deletions
@@ -281,16 +281,14 @@ if (window.location !== window.parent.location) { if (btn.getAttribute('aria-expanded') === 'true') { panel.setAttribute('aria-hidden', 'true'); btn.setAttribute('aria-expanded', 'false'); - btn.classList.add('btn-light'); - btn.classList.remove('btn-dark'); + btn.classList.replace('btn-dark', 'btn-light'); } else { if (btn2.getAttribute('aria-expanded') === 'true') { btn2.click(); } panel.setAttribute('aria-hidden', 'false'); btn.setAttribute('aria-expanded', 'true'); - btn.classList.add('btn-dark'); - btn.classList.remove('btn-light'); + btn.classList.replace('btn-light', 'btn-dark'); } }; @@ -299,16 +297,14 @@ if (window.location !== window.parent.location) { if (btn2.getAttribute('aria-expanded') === 'true') { panel2.setAttribute('aria-hidden', 'true'); btn2.setAttribute('aria-expanded', 'false'); - btn2.classList.add('btn-light'); - btn2.classList.remove('btn-dark'); + btn2.classList.replace('btn-dark', 'btn-light'); } else { if (btn.getAttribute('aria-expanded') === 'true') { btn.click(); } panel2.setAttribute('aria-hidden', 'false'); btn2.setAttribute('aria-expanded', 'true'); - btn2.classList.add('btn-dark'); - btn2.classList.remove('btn-light'); + btn2.classList.replace('btn-light', 'btn-dark'); } }; })(); @@ -338,8 +334,7 @@ if (window.location !== window.parent.location) { control.addEventListener('enterfullscreen', function() { const btn = control.element.getElementsByTagName('button')[0]; - btn.classList.add(classActive); - btn.classList.remove(classInactive); + btn.classList.replace(classInactive, classActive); btn.title = titleActive; const exp = document.getElementById('export-to-image'); @@ -350,8 +345,7 @@ if (window.location !== window.parent.location) { }) control.addEventListener('leavefullscreen', function() { const btn = control.element.getElementsByTagName('button')[0]; - btn.classList.add(classInactive); - btn.classList.remove(classActive); + btn.classList.replace(classActive, classInactive); btn.title = titleInactive; const exp = document.getElementById('export-to-image'); @@ -442,12 +436,10 @@ if (window.location !== window.parent.location) { panel.addEventListener('show.bs.modal', function() { backdrop.classList.add('modal-backdrop', 'show'); btn.setAttribute('aria-expanded', 'true'); - btn.classList.add('btn-dark'); - btn.classList.remove('btn-light'); + btn.classList.replace('btn-light', 'btn-dark'); }); panel.addEventListener('hidden.bs.modal', function() { - btn.classList.add('btn-light'); - btn.classList.remove('btn-dark'); + btn.classList.replace('btn-dark', 'btn-light'); btn.setAttribute('aria-expanded', 'false'); backdrop.classList.remove('modal-backdrop', 'show'); }); |