Use classList.toggle instead of className replace

This commit is contained in:
Chris Wanstrath 2026-03-03 12:36:06 -08:00
parent c81513b0ea
commit 0f197849b6

View File

@ -23,12 +23,15 @@ function toggleVisibility(btn) {
var next = current === 'public' ? 'private' : 'public'; var next = current === 'public' ? 'private' : 'public';
btn.dataset.visibility = next; btn.dataset.visibility = next;
btn.textContent = next; btn.textContent = next;
btn.className = btn.className.replace(' public', ''); btn.classList.toggle('public', next === 'public');
if (next === 'public') btn.className += ' public';
fetch('/api/visibility/' + encodeURIComponent(repo), { fetch('/api/visibility/' + encodeURIComponent(repo), {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ visibility: next }) body: JSON.stringify({ visibility: next })
}).catch(function() {
btn.dataset.visibility = current;
btn.textContent = current;
btn.classList.toggle('public', current === 'public');
}); });
} }
` `