forked from ionic-team/ionic-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclick-block.ts
More file actions
46 lines (37 loc) · 1.11 KB
/
click-block.ts
File metadata and controls
46 lines (37 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { Directive, ElementRef, forwardRef, Inject, Renderer } from '@angular/core';
import { App } from '../components/app/app';
import { clearNativeTimeout, nativeTimeout } from './dom';
import { Config } from '../config/config';
const DEFAULT_EXPIRE = 330;
/**
* @private
*/
@Directive({
selector: '.click-block'
})
export class ClickBlock {
private _tmrId: number;
private _showing: boolean = false;
isEnabled: boolean;
constructor(
@Inject(forwardRef(() => App)) app: App,
config: Config,
private elementRef: ElementRef,
private renderer: Renderer
) {
app._clickBlock = this;
this.isEnabled = config.getBoolean('clickBlock', true);
}
activate(shouldShow: boolean, expire: number) {
if (this.isEnabled) {
clearNativeTimeout(this._tmrId);
if (shouldShow) {
this._tmrId = nativeTimeout(this.activate.bind(this, false), expire || DEFAULT_EXPIRE);
}
if (this._showing !== shouldShow) {
this.renderer.setElementClass(this.elementRef.nativeElement, 'click-block-active', shouldShow);
this._showing = shouldShow;
}
}
}
}