htmgo/framework/h/xhr.go

60 lines
3 KiB
Go
Raw Permalink Normal View History

2024-09-21 03:59:07 +00:00
package h
2024-10-02 03:26:03 +00:00
import (
"github.com/maddalax/htmgo/framework/hx"
)
2024-09-21 03:59:07 +00:00
2024-10-26 02:59:17 +00:00
// Get adds two attributes to the element: hx-get and hx-trigger.
2024-09-30 17:39:48 +00:00
func Get(path string, trigger ...string) *AttributeMapOrdered {
2024-09-23 02:33:22 +00:00
return AttributeList(Attribute(hx.GetAttr, path), HxTriggerString(trigger...))
2024-09-21 03:59:07 +00:00
}
2024-10-26 02:59:17 +00:00
// GetPartial adds two attributes to the element: hx-get and hx-trigger, and uses the partial path for the hx-get attribute.
2024-09-30 17:39:48 +00:00
func GetPartial(partial PartialFunc, trigger ...string) *AttributeMapOrdered {
2024-09-21 03:59:07 +00:00
return Get(GetPartialPath(partial), trigger...)
}
2024-10-26 02:59:17 +00:00
// GetPartialWithQs adds two attributes to the element: hx-get and hx-trigger, and uses the partial path for the hx-get attribute. It also sets the query string parameters.
2024-09-30 17:39:48 +00:00
func GetPartialWithQs(partial PartialFunc, qs *Qs, trigger string) *AttributeMapOrdered {
2024-09-21 03:59:07 +00:00
return Get(GetPartialPathWithQs(partial, qs), trigger)
}
2024-10-26 02:59:17 +00:00
// GetWithQs adds two attributes to the element: hx-get and hx-trigger, and uses the path for the hx-get attribute. It also sets the query string parameters.
2024-09-30 17:39:48 +00:00
func GetWithQs(path string, qs *Qs, trigger string) *AttributeMapOrdered {
2024-09-21 03:59:07 +00:00
return Get(SetQueryParams(path, qs), trigger)
}
2024-10-26 02:59:17 +00:00
// PostPartial adds two attributes to the element: hx-post and hx-trigger, and uses the partial path for the hx-post attribute.
2024-09-30 17:39:48 +00:00
func PostPartial(partial PartialFunc, triggers ...string) *AttributeMapOrdered {
return Post(GetPartialPath(partial), triggers...)
2024-09-21 03:59:07 +00:00
}
2024-10-26 02:59:17 +00:00
// PostPartialWithQs adds two attributes to the element: hx-post and hx-trigger, and uses the partial path for the hx-post attribute. It also sets the query string parameters.
2024-09-30 17:39:48 +00:00
func PostPartialWithQs(partial PartialFunc, qs *Qs, trigger ...string) *AttributeMapOrdered {
2024-09-21 03:59:07 +00:00
return Post(GetPartialPathWithQs(partial, qs), trigger...)
}
2024-09-30 17:39:48 +00:00
func Post(url string, trigger ...string) *AttributeMapOrdered {
2024-09-23 02:33:22 +00:00
return AttributeList(Attribute(hx.PostAttr, url), HxTriggerString(trigger...))
2024-09-21 03:59:07 +00:00
}
2024-10-26 02:59:17 +00:00
// PostWithQs adds two attributes to the element: hx-post and hx-trigger, and uses the path for the hx-post attribute. It also sets the query string parameters.
2024-09-30 17:39:48 +00:00
func PostWithQs(url string, qs *Qs, trigger string) *AttributeMapOrdered {
return Post(SetQueryParams(url, qs), trigger)
}
2024-10-26 02:59:17 +00:00
// PostOnClick adds two attributes to the element: hx-post and hx-trigger, and uses the path for the hx-post attribute. It also sets the hx-trigger to hx-click.
2024-09-30 17:39:48 +00:00
func PostOnClick(url string) *AttributeMapOrdered {
2024-09-21 03:59:07 +00:00
return Post(url, hx.ClickEvent)
}
2024-10-26 02:59:17 +00:00
// PostPartialOnClick adds two attributes to the element: hx-post and hx-trigger, and uses the partial path for the hx-post attribute. It also sets the hx-trigger to hx-click.
2024-09-30 17:39:48 +00:00
func PostPartialOnClick(partial PartialFunc) *AttributeMapOrdered {
2024-09-21 03:59:07 +00:00
return PostOnClick(GetPartialPath(partial))
}
2024-10-26 02:59:17 +00:00
// PostPartialOnClickQs adds two attributes to the element: hx-post and hx-trigger, and uses the partial path for the hx-post attribute. It also sets the hx-trigger to hx-click. It also sets the query string parameters.
2024-09-30 17:39:48 +00:00
func PostPartialOnClickQs(partial PartialFunc, qs *Qs) *AttributeMapOrdered {
2024-09-21 03:59:07 +00:00
return PostOnClick(GetPartialPathWithQs(partial, qs))
}