Documentation
¶
Overview ¶
package trigger provides builders for hx-trigger attribute values.
Index ¶
- type Event
- func (e *Event) Changed() *Event
- func (s *Event) Clear(modifier Modifier) *Event
- func (e *Event) Consume() *Event
- func (e *Event) Delay(timing time.Duration) *Event
- func (e *Event) Filter(filter string) *Event
- func (e *Event) From(extendedSelector FromSelector) *Event
- func (e *Event) Once() *Event
- func (e *Event) OverrideEvent(event string) *Event
- func (e *Event) Queue(option QueueOption) *Event
- func (e *Event) String() string
- func (e *Event) Target(selector string) *Event
- func (e *Event) Throttle(timing time.Duration) *Event
- type FromSelector
- type IntersectEvent
- type Modifier
- type Poll
- type QueueOption
- type SelectorModifier
- type Trigger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
An Event is a builder to create a new user event hx-trigger.
func (*Event) Changed ¶
Changed makes the event only if the value of the element has changed. Please pay attention change is the name of the event and changed is the name of the modifier.
func (*Event) Clear ¶
Clear removes a modifier entirely from the builder. Used to undo an previously set modifier.
func (*Event) Consume ¶
Consume causes the event not to trigger any other htmx requests on parents (or on elements listening on parents).
func (*Event) Delay ¶
Delay will cause a delay before an event triggers a request. If the event is seen again it will reset the delay.
func (*Event) Filter ¶
Filter specifies a boolean javascript expression as an event filter.
If this expression evaluates to true the event will be triggered, otherwise it will be ignored.
<div hx-get="/clicked" hx-trigger="click[ctrlKey]">Control Click Me</div>
Conditions can also refer to global functions or state
<div hx-get="/clicked" hx-trigger="click[checkGlobalState()]">Control Click Me</div>
And can also be combined using the standard javascript syntax
<div hx-get="/clicked" hx-trigger="click[ctrlKey&&shiftKey]">Control-Shift Click Me</div>
Note that all symbols used in the expression will be resolved first against the triggering event, and then next against the global namespace, so myEvent[foo] will first look for a property named foo on the event, then look for a global symbol with the name foo
func (*Event) From ¶
func (e *Event) From(extendedSelector FromSelector) *Event
From allows the event that triggers a request to come from another element in the document (e.g. listening to a key event on the body, to support hot keys) A standard CSS selector resolves to all elements matching that selector. Thus, from:input would listen on every input on the page. If the selector contains whitespace, it will be wrapped in () to disambiguate it from other modifiers.
func (*Event) OverrideEvent ¶
OverrideEvent overrides the initial event name. This is useful if you are forking a default trigger setup.
func (*Event) Queue ¶
func (e *Event) Queue(option QueueOption) *Event
Queue determines how events are queued if an event occurs while a request for another event is in flight.
func (*Event) Target ¶
Target allows you to filter via a CSS selector on the target of the event. This can be useful when you want to listen for triggers from elements that might not be in the DOM at the point of initialization, by, for example, listening on the body, but with a target filter for a child element. If the selector contains whitespace, it will be wrapped in () to disambiguate it from other modifiers.
type FromSelector ¶ added in v0.0.4
type FromSelector string
A FromSelector is a non-standard selector for the From modifier.
const ( FromDocument FromSelector = "document" // listen for events on the document FromWindow FromSelector = "window" // listen for events on the window FromNext FromSelector = "next" // resolves to element.nextElementSibling FromPrevious FromSelector = "previous" // resolves to element.previousElementSibling )
func FromRelative ¶ added in v0.0.4
func FromRelative(modifier SelectorModifier, selector string) FromSelector
FromRelative creates a relative selector for an Event.From modifier. It always wraps the selector in (), in case it contains a space.
type IntersectEvent ¶
type IntersectEvent struct {
Event
}
An IntersectEvent fires once when an element first intersects the viewport. This supports additional options to a normal trigger, IntersectEvent.Root and IntersectEvent.Threshold.
func NewIntersectEvent ¶
func NewIntersectEvent() *IntersectEvent
NewIntersectEvent configures a trigger that fires once when an element first intersects the viewport. This supports additional options to a normal trigger, IntersectEvent.Root and IntersectEvent.Threshold.
func (*IntersectEvent) Root ¶
func (e *IntersectEvent) Root(selector string) *IntersectEvent
Root configures a CSS selector of the root element for intersection.
func (*IntersectEvent) Threshold ¶
func (e *IntersectEvent) Threshold(threshold float64) *IntersectEvent
Threshold takes a floating point number between 0.0 and 1.0, indicating what amount of intersection to fire the event on
type Modifier ¶
type Modifier string
Modifier is an enum of the possible hx-trigger modifiers.
const ( Once Modifier = "once" // the event will only trigger once (e.g. the first click) Changed Modifier = "changed" // the event will only change if the value of the element has changed. Please pay attention change is the name of the event and changed is the name of the modifier. Delay Modifier = "delay" // a delay will occur before an event triggers a request. If the event is seen again it will reset the delay. Throttle Modifier = "throttle" // a throttle will occur after an event triggers a request. If the event is seen again before the delay completes, it is ignored, the element will trigger at the end of the delay. From Modifier = "from" // allows the event that triggers a request to come from another element in the document (e.g. listening to a key event on the body, to support hot keys) Target Modifier = "target" // allows you to filter via a CSS selector on the target of the event. This can be useful when you want to listen for triggers from elements that might not be in the DOM at the point of initialization, by, for example, listening on the body, but with a target filter for a child element Consume Modifier = "consume" // if this option is included the event will not trigger any other htmx requests on parents (or on elements listening on parents) Queue Modifier = "queue" // determines how events are queued if an event occurs while a request for another event is in flight. Options are: Root Modifier = "root" // a CSS selector of the root element for intersection. Only used by the intersect event. Threshold Modifier = "threshold" // a floating point number between 0.0 and 1.0, indicating what amount of intersection to fire the event on. Only used by the intersect event. )
type Poll ¶
type Poll struct {
// contains filtered or unexported fields
}
func NewFilteredPoll ¶
NewPoll creates a new polling trigger with a javascript expression as a filter. When the timer goes off, the trigger will only occur if the expression evaluates to true.
type QueueOption ¶
type QueueOption string
A QueueOption determines how events are queued if an event occurs while a request for another event is in flight.
const ( First QueueOption = "first" // queue the first event Last QueueOption = "last" // queue the last event (default) All QueueOption = "all" // queue all events (issue a request for each event) None QueueOption = "none" // do not queue new events )
type SelectorModifier ¶ added in v0.0.4
type SelectorModifier string
A SelectorModifier is a relative modifier to a CSS selector. This is used for "extended selectors". Some attributes only support a subset of these, but any Relative function that takes this type supports the full set..
const ( Closest SelectorModifier = "closest" // find the closest ancestor element or itself, that matches the given CSS selector Find SelectorModifier = "find" // find the first child descendant element that matches the given CSS selector Next SelectorModifier = "next" // scan the DOM forward for the first element that matches the given CSS selector. (e.g. next .error will target the closest following sibling element with error class) Previous SelectorModifier = "previous" // scan the DOM backwards fo )