Compare commits

...

2 Commits

Author SHA1 Message Date
jordi fita mas 5d82597d14 Manually update and restore the <title> when showing dialog with HTMx
Mostly, the same problem as before: if the document title does not
reflect the application’s state, it becomes useless when there are
multiple open tabs.

In this case, however, i do not know how to tell HTMx to restore the
title to how it was before opening the dialog without a new request to
the server, that makes no sense when the dialog was closed without any
change whatsoever.  Thus, i do it with JavaScript on the client side.
2023-03-26 14:06:26 +02:00
jordi fita mas b0db8df732 Add the <title> element for the “main” boosted pages
Otherwise, the page title does not change and becomes useless.
2023-03-26 13:57:24 +02:00
2 changed files with 5 additions and 0 deletions

View File

@ -401,6 +401,7 @@ class Tags extends HTMLDivElement {
customElements.define('numerus-multiselect', Multiselect, {extends: 'div'});
customElements.define('numerus-tags', Tags, {extends: 'div'});
let savedTitle = '';
htmx.onLoad((target) => {
if (target.tagName === 'DIALOG') {
@ -408,6 +409,8 @@ htmx.onLoad((target) => {
for (const detail of details) {
detail.removeAttribute('open');
}
savedTitle = document.title;
document.title = target.querySelector('h2').textContent + ' — ' + savedTitle.substring(savedTitle.indexOf("—") + 1);
target.showModal();
const button = target.querySelector('.close-dialog');
if (button) {
@ -425,6 +428,7 @@ htmx.on('closeModal', () => {
}
openDialog.close();
openDialog.remove();
document.title = savedTitle;
});
htmx.on(document, 'alpine:init', () => {

View File

@ -1,2 +1,3 @@
<title>{{ template "title" . }} — Numerus</title>
{{- template "breadcrumbs" . }}
{{- template "content" . }}