Improves tabbing javascript for create status tabs

This commit is contained in:
Mouse Reeve 2020-11-08 19:09:29 -08:00
parent b7f8055ede
commit b7bc089d86
2 changed files with 11 additions and 21 deletions

View file

@ -32,26 +32,25 @@ function rate_stars(e) {
} }
function tabChange(e) { function tabChange(e) {
var target = e.target.closest('li') var target = e.target.closest('li');
var identifier = target.getAttribute('data-id');
var parent_element = target.parentElement var parent_element = target.parentElement;
var tabs = parent_element.getElementsByTagName('label'); var tabs = parent_element.getElementsByTagName('label');
for (i = 0; i < tabs.length; i++) {
var tab = tabs[i].parentElement; parent_element.querySelectorAll('[aria-selected="true"]')
if (tab.getAttribute('data-id') == identifier) { .forEach(t => t.setAttribute("aria-selected", false));
tab.className += ' is-active'; e.target.parentElement.setAttribute("aria-selected", true);
} else {
tab.className = tab.className.replace('is-active', ''); parent_element.querySelectorAll('li')
} .forEach(t => t.className='');
} target.className += ' is-active';
} }
function nestedTabChange(e) { function nestedTabChange(e) {
var target = e.target.closest('li') var target = e.target.closest('li')
var identifier = target.getAttribute('data-id'); var identifier = target.getAttribute('data-id');
var parent_element = target.parentElement.closest('li').parentElement;
var parent_element = target.parentElement.closest('li').parentElement;
var tabs = parent_element.getElementsByTagName('label'); var tabs = parent_element.getElementsByTagName('label');
for (i = 0; i < tabs.length; i++) { for (i = 0; i < tabs.length; i++) {
var tab = tabs[i].parentElement; var tab = tabs[i].parentElement;

View file

@ -38,14 +38,6 @@
<ul class="dropdown-content"> <ul class="dropdown-content">
{% for shelf in request.user.shelf_set.all %} {% for shelf in request.user.shelf_set.all %}
<li> <li>
{% if shelf.identifier == 'reading' and active_shelf.identifier != 'reading' %}
<div class="dropdown-item pt-0 pb-0">
<label class="button is-small" for="start-reading-{{ uuid }}" role="button" tabindex="0">
{{ shelf.name }}
</label>
{% include 'snippets/start_reading_modal.html' %}
</div>
{% else %}
<form class="dropdown-item pt-0 pb-0" name="shelve" action="/shelve/" method="post"> <form class="dropdown-item pt-0 pb-0" name="shelve" action="/shelve/" method="post">
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="book" value="{{ book.id }}"> <input type="hidden" name="book" value="{{ book.id }}">
@ -54,7 +46,6 @@
{% if shelf in book.shelf_set.all %}<span class="icon icon-check"></span>{% endif %} {% if shelf in book.shelf_set.all %}<span class="icon icon-check"></span>{% endif %}
</button> </button>
</form> </form>
{% endif %}
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>