import { Injectable , OnDestroy , Optional , SkipSelf } from '@angular/core' ; import { RelatedContentService } from '../../../../common/services/related-content.service' ; import { ActivityEntity , ActivityService } from '../activity.service' ; import { Subscription , BehaviorSubject , Observable } from 'rxjs' ; import { toggleFullscreen } from '../../../../helpers/fullscreen' ; import { SiteService } from '../../../../common/services/site.service' ; import { Location } from '@angular/common' ; import { AnalyticsService } from '../../../../services/analytics' ; import { OverlayModalService } from '../../../../services/ux/overlay-modal' ; @ Injectable ( ) export class ActivityModalService { protected modalPager$ : Subscription ; protected asyncEntity$ : Subscription ; activityService : ActivityService ; /**
     * The current activityService entity
     */ entity : ActivityEntity ; /**
     * Where the browser url history  will return to when user leaves modal
     */ sourceUrl : string ; /**
     * Is the modal loading?
     */ loading$ : BehaviorSubject < boolean > = new BehaviorSubject < boolean > ( true ) ; /**
     * Whether the modal stage element is in fullscreen mode
     */ isFullscreen$ : BehaviorSubject < boolean > = new BehaviorSubject < boolean > ( false ) ; /**
     * Whether the cursor is hovering over the fullscreen icon
     */ fullscreenHovering$ : BehaviorSubject < boolean > = new BehaviorSubject < boolean > ( false ) ; overlayVisible$ : BehaviorSubject < boolean > = new BehaviorSubject < boolean > ( false ) ; pagerVisible$ : BehaviorSubject < boolean > = new BehaviorSubject < boolean > ( false ) ; constructor ( private site , private location , private overlayModal ) { } setSourceUrl ( url ) { this . sourceUrl = url ; } setActivityService ( activityService ) { if ( ! this . activityService ) { this . activityService = activityService ; } } setEntity ( entity ) { this . entity = entity ; this . activityService . setEntity ( entity ) ; } returnToSourceUrl ( ) { this . location . replaceState ( this . sourceUrl ) ; } dismiss ( ) { this . returnToSourceUrl ( ) ; this . activityService . displayOptions . isModal = false ; this . overlayModal . dismiss ( ) ; } toggleFullscreen ( ) { this . fullscreenHovering$ . next ( false ) ; const el = document . querySelector ( '.m-activityModal__stageWrapper' ) ; if ( el ) { this . isFullscreen$ . next ( toggleFullscreen ( el ) ) ; } } shouldFilterOutKeyDownEvent ( $event ) { const missingEvent = ! $event || ! $event . target ; const tagName = ( ( $event . target as HTMLElement ) . tagName || '' ) . toLowerCase ( ) ; const isContentEditable = ( $event . target as HTMLElement ) . contentEditable === 'true' ; if ( missingEvent || tagName === 'input' || tagName === 'textarea' || isContentEditable || ( $event . key !== 'ArrowLeft' && $event . key !== 'ArrowRight' && $event . key !== 'Escape' ) ) { return true ; } $event . stopPropagation ( ) ; $event . preventDefault ( ) ; return false ; } }