Recount-Server/web/static/index.js
2024-01-20 15:05:06 -08:00

60 lines
1.6 KiB
JavaScript

import {fill_charts} from "./chart_functions.js";
import {register_dropdowns} from "./dropdowns.js";
function debounce(func, delay) {
let timeoutId;
return function (...args) {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
func.apply(this, args);
}, delay);
};
}
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) {
a_el.removeEventListener("click", switch_nav);
a_el.addEventListener("click", switch_nav);
});
}
function register_handlers() {
register_nav_links();
fill_charts();
register_dropdowns();
}
function load_in_table() {
var rows = Array.from(document.querySelectorAll(".row_awaiting_processing"));
rows.sort((a, b) => b.dataset.rcntTransactionRowPos - a.dataset.rcntTransactionRowPos);
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);
}
const trigger_table_animation = debounce(load_in_table, 100);
const trigger_reset_handlers = debounce(register_handlers, 200);
export {trigger_reset_handlers, trigger_table_animation};