forked from tangled.org/core
Monorepo for Tangled — https://tangled.org
at master 1.0 kB view raw
1package pages 2 3import ( 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. 10func (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// HxRefresh is a client-side full refresh of the page. 19func (s *Pages) HxRefresh(w http.ResponseWriter) { 20 w.Header().Set("HX-Refresh", "true") 21 w.WriteHeader(http.StatusOK) 22} 23 24// HxRedirect is a full page reload with a new location. 25func (s *Pages) HxRedirect(w http.ResponseWriter, location string) { 26 w.Header().Set("HX-Redirect", location) 27 w.WriteHeader(http.StatusOK) 28} 29 30// HxLocation is an SPA-style navigation to a new location. 31func (s *Pages) HxLocation(w http.ResponseWriter, location string) { 32 w.Header().Set("HX-Location", location) 33 w.WriteHeader(http.StatusOK) 34}