import { listenToHoverBySelector } from '../util/dom-event' ; import { EventApi } from '../api/EventApi' ; import { getElSeg } from '../component/event-rendering' ; import { Interaction , InteractionSettings } from './interaction' ; import { ViewApi } from '../ViewApi' ; export interface EventHoveringArg { el : HTMLElement ; event : EventApi ; jsEvent : MouseEvent ; view : ViewApi ; } export class EventHovering extends Interaction { removeHoverListeners : ( ) => void ; currentSegEl : HTMLElement ; constructor ( settings ) { super ( settings ) ; this . removeHoverListeners = listenToHoverBySelector ( settings . el , '.fc-event' , this . handleSegEnter , this . handleSegLeave ) ; } destroy ( ) { this . removeHoverListeners ( ) ; } handleEventElRemove = ( el ) => { if ( el === this . currentSegEl ) { this . handleSegLeave ( null , this . currentSegEl ) ; } } ; handleSegEnter = ( ev , segEl ) => { if ( getElSeg ( segEl ) ) { this . currentSegEl = segEl ; this . triggerEvent ( 'eventMouseEnter' , ev , segEl ) ; } } ; handleSegLeave = ( ev , segEl ) => { if ( this . currentSegEl ) { this . currentSegEl = null ; this . triggerEvent ( 'eventMouseLeave' , ev , segEl ) ; } } ; triggerEvent ( publicEvName , ev , segEl ) { let { component } = this ; let { context } = component ; let seg = getElSeg ( segEl ) ! ; if ( ! ev || component . isValidSegDownEl ( ev . target as HTMLElement ) ) { context . emitter . trigger ( publicEvName , { el : segEl , event : new EventApi ( context , seg . eventRange . def , seg . eventRange . instance ) , jsEvent : ev as MouseEvent , view : context . viewApi , } as EventHoveringArg ) ; } } }