import { listenBySelector } from '../util/dom-event' ; import { EventApi } from '../api/EventApi' ; import { elementClosest } from '../util/dom-manip' ; import { getElSeg } from '../component/event-rendering' ; import { Interaction , InteractionSettings } from './interaction' ; import { ViewApi } from '../ViewApi' ; export interface EventClickArg { el : HTMLElement ; event : EventApi ; jsEvent : MouseEvent ; view : ViewApi ; } export class EventClicking extends Interaction { constructor ( settings ) { super ( settings ) ; this . destroy = listenBySelector ( settings . el , 'click' , '.fc-event' , this . handleSegClick ) ; } handleSegClick = ( ev , segEl ) => { let { component } = this ; let { context } = component ; let seg = getElSeg ( segEl ) ; if ( seg && component . isValidSegDownEl ( ev . target as HTMLElement ) ) { let hasUrlContainer = elementClosest ( ev . target as HTMLElement , '.fc-event-forced-url' ) ; let url = hasUrlContainer ? ( hasUrlContainer . querySelector ( 'a[href]' ) as any ) . href : '' ; context . emitter . trigger ( 'eventClick' , { el : segEl , event : new EventApi ( component . context , seg . eventRange . def , seg . eventRange . instance ) , jsEvent : ev as MouseEvent , view : context . viewApi , } as EventClickArg ) ; if ( url && ! ev . defaultPrevented ) { window . location . href = url ; } } } ; }