|
1 |
| -import { ApplicationRef, ComponentRef, Directive, ElementRef, EmbeddedViewRef, HostListener, Input, ViewContainerRef } from '@angular/core'; |
| 1 | +import { ApplicationRef, ComponentRef, Directive, ElementRef, EmbeddedViewRef, HostListener, Input, OnDestroy, ViewContainerRef } from '@angular/core'; |
2 | 2 | import { TooltipComponent } from "./tooltip.component";
|
3 | 3 |
|
4 | 4 | @Directive({
|
5 | 5 | selector: '[systelabTooltip],[systelabTooltipHtml]'
|
6 | 6 | })
|
7 |
| -export class TooltipDirective { |
| 7 | +export class TooltipDirective implements OnDestroy { |
8 | 8 |
|
9 | 9 | public static readonly DEFAULT_DELAY = 200;
|
10 | 10 |
|
11 | 11 | @Input() public systelabTooltip: string;
|
12 | 12 | @Input() public systelabTooltipHtml: string;
|
13 |
| - @Input() systelabTooltipPlacement: undefined | 'top' | 'right' | 'bottom' | 'left'; |
14 |
| - @Input() systelabTooltipDelay = TooltipDirective.DEFAULT_DELAY; |
15 |
| - @Input() systelabTooltipHideDelay = TooltipDirective.DEFAULT_DELAY; |
| 13 | + @Input() public systelabTooltipPlacement: undefined | 'top' | 'right' | 'bottom' | 'left'; |
| 14 | + @Input() public systelabTooltipDelay = TooltipDirective.DEFAULT_DELAY; |
| 15 | + @Input() public systelabTooltipHideDelay = TooltipDirective.DEFAULT_DELAY; |
16 | 16 |
|
17 | 17 | private componentRef: ComponentRef<any> | null = null;
|
18 | 18 | private showTimeout?: number;
|
19 | 19 | private hideTimeout?: number;
|
20 |
| - private touchTimeout?: number; |
21 | 20 |
|
22 | 21 | constructor(private elementRef: ElementRef, private appRef: ApplicationRef, private viewContainerRef: ViewContainerRef) {
|
23 | 22 | }
|
24 | 23 |
|
25 | 24 | @HostListener('mouseenter')
|
26 |
| - onMouseEnter(): void { |
| 25 | + public onMouseEnter(): void { |
27 | 26 | this.initializeTooltip();
|
28 | 27 | }
|
29 | 28 |
|
30 | 29 | @HostListener('mouseleave')
|
31 |
| - onMouseLeave(): void { |
32 |
| - this.setHideTooltipTimeout(); |
33 |
| - } |
34 |
| - |
35 |
| - @HostListener('touchstart', ['$event']) |
36 |
| - onTouchStart($event: TouchEvent): void { |
37 |
| - $event.preventDefault(); |
38 |
| - window.clearTimeout(this.touchTimeout); |
39 |
| - this.touchTimeout = window.setTimeout(this.initializeTooltip.bind(this), 500); |
40 |
| - } |
41 |
| - |
42 |
| - @HostListener('touchend') |
43 |
| - onTouchEnd(): void { |
44 |
| - window.clearTimeout(this.touchTimeout); |
45 |
| - this.setHideTooltipTimeout(); |
| 30 | + public onMouseLeave(): void { |
| 31 | + if (this.systelabTooltipHideDelay) { |
| 32 | + this.hideTimeout = this.setHideTooltipTimeout(); |
| 33 | + } else { |
| 34 | + this.destroy(); |
| 35 | + } |
46 | 36 | }
|
47 | 37 |
|
48 | 38 | private initializeTooltip() {
|
@@ -105,15 +95,15 @@ export class TooltipDirective {
|
105 | 95 | }
|
106 | 96 | }
|
107 | 97 |
|
108 |
| - private setHideTooltipTimeout() { |
109 |
| - this.hideTimeout = window.setTimeout(this.destroy.bind(this), this.systelabTooltipHideDelay); |
| 98 | + private setHideTooltipTimeout():number { |
| 99 | + return window.setTimeout(this.destroy.bind(this), this.systelabTooltipHideDelay); |
110 | 100 | }
|
111 | 101 |
|
112 |
| - ngOnDestroy(): void { |
| 102 | + public ngOnDestroy(): void { |
113 | 103 | this.destroy();
|
114 | 104 | }
|
115 | 105 |
|
116 |
| - destroy(): void { |
| 106 | + public destroy(): void { |
117 | 107 | if (this.componentRef !== null) {
|
118 | 108 | window.clearInterval(this.showTimeout);
|
119 | 109 | window.clearInterval(this.systelabTooltipHideDelay);
|
|
0 commit comments