Recount-Server/web/static/index.js

61 lines
1.6 KiB
JavaScript
Raw Normal View History

2024-01-17 19:58:31 -08:00
import {fill_charts} from "./chart_functions.js";
2024-01-20 15:05:06 -08:00
import {register_dropdowns} from "./dropdowns.js";
2024-01-17 19:58:31 -08:00
2024-01-12 20:50:41 -08:00
2024-01-15 19:26:51 -08:00
function debounce(func, delay) {
let timeoutId;
return function (...args) {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
func.apply(this, args);
}, delay);
};
2024-01-12 20:50:41 -08:00
}
2024-01-20 15:05:06 -08:00
function switch_nav(event) {
var active_anchor = document.querySelector("nav a.active");
active_anchor.classList.remove("active");
var clicked = event.target;
clicked.classList.add("active");
}
function register_nav_links() {
var navAnchors = document.querySelectorAll("nav a");
navAnchors.forEach(function (a_el) {
2024-01-20 15:05:06 -08:00
a_el.removeEventListener("click", switch_nav);
a_el.addEventListener("click", switch_nav);
});
}
2024-01-20 15:05:06 -08:00
2024-01-15 19:26:51 -08:00
function register_handlers() {
register_nav_links();
2024-01-20 15:05:06 -08:00
fill_charts();
register_dropdowns();
2024-01-15 19:26:51 -08:00
}
function load_in_table() {
var rows = Array.from(document.querySelectorAll(".row_awaiting_processing"));
rows.sort((a, b) => b.dataset.rcntTransactionRowPos - a.dataset.rcntTransactionRowPos);
2024-01-15 19:26:51 -08:00
const processElement = (element, index) => {
element.classList.remove('row_awaiting_processing');
setTimeout(() => {
if (index < rows.length - 1) {
processElement(rows[index + 1], index + 1);
}
}, 25); // 1000 milliseconds (1 second) delay, adjust as needed
};
processElement(rows[0], 0);
}
2024-01-15 19:26:51 -08:00
const trigger_table_animation = debounce(load_in_table, 100);
2024-01-20 15:05:06 -08:00
const trigger_reset_handlers = debounce(register_handlers, 200);
2024-01-19 21:05:08 -08:00
2024-01-20 15:05:06 -08:00
export {trigger_reset_handlers, trigger_table_animation};