28 lines
839 B
1
package pages
2
3
import (
4
"fmt"
5
"net/http"
6
)
7
8
// Notice performs a hx-oob-swap to replace the content of an element with a message.
9
// Pass the id of the element and the message to display.
10
func (s *Pages) Notice(w http.ResponseWriter, id, msg string) {
11
html := fmt.Sprintf(`<span id="%s" hx-swap-oob="innerHTML">%s</span>`, id, msg)
12
13
w.Header().Set("Content-Type", "text/html")
14
w.WriteHeader(http.StatusOK)
15
w.Write([]byte(html))
16
}
17
18
// HxRedirect is a full page reload with a new location.
19
func (s *Pages) HxRedirect(w http.ResponseWriter, location string) {
20
w.Header().Set("HX-Redirect", location)
21
w.WriteHeader(http.StatusOK)
22
}
23
24
// HxLocation is an SPA-style navigation to a new location.
25
func (s *Pages) HxLocation(w http.ResponseWriter, location string) {
26
w.Header().Set("HX-Location", location)
27
w.WriteHeader(http.StatusOK)
28
}
29