forked from mirrors/bookwyrm
Tab change javascript out of html
This commit is contained in:
parent
4d4e692f49
commit
7abe39b7d5
3 changed files with 21 additions and 22 deletions
|
@ -11,6 +11,12 @@ window.onload = function() {
|
||||||
// select all
|
// select all
|
||||||
Array.from(document.getElementsByClassName('select-all'))
|
Array.from(document.getElementsByClassName('select-all'))
|
||||||
.forEach(t => t.onclick = selectAll);
|
.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);
|
||||||
};
|
};
|
||||||
|
|
||||||
function toggleAction(e) {
|
function toggleAction(e) {
|
||||||
|
@ -42,32 +48,25 @@ function selectAll(e) {
|
||||||
.forEach(t => t.checked=true);
|
.forEach(t => t.checked=true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function rate_stars(e) {
|
function tabChangeNested(e) {
|
||||||
e.preventDefault();
|
var target = e.target.closest('li')
|
||||||
ajaxPost(e.target);
|
var parentElement = target.parentElement.closest('li').parentElement;
|
||||||
rating = e.target.rating.value;
|
handleTabChange(target, parentElement)
|
||||||
var stars = e.target.parentElement.getElementsByClassName('icon');
|
|
||||||
for (var i = 0; i < stars.length ; i++) {
|
|
||||||
stars[i].className = rating > i ? 'icon icon-star-full' : 'icon icon-star-empty';
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function tabChange(e, nested) {
|
function tabChange(e) {
|
||||||
var target = e.target.closest('li')
|
var target = e.target.closest('li')
|
||||||
var identifier = target.getAttribute('data-id');
|
var parentElement = target.parentElement;
|
||||||
|
handleTabChange(target, parentElement)
|
||||||
|
}
|
||||||
|
|
||||||
if (nested) {
|
|
||||||
var parent_element = target.parentElement.closest('li').parentElement;
|
|
||||||
} else {
|
|
||||||
var parent_element = target.parentElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
parent_element.querySelectorAll('[aria-selected="true"]')
|
function handleTabChange(target, parentElement) {
|
||||||
|
parentElement.querySelectorAll('[aria-selected="true"]')
|
||||||
.forEach(t => t.setAttribute("aria-selected", false));
|
.forEach(t => t.setAttribute("aria-selected", false));
|
||||||
target.querySelector('[role="tab"]').setAttribute("aria-selected", true);
|
target.querySelector('[role="tab"]').setAttribute("aria-selected", true);
|
||||||
|
|
||||||
parent_element.querySelectorAll('li')
|
parentElement.querySelectorAll('li')
|
||||||
.forEach(t => t.className='');
|
.forEach(t => t.className='');
|
||||||
target.className = 'is-active';
|
target.className = 'is-active';
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
<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, nested=true)">
|
<label for="book-{{ book.id }}" class="tab-change-nested">
|
||||||
<div role="tab" tabindex="0" aria-selected="{% if shelf_counter == 1 and forloop.first %}true{% else %}false{% endif %}" aria-controls="book-{{ book.id }}-panel">
|
<div role="tab" tabindex="0" aria-selected="{% if shelf_counter == 1 and forloop.first %}true{% else %}false{% endif %}" aria-controls="book-{{ book.id }}-panel">
|
||||||
<a>
|
<a>
|
||||||
{% include 'snippets/book_cover.html' with book=book size="medium" %}
|
{% include 'snippets/book_cover.html' with book=book size="medium" %}
|
||||||
|
|
|
@ -5,21 +5,21 @@
|
||||||
<ul role="tablist">
|
<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 }}">
|
<label for="review-{{ book.id }}">
|
||||||
<div onclick="tabChange(event)" role="tab" aria-selected="true" tabindex="0">
|
<div class="tab-change" role="tab" aria-selected="true" tabindex="0">
|
||||||
<a>Review</a>
|
<a>Review</a>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</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}}">
|
<label for="comment-{{ book.id}}">
|
||||||
<div onclick="tabChange(event)" role="tab" tabindex="0">
|
<div class="tab-change" role="tab" tabindex="0">
|
||||||
<a>Comment</a>
|
<a>Comment</a>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</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 }}">
|
<label for="quote-{{ book.id }}">
|
||||||
<div onclick="tabChange(event)" role="tab" tabindex="0">
|
<div class="tab-change" role="tab" tabindex="0">
|
||||||
<a>Quote</a>
|
<a>Quote</a>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
|
|
Loading…
Reference in a new issue