46 lines
1.5 KiB
HTML
46 lines
1.5 KiB
HTML
{{ block "script" .}}
|
|
<script>
|
|
function clickBackButton() {
|
|
if (window.history.state && window.history.state["htmx"]) {
|
|
window.history.back();
|
|
} else {
|
|
window.location.href = '/';
|
|
}
|
|
}
|
|
function setScatteredWordsVisibility() {
|
|
const scatteredWords = document.getElementById('scatteredWords');
|
|
if (!scatteredWords) return;
|
|
const url = window.location.pathname;
|
|
if (url === '/' || url === '') {
|
|
scatteredWords.classList.add('md:block');
|
|
} else {
|
|
scatteredWords.classList.remove('md:block');
|
|
}
|
|
}
|
|
document.addEventListener('DOMContentLoaded', (event) => {
|
|
setScatteredWordsVisibility();
|
|
document.body.addEventListener('htmx:pushedIntoHistory', function (evt) {
|
|
setScatteredWordsVisibility();
|
|
});
|
|
document.body.addEventListener('htmx:historyRestore', function (e) {
|
|
setScatteredWordsVisibility();
|
|
});
|
|
document.body.addEventListener("htmx:afterRequest", (evt) => {
|
|
const trigger = evt.detail.xhr.getResponseHeader("Hx-Trigger");
|
|
if (trigger === "DownloadCVButton") {
|
|
if (evt.detail.xhr.status !== 200) {
|
|
alert("Failed to download CV. Please try again later.");
|
|
return;
|
|
}
|
|
const link = document.createElement('a');
|
|
link.href = '/download';
|
|
link.download = 'DilankaHerath-CV.pdf';
|
|
document.body.appendChild(link);
|
|
link.click();
|
|
link.remove();
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
{{ end }}
|