|
|
|
@ -7,18 +7,22 @@ |
|
|
|
|
|
|
|
// tslint:disable: directive-selector
|
|
|
|
|
|
|
|
import { Directive, ElementRef, HostListener, Input, Renderer2 } from '@angular/core'; |
|
|
|
import { Directive, ElementRef, HostListener, Input, OnDestroy, Renderer2 } from '@angular/core'; |
|
|
|
import { DialogService, Tooltip } from '@app/framework/internal'; |
|
|
|
|
|
|
|
@Directive({ |
|
|
|
selector: '[title]' |
|
|
|
}) |
|
|
|
export class TooltipDirective { |
|
|
|
export class TooltipDirective implements OnDestroy { |
|
|
|
private titleText: string; |
|
|
|
private timer: any; |
|
|
|
|
|
|
|
@Input() |
|
|
|
public titlePosition = 'top-right'; |
|
|
|
|
|
|
|
@Input() |
|
|
|
public titleDelay = 1000; |
|
|
|
|
|
|
|
@Input() |
|
|
|
public set title(value: string) { |
|
|
|
this.titleText = value; |
|
|
|
@ -33,25 +37,47 @@ export class TooltipDirective { |
|
|
|
) { |
|
|
|
} |
|
|
|
|
|
|
|
public ngOnDestroy() { |
|
|
|
this.hide(); |
|
|
|
} |
|
|
|
|
|
|
|
@HostListener('mouseenter') |
|
|
|
public onMouseEnter() { |
|
|
|
this.hide(); |
|
|
|
|
|
|
|
if (this.titleText) { |
|
|
|
this.dialogs.tooltip(new Tooltip(this.element.nativeElement, this.titleText, this.titlePosition)); |
|
|
|
if (this.titleDelay > 0) { |
|
|
|
this.timer = setTimeout(() => { |
|
|
|
this.show(); |
|
|
|
}, this.titleDelay); |
|
|
|
} else { |
|
|
|
this.show(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@HostListener('mouseleave') |
|
|
|
public onMouseLeave() { |
|
|
|
if (this.titleText) { |
|
|
|
this.dialogs.tooltip(new Tooltip(this.element.nativeElement, null, this.titlePosition)); |
|
|
|
} |
|
|
|
this.hide(); |
|
|
|
} |
|
|
|
|
|
|
|
@HostListener('click') |
|
|
|
public onClick() { |
|
|
|
this.hide(); |
|
|
|
} |
|
|
|
|
|
|
|
private hide() { |
|
|
|
if (this.titleText) { |
|
|
|
this.dialogs.tooltip(new Tooltip(this.element.nativeElement, null, this.titlePosition)); |
|
|
|
} |
|
|
|
|
|
|
|
if (this.timer) { |
|
|
|
clearTimeout(this.timer); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private show() { |
|
|
|
this.dialogs.tooltip(new Tooltip(this.element.nativeElement, this.titleText, this.titlePosition)); |
|
|
|
} |
|
|
|
|
|
|
|
private unsetAttribute() { |
|
|
|
|