diff --git a/bookwyrm/static/js/shared.js b/bookwyrm/static/js/shared.js index dd4fc3322..e7b87dd87 100644 --- a/bookwyrm/static/js/shared.js +++ b/bookwyrm/static/js/shared.js @@ -1,7 +1,7 @@ // set up javascript listeners window.onload = function() { // let buttons set keyboard focus - Array.from(document.getElementsByClassName('toggle-control')) + document.querySelectorAll('[data-controls]') .forEach(t => t.onclick = toggleAction); // javascript interactions (boost/fav) @@ -51,8 +51,8 @@ function setDisplay(el) { } function toggleAction(e) { - var pressed = e.currentTarget.getAttribute('aria-pressed') == 'false'; var el = e.currentTarget; + var pressed = el.getAttribute('aria-pressed') == 'false'; var targetId = el.getAttribute('data-controls'); document.querySelectorAll('[data-controls="' + targetId + '"]') @@ -69,17 +69,17 @@ function toggleAction(e) { } } - // set hover, if appropriate - var hover = el.getAttribute('data-hover-target'); - if (hover) { - document.getElementById(hover).focus(); - } - // set checkbox, if appropriate var checkbox = el.getAttribute('data-controls-checkbox'); if (checkbox) { document.getElementById(checkbox).checked = !!pressed; } + + // set focus, if appropriate + var focus = el.getAttribute('data-focus-target'); + if (focus) { + document.getElementById(focus).focus(); + } } diff --git a/bookwyrm/templates/book.html b/bookwyrm/templates/book.html index a73569545..dcb1b8540 100644 --- a/bookwyrm/templates/book.html +++ b/bookwyrm/templates/book.html @@ -94,7 +94,7 @@ {% include 'snippets/trimmed_text.html' with full=book|book_description %} {% if request.user.is_authenticated and perms.bookwyrm.edit_book and not book|book_description %} - {% include 'snippets/toggle/open_button.html' with text="Add description" controls_text="add-description" controls_uid=book.id hover="id_description" hide_active=True id="hide-description" %} + {% include 'snippets/toggle/open_button.html' with text="Add description" controls_text="add-description" controls_uid=book.id focus="id_description" hide_active=True id="hide-description" %}