edit the layout handling and add cv download

This commit is contained in:
Dilanka-H
2025-11-24 14:45:21 +07:00
parent fc5c7db221
commit bb65f04992
14 changed files with 351 additions and 253 deletions

View File

@@ -1,7 +1,6 @@
{{ block "script" .}}
<script>
function clickBackButton() {
console.log('Back button clicked', window.history.state);
if (window.history.state && window.history.state["htmx"]) {
window.history.back();
} else {
@@ -12,11 +11,9 @@
const scatteredWords = document.getElementById('scatteredWords');
if (!scatteredWords) return;
const url = window.location.pathname;
console.log('Current URL:', url);
if (url === '/' || url === '') {
scatteredWords.classList.add('md:block');
} else {
console.log('Hiding scattered words');
scatteredWords.classList.remove('md:block');
}
}
@@ -25,11 +22,24 @@
document.body.addEventListener('htmx:pushedIntoHistory', function (evt) {
setScatteredWordsVisibility();
});
document.body.addEventListener('htmx:historyRestore', function (e) {
console.log('Restoring history state', e.detail);
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 }}