2020-11-08 15:59:50 +00:00
|
|
|
import {
|
|
|
|
calculate,
|
|
|
|
generateTable,
|
|
|
|
loadResultsFromUrl,
|
|
|
|
clearInputs,
|
|
|
|
clearResults,
|
|
|
|
} from './display';
|
2023-09-24 16:33:49 +00:00
|
|
|
import contentTemplate from './templates/content.pug';
|
|
|
|
|
|
|
|
const loadContent = () => {
|
|
|
|
document.body.innerHTML = contentTemplate({
|
|
|
|
embed: window.location.hash === '#embed',
|
|
|
|
});
|
|
|
|
};
|
2019-09-07 18:30:44 +00:00
|
|
|
|
2020-11-06 23:08:59 +00:00
|
|
|
const handleCalculateButtonClick = (event: Event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
calculate();
|
|
|
|
};
|
|
|
|
|
2022-08-31 20:09:48 +00:00
|
|
|
export const bindActions = (): void => {
|
2019-09-07 18:30:44 +00:00
|
|
|
document
|
|
|
|
.querySelector('#calculate-button')!
|
|
|
|
.addEventListener('click', handleCalculateButtonClick);
|
2020-10-18 19:06:38 +00:00
|
|
|
};
|
2019-09-07 18:30:44 +00:00
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
2023-09-24 16:33:49 +00:00
|
|
|
loadContent();
|
2019-10-03 19:03:13 +00:00
|
|
|
generateTable();
|
2020-11-06 23:08:59 +00:00
|
|
|
loadResultsFromUrl();
|
2019-09-07 18:30:44 +00:00
|
|
|
bindActions();
|
|
|
|
});
|
2020-11-07 22:07:10 +00:00
|
|
|
|
|
|
|
window.addEventListener('popstate', () => {
|
|
|
|
if (window.location.search) {
|
|
|
|
loadResultsFromUrl();
|
|
|
|
} else {
|
|
|
|
clearInputs();
|
|
|
|
clearResults();
|
|
|
|
}
|
|
|
|
});
|
2023-09-24 16:33:49 +00:00
|
|
|
|
|
|
|
window.addEventListener('hashchange', () => {
|
|
|
|
loadContent();
|
|
|
|
generateTable();
|
|
|
|
loadResultsFromUrl();
|
|
|
|
});
|