htmgo/framework/h/xhr.go
maddalax 3468baaa84 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	framework/h/attribute.go
#	framework/h/lifecycle.go
#	framework/h/render.go
2024-10-25 22:01:04 -05:00

59 lines
3 KiB
Go

package h
import (
"github.com/maddalax/htmgo/framework/hx"
)
// Get adds two attributes to the element: hx-get and hx-trigger.
func Get(path string, trigger ...string) *AttributeMapOrdered {
return AttributeList(Attribute(hx.GetAttr, path), HxTriggerString(trigger...))
}
// GetPartial adds two attributes to the element: hx-get and hx-trigger, and uses the partial path for the hx-get attribute.
func GetPartial(partial PartialFunc, trigger ...string) *AttributeMapOrdered {
return Get(GetPartialPath(partial), trigger...)
}
// 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.
func GetPartialWithQs(partial PartialFunc, qs *Qs, trigger string) *AttributeMapOrdered {
return Get(GetPartialPathWithQs(partial, qs), trigger)
}
// 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.
func GetWithQs(path string, qs *Qs, trigger string) *AttributeMapOrdered {
return Get(SetQueryParams(path, qs), trigger)
}
// PostPartial adds two attributes to the element: hx-post and hx-trigger, and uses the partial path for the hx-post attribute.
func PostPartial(partial PartialFunc, triggers ...string) *AttributeMapOrdered {
return Post(GetPartialPath(partial), triggers...)
}
// 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.
func PostPartialWithQs(partial PartialFunc, qs *Qs, trigger ...string) *AttributeMapOrdered {
return Post(GetPartialPathWithQs(partial, qs), trigger...)
}
func Post(url string, trigger ...string) *AttributeMapOrdered {
return AttributeList(Attribute(hx.PostAttr, url), HxTriggerString(trigger...))
}
// 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.
func PostWithQs(url string, qs *Qs, trigger string) *AttributeMapOrdered {
return Post(SetQueryParams(url, qs), trigger)
}
// 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.
func PostOnClick(url string) *AttributeMapOrdered {
return Post(url, hx.ClickEvent)
}
// 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.
func PostPartialOnClick(partial PartialFunc) *AttributeMapOrdered {
return PostOnClick(GetPartialPath(partial))
}
// 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.
func PostPartialOnClickQs(partial PartialFunc, qs *Qs) *AttributeMapOrdered {
return PostOnClick(GetPartialPathWithQs(partial, qs))
}