import { ActivatorBase , isActivatedDisabled } from './activator-base' ; import { App } from '../components/app/app' ; import { Config } from '../config/config' ; import { DomController } from '../platform/dom-controller' ; import { PointerCoordinates } from '../util/dom' ; export class Activator implements ActivatorBase { protected _queue : HTMLElement [ ] = [ ] ; protected _active : HTMLElement [ ] = [ ] ; protected _activeDefer : Function ; protected _clearDefer : Function ; _css : string ; activatedDelay = ADD_ACTIVATED_DEFERS ; clearDelay = CLEAR_STATE_DEFERS ; constructor ( protected app , config , private dom ) { this . _css = config . get ( 'activatedClass' , 'activated' ) ; } clickAction ( ev , activatableEle , _startCoord ) { if ( isActivatedDisabled ( ev , activatableEle ) ) { return ; } this . _scheduleClear ( ) ; this . _queue . length = 0 ; for ( var i = 0 ; i < this . _active . length ; i ++ ) { this . _active [ i ] . classList . remove ( this . _css ) ; } this . _active . length = 0 ; if ( activatableEle && activatableEle . parentNode ) { this . _active . push ( activatableEle ) ; activatableEle . classList . add ( this . _css ) ; } } downAction ( ev , activatableEle , _startCoord ) { if ( isActivatedDisabled ( ev , activatableEle ) ) { return ; } this . unscheduleClear ( ) ; this . deactivate ( true ) ; this . _queue . push ( activatableEle ) ; this . _activeDefer = this . dom . write ( ( ) => { this . _activeDefer = null ; let activatableEle ; for ( let i = 0 ; i < this . _queue . length ; i ++ ) { activatableEle = this . _queue [ i ] ; this . _active . push ( activatableEle ) ; activatableEle . classList . add ( this . _css ) ; } this . _queue . length = 0 ; } , this . activatedDelay ) ; } upAction ( _ev , _activatableEle , _startCoord ) { this . _scheduleClear ( ) ; } _scheduleClear ( ) { if ( this . _clearDefer ) { return ; } this . _clearDefer = this . dom . write ( ( ) => { this . clearState ( true ) ; this . _clearDefer = null ; } , this . clearDelay ) ; } unscheduleClear ( ) { if ( this . _clearDefer ) { this . _clearDefer ( ) ; this . _clearDefer = null ; } } clearState ( animated ) { if ( ! this . app . isEnabled ( ) ) { this . dom . write ( ( ) => { this . clearState ( animated ) ; } , 600 ) ; } else { this . deactivate ( animated ) ; } } deactivate ( animated ) { this . _clearDeferred ( ) ; this . _queue . length = 0 ; let ele ; for ( var i = 0 ; i < this . _active . length ; i ++ ) { ele = this . _active [ i ] ; ( < any > ele . style ) [ this . dom . plt . Css . transition ] = animated ? '' : 'none' ; ele . classList . remove ( this . _css ) ; } this . _active . length = 0 ; } _clearDeferred ( ) { if ( this . _activeDefer ) { this . _activeDefer ( ) ; this . _activeDefer = null ; } } } const ADD_ACTIVATED_DEFERS = 80 ; const CLEAR_STATE_DEFERS = 80 ;