diff --git a/bookwyrm/static/css/format.css b/bookwyrm/static/css/format.css index 870152d57..f08f6739a 100644 --- a/bookwyrm/static/css/format.css +++ b/bookwyrm/static/css/format.css @@ -14,10 +14,13 @@ } /* --- TOGGLES --- */ -[aria-pressed=true] { +.toggle-button[aria-pressed=true], .toggle-button[aria-pressed=true]:hover { background-color: hsl(171, 100%, 41%); color: white; } +.hide-active[aria-pressed=true] { + display: none; +} input.toggle-control { display: none; diff --git a/bookwyrm/static/js/shared.js b/bookwyrm/static/js/shared.js index aa58274e1..dd4fc3322 100644 --- a/bookwyrm/static/js/shared.js +++ b/bookwyrm/static/js/shared.js @@ -52,33 +52,51 @@ function setDisplay(el) { function toggleAction(e) { var pressed = e.currentTarget.getAttribute('aria-pressed') == 'false'; - e.currentTarget.setAttribute('aria-pressed', pressed); + var el = e.currentTarget; + + var targetId = el.getAttribute('data-controls'); + document.querySelectorAll('[data-controls="' + targetId + '"]') + .forEach(t => t.setAttribute('aria-pressed', !!(t.getAttribute('aria-pressed') == 'false'))); - var targetId = e.currentTarget.getAttribute('data-controls'); if (targetId) { var target = document.getElementById(targetId); if (pressed) { - target.className = target.className.replace('hidden', ''); + removeClass(target, 'hidden'); + addClass(target, 'is-active'); } else { - target.className += ' hidden'; + addClass(target, 'hidden'); + removeClass(target, 'is-active'); } - } // set hover, if appropriate - var hover = e.currentTarget.getAttribute('data-hover-target'); + var hover = el.getAttribute('data-hover-target'); if (hover) { document.getElementById(hover).focus(); } // set checkbox, if appropriate - var checkbox = e.currentTarget.getAttribute('data-controls-checkbox'); + var checkbox = el.getAttribute('data-controls-checkbox'); if (checkbox) { document.getElementById(checkbox).checked = !!pressed; } } +function addClass(el, classname) { + el.className = el.className.split(' ').concat(classname).join(' '); +} + +function removeClass(el, className) { + var classes = el.className.split(' '); + const idx = classes.indexOf(className); + if (idx > -1) { + classes.splice(idx, 1); + } + el.className = classes.join(' '); +} + + function interact(e) { e.preventDefault(); ajaxPost(e.target); diff --git a/bookwyrm/templates/book.html b/bookwyrm/templates/book.html index 4e65ecf84..a73569545 100644 --- a/bookwyrm/templates/book.html +++ b/bookwyrm/templates/book.html @@ -94,30 +94,20 @@ {% 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 %} -
Didn't find what you were looking for?
- - - + {% include 'snippets/toggle/open_button.html' with text="Show results from other catalogues" small=True controls_text="more-results" %}