diff --git a/bookwyrm/static/js/shared.js b/bookwyrm/static/js/shared.js index edd1653e..04a67789 100644 --- a/bookwyrm/static/js/shared.js +++ b/bookwyrm/static/js/shared.js @@ -13,8 +13,6 @@ window.onload = function() { .forEach(t => t.onclick = selectAll); // toggle between tabs - Array.from(document.getElementsByClassName('tab-change-nested')) - .forEach(t => t.onclick = tabChangeNested); Array.from(document.getElementsByClassName('tab-change')) .forEach(t => t.onclick = tabChange); @@ -50,6 +48,7 @@ function setDisplay(el) { } } + function toggleAction(e) { var el = e.currentTarget; var pressed = el.getAttribute('aria-pressed') == 'false'; @@ -92,7 +91,11 @@ function addRemoveClass(el, classname, bool) { } function addClass(el, classname) { - el.className = el.className.split(' ').concat(classname).join(' '); + var classes = el.className.split(' '); + if (classes.indexOf(classname) > -1) { + return + } + el.className = classes.concat(classname).join(' '); } function removeClass(el, className) { @@ -128,35 +131,32 @@ function selectAll(e) { .forEach(t => t.checked=true); } -function tabChangeNested(e) { - var target = e.target.closest('li') - var parentElement = target.parentElement.closest('li').parentElement; - handleTabChange(target, parentElement) -} - function tabChange(e) { - var target = e.target.closest('li') - var parentElement = target.parentElement; - handleTabChange(target, parentElement) -} + var el = e.currentTarget; + var parentElement = el.closest('[role="tablist"]'); - -function handleTabChange(target, parentElement) { parentElement.querySelectorAll('[aria-selected="true"]') .forEach(t => t.setAttribute("aria-selected", false)); - target.querySelector('[role="tab"]').setAttribute("aria-selected", true); + el.setAttribute("aria-selected", true); parentElement.querySelectorAll('li') - .forEach(t => t.className=''); - target.className = 'is-active'; + .forEach(t => removeClass(t, 'is-active')); + addClass(el, 'is-active'); + + var tabId = el.getAttribute('data-tab'); + Array.from(document.getElementsByClassName(el.getAttribute('data-category'))) + .forEach(t => addRemoveClass(t, 'hidden', t.id != tabId)) } function toggleMenu(e) { var el = e.currentTarget; var expanded = el.getAttribute('aria-expanded') == 'false'; el.setAttribute('aria-expanded', expanded); - var target = document.getElementById(el.getAttribute('data-controls')); - addRemoveClass(target, 'is-active', expanded); + var targetId = el.getAttribute('data-controls'); + if (targetId) { + var target = document.getElementById(targetId); + addRemoveClass(target, 'is-active', expanded); + } } function ajaxPost(form) { diff --git a/bookwyrm/templates/book.html b/bookwyrm/templates/book.html index be5f6397..4a95237c 100644 --- a/bookwyrm/templates/book.html +++ b/bookwyrm/templates/book.html @@ -175,11 +175,11 @@ {% endif %} {% if request.user.is_authenticated %} -
+
{% include 'snippets/create_status.html' with book=book hide_cover=True %} -
+ -
+
{% csrf_token %} @@ -187,7 +187,7 @@
-
+ {% endif %}
diff --git a/bookwyrm/templates/feed.html b/bookwyrm/templates/feed.html index 9b69efea..61017001 100644 --- a/bookwyrm/templates/feed.html +++ b/bookwyrm/templates/feed.html @@ -9,7 +9,7 @@

There are no books here right now! Try searching for a book to get started

{% else %}
-