import { Directive , ElementRef , Inject , Renderer , forwardRef } from '@angular/core' ; import { App } from '../app/app' ; import { Config } from '../../config/config' ; import { Platform } from '../../platform/platform' ; hidden @ Directive ( { selector : '.click-block' } ) export class ClickBlock { private _tmr : number ; private _showing : boolean = false ; private _start : number ; private _minEnd : number ; isEnabled : boolean ; constructor ( @ Inject ( forwardRef ( ( ) => App ) ) app , config , private plt , private elementRef , private renderer ) { app . _clickBlock = this ; const enabled = this . isEnabled = config . getBoolean ( 'clickBlock' , true ) ; if ( enabled ) { this . _setElementClass ( 'click-block-enabled' , true ) ; } } activate ( shouldShow , expire = 100 , minDuration = 0 ) { if ( this . isEnabled ) { this . plt . cancelTimeout ( this . _tmr ) ; if ( shouldShow ) { this . _start = Date . now ( ) ; this . _minEnd = this . _start + ( minDuration || 0 ) ; this . _activate ( true ) ; } this . _tmr = this . plt . timeout ( this . _activate . bind ( this , false ) , expire ) ; } } internal _activate ( shouldShow ) { if ( this . _showing !== shouldShow ) { if ( ! shouldShow ) { var now = Date . now ( ) ; if ( now < this . _minEnd ) { this . _tmr = this . plt . timeout ( this . _activate . bind ( this , false ) , this . _minEnd - now ) ; return ; } } this . _setElementClass ( 'click-block-active' , shouldShow ) ; this . _showing = shouldShow ; } } private _setElementClass ( className , add ) { this . renderer . setElementClass ( this . elementRef . nativeElement , className , add ) ; } }