moviewyrm/bookwyrm/static/js/shared.js

68 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-03-16 01:12:45 +00:00
function interact(e) {
e.preventDefault();
ajaxPost(e.target);
var identifier = e.target.getAttribute('data-id');
var elements = document.getElementsByClassName(identifier);
for (var i = 0; i < elements.length; i++) {
if (elements[i].className.includes('hidden')) {
elements[i].className = elements[i].className.replace('hidden', '');
} else {
elements[i].className += ' hidden';
}
2020-03-16 01:12:45 +00:00
}
return true;
}
2020-03-21 23:50:49 +00:00
function reply(e) {
2020-03-16 01:12:45 +00:00
e.preventDefault();
ajaxPost(e.target);
// TODO: display comment
return true;
}
2020-11-13 18:14:24 +00:00
function selectAll(el) {
el.parentElement.querySelectorAll('[type="checkbox"]')
.forEach(t => t.checked=true);
}
2020-04-04 17:08:34 +00:00
function rate_stars(e) {
2020-04-03 23:47:47 +00:00
e.preventDefault();
ajaxPost(e.target);
2020-04-04 17:08:34 +00:00
rating = e.target.rating.value;
2020-04-03 23:47:47 +00:00
var stars = e.target.parentElement.getElementsByClassName('icon');
for (var i = 0; i < stars.length ; i++) {
2020-04-04 17:08:34 +00:00
stars[i].className = rating > i ? 'icon icon-star-full' : 'icon icon-star-empty';
2020-04-03 23:47:47 +00:00
}
return true;
}
function tabChange(e, nested) {
var target = e.target.closest('li')
var identifier = target.getAttribute('data-id');
2020-03-21 23:50:49 +00:00
if (nested) {
var parent_element = target.parentElement.closest('li').parentElement;
} else {
var parent_element = target.parentElement;
}
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';
2020-03-21 23:50:49 +00:00
}
2020-11-09 19:58:19 +00:00
function toggleMenu(el) {
el.setAttribute('aria-expanded', el.getAttribute('aria-expanded') == 'false');
}
function ajaxPost(form) {
fetch(form.action, {
method : "POST",
body: new FormData(form)
});
2020-03-15 21:15:36 +00:00
}