Merge pull request #327 from mouse-reeve/create-status-tabs

Covers and create status tabs
This commit is contained in:
Mouse Reeve 2020-11-08 20:12:21 -08:00 committed by GitHub
commit 52cb5fbb0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 26 deletions

View file

@ -31,22 +31,23 @@ function rate_stars(e) {
return true; return true;
} }
function tabChange(e) { function tabChange(e, nested) {
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 tabs = parent_element.getElementsByTagName('label'); if (nested) {
for (i = 0; i < tabs.length; i++) { var parent_element = target.parentElement.closest('li').parentElement;
var tab = tabs[i].parentElement; } else {
if (tab.getAttribute('data-id') == identifier) { var parent_element = target.parentElement;
tab.className += ' is-active';
} else {
tab.className = tab.className.replace('is-active', '');
}
} }
var el = document.getElementById(identifier); parent_element.querySelectorAll('[aria-selected="true"]')
.forEach(t => t.setAttribute("aria-selected", false));
target.querySelector('[role="tab"]').setAttribute("aria-selected", true);
parent_element.querySelectorAll('li')
.forEach(t => t.className='');
target.className = 'is-active';
} }
function ajaxPost(form) { function ajaxPost(form) {

View file

@ -21,7 +21,13 @@
<ul> <ul>
{% for book in shelf.books %} {% for book in shelf.books %}
<li class="{% if shelf_counter == 1 and forloop.first %}is-active{% endif %}" data-id="tab-book-{{ book.id }}"> <li class="{% if shelf_counter == 1 and forloop.first %}is-active{% endif %}" data-id="tab-book-{{ book.id }}">
<label for="book-{{ book.id }}" onclick="tabChange(event)"><a>{% include 'snippets/book_cover.html' with book=book size="medium" %}</a></label> <label for="book-{{ book.id }}" onclick="tabChange(event, nested=true)">
<div role="tab" tabindex="0" aria-selected="{% if shelf_counter == 1 and forloop.first %}true{% else %}false{% endif %}">
<a>
{% include 'snippets/book_cover.html' with book=book size="medium" %}
</a>
</div>
</label>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>

View file

@ -2,15 +2,27 @@
{% load fr_display %} {% load fr_display %}
<div class="tabs is-boxed"> <div class="tabs is-boxed">
<ul> <ul role="tablist">
<li class="is-active" data-id="tab-review-{{ book.id }}" data-category="tab-option-{{ book.id }}"> <li class="is-active" data-id="tab-review-{{ book.id }}" data-category="tab-option-{{ book.id }}">
<label for="review-{{ book.id }}" onclick="tabChange(event)"><a>Review</a></label> <label for="review-{{ book.id }}">
<div onclick="tabChange(event)" role="tab" aria-selected="true" tabindex="0">
<a>Review</a>
</div>
</label>
</li> </li>
<li data-id="tab-comment-{{ book.id }}" data-category="tab-option-{{ book.id }}"> <li data-id="tab-comment-{{ book.id }}" data-category="tab-option-{{ book.id }}">
<label for="comment-{{ book.id}}" onclick="tabChange(event)"><a>Comment</a></label> <label for="comment-{{ book.id}}">
<div onclick="tabChange(event)" role="tab" tabindex="0">
<a>Comment</a>
</div>
</label>
</li> </li>
<li data-id="tab-quotation-{{ book.id }}" data-category="tab-option-{{ book.id }}"> <li data-id="tab-quotation-{{ book.id }}" data-category="tab-option-{{ book.id }}">
<label for="quote-{{ book.id }}" onclick="tabChange(event)"><a>Quote</a></label> <label for="quote-{{ book.id }}">
<div onclick="tabChange(event)" role="tab" tabindex="0">
<a>Quote</a>
</div>
</label>
</li> </li>
</ul> </ul>
</div> </div>
@ -22,7 +34,7 @@
<div> <div>
<input class="toggle-control" type="radio" name="status-tabs-{{ book.id }}" id="comment-{{ book.id }}"> <input class="toggle-control" type="radio" name="status-tabs-{{ book.id }}" id="comment-{{ book.id }}">
{% include 'snippets/create_status_form.html' with type="comment" placeholder="Some thougts on '"|add:book.title|add:"'" %} {% include 'snippets/create_status_form.html' with type="comment" placeholder="Some thoughts on '"|add:book.title|add:"'" %}
</div> </div>
<div> <div>

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>