2021-10-04 17:58:17 +03:00
|
|
|
package rui
|
|
|
|
|
2024-09-12 14:05:11 +03:00
|
|
|
// Constants which describe values for view's animation events properties
|
2021-10-04 17:58:17 +03:00
|
|
|
const (
|
2021-11-04 21:13:34 +03:00
|
|
|
// TransitionRunEvent is the constant for "transition-run-event" property tag.
|
2024-09-18 13:50:06 +03:00
|
|
|
//
|
|
|
|
// Used by `View`.
|
|
|
|
// Is fired when a transition is first created, i.e. before any transition delay has begun.
|
|
|
|
//
|
|
|
|
// General listener format:
|
|
|
|
// `func(view rui.View, propertyName string)`.
|
|
|
|
//
|
|
|
|
// where:
|
|
|
|
// view - Interface of a view which generated this event,
|
|
|
|
// propertyName - Name of the property.
|
|
|
|
//
|
|
|
|
// Allowed listener formats:
|
|
|
|
// `func(view rui.View)`,
|
|
|
|
// `func(propertyName string)`,
|
|
|
|
// `func()`.
|
2024-11-13 12:56:39 +03:00
|
|
|
TransitionRunEvent PropertyName = "transition-run-event"
|
2021-10-04 17:58:17 +03:00
|
|
|
|
2024-09-18 13:50:06 +03:00
|
|
|
// TransitionStartEvent is the constant for "transition-start-event" property tag.
|
|
|
|
//
|
|
|
|
// Used by `View`.
|
|
|
|
// Is fired when a transition has actually started, i.e., after "delay" has ended.
|
|
|
|
//
|
|
|
|
// General listener format:
|
|
|
|
// `func(view rui.View, propertyName string)`.
|
|
|
|
//
|
|
|
|
// where:
|
|
|
|
// view - Interface of a view which generated this event,
|
|
|
|
// propertyName - Name of the property.
|
|
|
|
//
|
|
|
|
// Allowed listener formats:
|
|
|
|
// `func(view rui.View)`,
|
|
|
|
// `func(propertyName string)`,
|
|
|
|
// `func()`.
|
2024-11-13 12:56:39 +03:00
|
|
|
TransitionStartEvent PropertyName = "transition-start-event"
|
2021-10-04 17:58:17 +03:00
|
|
|
|
2021-11-04 21:13:34 +03:00
|
|
|
// TransitionEndEvent is the constant for "transition-end-event" property tag.
|
2024-09-18 13:50:06 +03:00
|
|
|
//
|
|
|
|
// Used by `View`.
|
|
|
|
// Is fired when a transition has completed.
|
|
|
|
//
|
|
|
|
// General listener format:
|
|
|
|
// `func(view rui.View, propertyName string)`.
|
|
|
|
//
|
|
|
|
// where:
|
|
|
|
// view - Interface of a view which generated this event,
|
|
|
|
// propertyName - Name of the property.
|
|
|
|
//
|
|
|
|
// Allowed listener formats:
|
|
|
|
// `func(view rui.View)`,
|
|
|
|
// `func(propertyName string)`,
|
|
|
|
// `func()`.
|
2024-11-13 12:56:39 +03:00
|
|
|
TransitionEndEvent PropertyName = "transition-end-event"
|
2021-10-04 17:58:17 +03:00
|
|
|
|
2021-11-04 21:13:34 +03:00
|
|
|
// TransitionCancelEvent is the constant for "transition-cancel-event" property tag.
|
2024-09-18 13:50:06 +03:00
|
|
|
//
|
|
|
|
// Used by `View`.
|
2024-11-13 12:56:39 +03:00
|
|
|
// Is fired when a transition is cancelled. The transition is cancelled when: * A new property transition has begun. * The
|
|
|
|
// "visibility" property is set to "gone". * The transition is stopped before it has run to completion, e.g. by moving the
|
2024-09-18 13:50:06 +03:00
|
|
|
// mouse off a hover-transitioning view.
|
|
|
|
//
|
|
|
|
// General listener format:
|
|
|
|
// `func(view rui.View, propertyName string)`.
|
|
|
|
//
|
|
|
|
// where:
|
|
|
|
// view - Interface of a view which generated this event,
|
|
|
|
// propertyName - Name of the property.
|
|
|
|
//
|
|
|
|
// Allowed listener formats:
|
|
|
|
// `func(view rui.View)`,
|
|
|
|
// `func(propertyName string)`,
|
|
|
|
// `func()`.
|
2024-11-13 12:56:39 +03:00
|
|
|
TransitionCancelEvent PropertyName = "transition-cancel-event"
|
2021-10-04 17:58:17 +03:00
|
|
|
|
|
|
|
// AnimationStartEvent is the constant for "animation-start-event" property tag.
|
2024-09-18 13:50:06 +03:00
|
|
|
//
|
|
|
|
// Used by `View`.
|
2024-11-13 12:56:39 +03:00
|
|
|
// Fired when an animation has started. If there is an "animation-delay", this event will fire once the delay period has
|
2024-09-18 13:50:06 +03:00
|
|
|
// expired.
|
|
|
|
//
|
|
|
|
// General listener format:
|
|
|
|
// `func(view rui.View, animationId string)`.
|
|
|
|
//
|
|
|
|
// where:
|
|
|
|
// view - Interface of a view which generated this event,
|
|
|
|
// animationId - Id of the animation.
|
|
|
|
//
|
|
|
|
// Allowed listener formats:
|
|
|
|
// `func(view rui.View)`,
|
|
|
|
// `func(animationId string)`,
|
|
|
|
// `func()`.
|
2024-11-13 12:56:39 +03:00
|
|
|
AnimationStartEvent PropertyName = "animation-start-event"
|
2021-10-04 17:58:17 +03:00
|
|
|
|
|
|
|
// AnimationEndEvent is the constant for "animation-end-event" property tag.
|
2024-09-18 13:50:06 +03:00
|
|
|
//
|
|
|
|
// Used by `View`.
|
2024-11-13 12:56:39 +03:00
|
|
|
// Fired when an animation has completed. If the animation aborts before reaching completion, such as if the element is
|
2024-09-18 13:50:06 +03:00
|
|
|
// removed or the animation is removed from the element, the "animation-end-event" is not fired.
|
|
|
|
//
|
|
|
|
// General listener format:
|
|
|
|
// `func(view rui.View, animationId string)`.
|
|
|
|
//
|
|
|
|
// where:
|
|
|
|
// view - Interface of a view which generated this event,
|
|
|
|
// animationId - Id of the animation.
|
|
|
|
//
|
|
|
|
// Allowed listener formats:
|
|
|
|
// `func(view rui.View)`,
|
|
|
|
// `func(animationId string)`,
|
|
|
|
// `func()`.
|
2024-11-13 12:56:39 +03:00
|
|
|
AnimationEndEvent PropertyName = "animation-end-event"
|
2021-10-04 17:58:17 +03:00
|
|
|
|
|
|
|
// AnimationCancelEvent is the constant for "animation-cancel-event" property tag.
|
2024-09-18 13:50:06 +03:00
|
|
|
//
|
|
|
|
// Used by `View`.
|
2024-11-13 12:56:39 +03:00
|
|
|
// Fired when an animation unexpectedly aborts. In other words, any time it stops running without sending the
|
|
|
|
// "animation-end-event". This might happen when the animation-name is changed such that the animation is removed, or when
|
|
|
|
// the animating view is hidden. Therefore, either directly or because any of its containing views are hidden. The event
|
2024-09-18 13:50:06 +03:00
|
|
|
// is not supported by all browsers.
|
|
|
|
//
|
|
|
|
// General listener format:
|
|
|
|
// `func(view rui.View, animationId string)`.
|
|
|
|
//
|
|
|
|
// where:
|
|
|
|
// view - Interface of a view which generated this event,
|
|
|
|
// animationId - Id of the animation.
|
|
|
|
//
|
|
|
|
// Allowed listener formats:
|
|
|
|
// `func(view rui.View)`,
|
|
|
|
// `func(animationId string)`,
|
|
|
|
// `func()`.
|
2024-11-13 12:56:39 +03:00
|
|
|
AnimationCancelEvent PropertyName = "animation-cancel-event"
|
2021-10-04 17:58:17 +03:00
|
|
|
|
|
|
|
// AnimationIterationEvent is the constant for "animation-iteration-event" property tag.
|
2024-09-18 13:50:06 +03:00
|
|
|
//
|
|
|
|
// Used by `View`.
|
2024-11-13 12:56:39 +03:00
|
|
|
// Fired when an iteration of an animation ends, and another one begins. This event does not occur at the same time as the
|
2024-09-18 13:50:06 +03:00
|
|
|
// animation end event, and therefore does not occur for animations with an "iteration-count" of one.
|
|
|
|
//
|
|
|
|
// General listener format:
|
|
|
|
// `func(view rui.View, animationId string)`.
|
|
|
|
//
|
|
|
|
// where:
|
|
|
|
// view - Interface of a view which generated this event,
|
|
|
|
// animationId - Id of the animation.
|
|
|
|
//
|
|
|
|
// Allowed listener formats:
|
|
|
|
// `func(view rui.View)`,
|
|
|
|
// `func(animationId string)`,
|
|
|
|
// `func()`.
|
2024-11-13 12:56:39 +03:00
|
|
|
AnimationIterationEvent PropertyName = "animation-iteration-event"
|
2021-10-04 17:58:17 +03:00
|
|
|
)
|
|
|
|
|
2024-11-13 12:56:39 +03:00
|
|
|
/*
|
|
|
|
func setTransitionListener(properties Properties, tag PropertyName, value any) bool {
|
2024-11-18 17:20:25 +03:00
|
|
|
if listeners, ok := valueToOneArgEventListeners[View, string](value); ok {
|
2024-11-13 12:56:39 +03:00
|
|
|
if len(listeners) == 0 {
|
|
|
|
properties.setRaw(tag, nil)
|
|
|
|
} else {
|
|
|
|
properties.setRaw(tag, listeners)
|
2021-10-04 17:58:17 +03:00
|
|
|
}
|
2024-11-13 12:56:39 +03:00
|
|
|
return true
|
2021-10-04 17:58:17 +03:00
|
|
|
}
|
2024-11-13 12:56:39 +03:00
|
|
|
notCompatibleType(tag, value)
|
|
|
|
return false
|
2021-10-04 17:58:17 +03:00
|
|
|
}
|
|
|
|
|
2024-11-13 12:56:39 +03:00
|
|
|
func (view *viewData) removeTransitionListener(tag PropertyName) {
|
2021-10-04 17:58:17 +03:00
|
|
|
delete(view.properties, tag)
|
|
|
|
if view.created {
|
2024-11-13 12:56:39 +03:00
|
|
|
if js, ok := eventJsFunc[tag]; ok {
|
2022-10-30 17:22:33 +03:00
|
|
|
view.session.removeProperty(view.htmlID(), js.jsEvent)
|
2021-10-04 17:58:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func transitionEventsHtml(view View, buffer *strings.Builder) {
|
2024-11-13 12:56:39 +03:00
|
|
|
for _, tag := range []PropertyName{TransitionRunEvent, TransitionStartEvent, TransitionEndEvent, TransitionCancelEvent} {
|
2021-10-04 17:58:17 +03:00
|
|
|
if value := view.getRaw(tag); value != nil {
|
2024-11-13 12:56:39 +03:00
|
|
|
if js, ok := eventJsFunc[tag]; ok {
|
|
|
|
if listeners, ok := value.([]func(View, string)); ok && len(listeners) > 0 {
|
|
|
|
buffer.WriteString(js.jsEvent)
|
|
|
|
buffer.WriteString(`="`)
|
|
|
|
buffer.WriteString(js.jsFunc)
|
|
|
|
buffer.WriteString(`(this, event)" `)
|
|
|
|
}
|
2021-10-04 17:58:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-11-13 12:56:39 +03:00
|
|
|
*/
|
2021-10-04 17:58:17 +03:00
|
|
|
|
2024-11-13 12:56:39 +03:00
|
|
|
func (view *viewData) handleTransitionEvents(tag PropertyName, data DataObject) {
|
|
|
|
if propertyName, ok := data.PropertyValue("property"); ok {
|
|
|
|
property := PropertyName(propertyName)
|
2021-10-04 17:58:17 +03:00
|
|
|
if tag == TransitionEndEvent || tag == TransitionCancelEvent {
|
|
|
|
if animation, ok := view.singleTransition[property]; ok {
|
|
|
|
delete(view.singleTransition, property)
|
2024-11-13 12:56:39 +03:00
|
|
|
setTransition(view, tag, animation)
|
|
|
|
session := view.session
|
|
|
|
session.updateCSSProperty(view.htmlID(), "transition", transitionCSS(view, session))
|
2021-10-04 17:58:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-18 17:20:25 +03:00
|
|
|
for _, listener := range getOneArgEventListeners[View, PropertyName](view, nil, tag) {
|
2021-10-04 17:58:17 +03:00
|
|
|
listener(view, property)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-13 12:56:39 +03:00
|
|
|
/*
|
|
|
|
func setAnimationListener(properties Properties, tag PropertyName, value any) bool {
|
2024-11-18 17:20:25 +03:00
|
|
|
if listeners, ok := valueToOneArgEventListeners[View, string](value); ok {
|
2024-11-13 12:56:39 +03:00
|
|
|
if len(listeners) == 0 {
|
|
|
|
properties.setRaw(tag, nil)
|
|
|
|
} else {
|
|
|
|
properties.setRaw(tag, listeners)
|
|
|
|
}
|
|
|
|
return true
|
2021-10-04 17:58:17 +03:00
|
|
|
}
|
2024-11-13 12:56:39 +03:00
|
|
|
notCompatibleType(tag, value)
|
2021-10-04 17:58:17 +03:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-11-13 12:56:39 +03:00
|
|
|
func (view *viewData) removeAnimationListener(tag PropertyName) {
|
2021-10-04 17:58:17 +03:00
|
|
|
delete(view.properties, tag)
|
|
|
|
if view.created {
|
2024-11-13 12:56:39 +03:00
|
|
|
if js, ok := eventJsFunc[tag]; ok {
|
2022-10-30 17:22:33 +03:00
|
|
|
view.session.removeProperty(view.htmlID(), js.jsEvent)
|
2021-10-04 17:58:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func animationEventsHtml(view View, buffer *strings.Builder) {
|
2024-11-13 12:56:39 +03:00
|
|
|
for _, tag := range []PropertyName{AnimationStartEvent, AnimationEndEvent, AnimationIterationEvent, AnimationCancelEvent} {
|
2021-10-04 17:58:17 +03:00
|
|
|
if value := view.getRaw(tag); value != nil {
|
2024-11-13 12:56:39 +03:00
|
|
|
if js, ok := eventJsFunc[tag]; ok {
|
|
|
|
if listeners, ok := value.([]func(View, string)); ok && len(listeners) > 0 {
|
|
|
|
buffer.WriteString(js.jsEvent)
|
|
|
|
buffer.WriteString(`="`)
|
|
|
|
buffer.WriteString(js.jsFunc)
|
|
|
|
buffer.WriteString(`(this, event)" `)
|
|
|
|
}
|
2021-10-04 17:58:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-11-13 12:56:39 +03:00
|
|
|
*/
|
2021-10-04 17:58:17 +03:00
|
|
|
|
2024-11-13 12:56:39 +03:00
|
|
|
func (view *viewData) handleAnimationEvents(tag PropertyName, data DataObject) {
|
2024-11-18 17:20:25 +03:00
|
|
|
if listeners := getOneArgEventListeners[View, string](view, nil, tag); len(listeners) > 0 {
|
2021-10-04 17:58:17 +03:00
|
|
|
id := ""
|
|
|
|
if name, ok := data.PropertyValue("name"); ok {
|
2022-08-31 22:17:46 +03:00
|
|
|
for _, animation := range GetAnimation(view) {
|
2021-10-04 17:58:17 +03:00
|
|
|
if name == animation.animationName() {
|
|
|
|
id, _ = stringProperty(animation, ID, view.Session())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, listener := range listeners {
|
|
|
|
listener(view, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetTransitionRunListeners returns the "transition-run-event" listener list.
|
|
|
|
// If there are no listeners then the empty list is returned.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetTransitionRunListeners(view View, subviewID ...string) []func(View, string) {
|
2024-11-18 17:20:25 +03:00
|
|
|
return getOneArgEventListeners[View, string](view, subviewID, TransitionRunEvent)
|
2021-10-04 17:58:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetTransitionStartListeners returns the "transition-start-event" listener list.
|
|
|
|
// If there are no listeners then the empty list is returned.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetTransitionStartListeners(view View, subviewID ...string) []func(View, string) {
|
2024-11-18 17:20:25 +03:00
|
|
|
return getOneArgEventListeners[View, string](view, subviewID, TransitionStartEvent)
|
2021-10-04 17:58:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetTransitionEndListeners returns the "transition-end-event" listener list.
|
|
|
|
// If there are no listeners then the empty list is returned.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetTransitionEndListeners(view View, subviewID ...string) []func(View, string) {
|
2024-11-18 17:20:25 +03:00
|
|
|
return getOneArgEventListeners[View, string](view, subviewID, TransitionEndEvent)
|
2021-10-04 17:58:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetTransitionCancelListeners returns the "transition-cancel-event" listener list.
|
|
|
|
// If there are no listeners then the empty list is returned.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetTransitionCancelListeners(view View, subviewID ...string) []func(View, string) {
|
2024-11-18 17:20:25 +03:00
|
|
|
return getOneArgEventListeners[View, string](view, subviewID, TransitionCancelEvent)
|
2021-10-04 17:58:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetAnimationStartListeners returns the "animation-start-event" listener list.
|
|
|
|
// If there are no listeners then the empty list is returned.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetAnimationStartListeners(view View, subviewID ...string) []func(View, string) {
|
2024-11-18 17:20:25 +03:00
|
|
|
return getOneArgEventListeners[View, string](view, subviewID, AnimationStartEvent)
|
2021-10-04 17:58:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetAnimationEndListeners returns the "animation-end-event" listener list.
|
|
|
|
// If there are no listeners then the empty list is returned.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetAnimationEndListeners(view View, subviewID ...string) []func(View, string) {
|
2024-11-18 17:20:25 +03:00
|
|
|
return getOneArgEventListeners[View, string](view, subviewID, AnimationEndEvent)
|
2021-10-04 17:58:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetAnimationCancelListeners returns the "animation-cancel-event" listener list.
|
|
|
|
// If there are no listeners then the empty list is returned.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetAnimationCancelListeners(view View, subviewID ...string) []func(View, string) {
|
2024-11-18 17:20:25 +03:00
|
|
|
return getOneArgEventListeners[View, string](view, subviewID, AnimationCancelEvent)
|
2021-10-04 17:58:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetAnimationIterationListeners returns the "animation-iteration-event" listener list.
|
|
|
|
// If there are no listeners then the empty list is returned.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetAnimationIterationListeners(view View, subviewID ...string) []func(View, string) {
|
2024-11-18 17:20:25 +03:00
|
|
|
return getOneArgEventListeners[View, string](view, subviewID, AnimationIterationEvent)
|
2021-10-04 17:58:17 +03:00
|
|
|
}
|