Skip to content

Commit

Permalink
fix(templates): shorten the modal title
Browse files Browse the repository at this point in the history
  • Loading branch information
danvergara committed Sep 15, 2024
1 parent 6ec9ee8 commit 609367b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 4 additions & 2 deletions templates/partials/active_modal.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">{{ .Filename }}</h5>
<div class="modal-title" id="modal-title" title="{{ .Filename }}">
{{ .Filename }}
</div>
</div>
<div class="modal-body">
{{if eq .FileType "image"}}
Expand All @@ -15,7 +17,7 @@
<div class="modal-footer">
<a href="/files/{{ .Filename }}" download>
<button class="btn btn-success">
Download {{ .Filename }}
Download
</button>
</a>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
Expand Down
13 changes: 9 additions & 4 deletions templates/partials/js.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@
}
</script>
<script>
htmx.on('htmx:load', function(evt) { updateName(); });
htmx.on(window, 'resize', function(evt) { updateName(); });
htmx.on('htmx:load', function(evt) { updateName('filename'); });
htmx.on(window, 'resize', function(evt) { updateName('filename'); });

const modal = document.getElementById('modals-here')
modal.addEventListener('shown.bs.modal', () => {
updateName('modal-title')
})

// Shorten the filename if it's too long to fit in the space available
function updateName() {
let filenameObj = document.getElementById('filename');
function updateName(id) {
let filenameObj = document.getElementById(id);
if (!filenameObj) return; // Not on the download page

let filename = filenameObj.title;
Expand Down

0 comments on commit 609367b

Please sign in to comment.