2021-01-14 17:38:33 -05:00
|
|
|
// set up javascript listeners
|
2021-01-14 16:02:28 -05:00
|
|
|
window.onload = function() {
|
2021-01-14 17:38:33 -05:00
|
|
|
// let buttons set keyboard focus
|
|
|
|
Array.from(document.getElementsByClassName('toggle-control'))
|
2021-01-14 18:16:18 -05:00
|
|
|
.forEach(t => t.onclick = toggleAction);
|
2021-01-14 17:38:33 -05:00
|
|
|
|
2021-01-14 18:16:18 -05:00
|
|
|
// javascript interactions (boost/fav)
|
2021-01-14 17:38:33 -05:00
|
|
|
Array.from(document.getElementsByClassName('interaction'))
|
|
|
|
.forEach(t => t.onsubmit = interact);
|
2021-01-14 18:16:18 -05:00
|
|
|
|
|
|
|
// select all
|
|
|
|
Array.from(document.getElementsByClassName('select-all'))
|
|
|
|
.forEach(t => t.onclick = selectAll);
|
2021-01-14 16:02:28 -05:00
|
|
|
};
|
|
|
|
|
2021-01-14 18:16:18 -05:00
|
|
|
function toggleAction(e) {
|
2021-01-14 16:02:28 -05:00
|
|
|
// set hover, if appropriate
|
|
|
|
var hover = e.target.getAttribute('data-hover-target')
|
|
|
|
if (hover) {
|
|
|
|
document.getElementById(hover).focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-15 21:12:45 -04:00
|
|
|
function interact(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
ajaxPost(e.target);
|
2020-03-21 17:29:39 -04:00
|
|
|
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-15 21:12:45 -04:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-01-14 18:16:18 -05:00
|
|
|
function selectAll(e) {
|
|
|
|
e.target.parentElement.parentElement.querySelectorAll('[type="checkbox"]')
|
2020-11-13 13:14:24 -05:00
|
|
|
.forEach(t => t.checked=true);
|
|
|
|
}
|
2020-11-11 21:32:52 -05:00
|
|
|
|
2020-04-04 13:08:34 -04:00
|
|
|
function rate_stars(e) {
|
2020-04-03 19:47:47 -04:00
|
|
|
e.preventDefault();
|
|
|
|
ajaxPost(e.target);
|
2020-04-04 13:08:34 -04:00
|
|
|
rating = e.target.rating.value;
|
2020-04-03 19:47:47 -04:00
|
|
|
var stars = e.target.parentElement.getElementsByClassName('icon');
|
|
|
|
for (var i = 0; i < stars.length ; i++) {
|
2020-04-04 13:08:34 -04:00
|
|
|
stars[i].className = rating > i ? 'icon icon-star-full' : 'icon icon-star-empty';
|
2020-04-03 19:47:47 -04:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-08 22:34:41 -05:00
|
|
|
function tabChange(e, nested) {
|
|
|
|
var target = e.target.closest('li')
|
|
|
|
var identifier = target.getAttribute('data-id');
|
2020-03-21 19:50:49 -04:00
|
|
|
|
2020-11-08 22:34:41 -05:00
|
|
|
if (nested) {
|
|
|
|
var parent_element = target.parentElement.closest('li').parentElement;
|
|
|
|
} else {
|
|
|
|
var parent_element = target.parentElement;
|
|
|
|
}
|
2020-11-08 22:09:29 -05:00
|
|
|
|
|
|
|
parent_element.querySelectorAll('[aria-selected="true"]')
|
|
|
|
.forEach(t => t.setAttribute("aria-selected", false));
|
2020-11-08 22:34:41 -05:00
|
|
|
target.querySelector('[role="tab"]').setAttribute("aria-selected", true);
|
2020-11-08 22:09:29 -05:00
|
|
|
|
|
|
|
parent_element.querySelectorAll('li')
|
|
|
|
.forEach(t => t.className='');
|
2020-11-08 22:34:41 -05:00
|
|
|
target.className = 'is-active';
|
2020-03-21 19:50:49 -04:00
|
|
|
}
|
|
|
|
|
2020-11-09 14:58:19 -05:00
|
|
|
function toggleMenu(el) {
|
|
|
|
el.setAttribute('aria-expanded', el.getAttribute('aria-expanded') == 'false');
|
|
|
|
}
|
|
|
|
|
2020-03-21 17:29:39 -04:00
|
|
|
function ajaxPost(form) {
|
|
|
|
fetch(form.action, {
|
|
|
|
method : "POST",
|
|
|
|
body: new FormData(form)
|
|
|
|
});
|
2020-03-15 17:15:36 -04:00
|
|
|
}
|