pm-controls
Version:
ProModel Controls
71 lines (63 loc) • 2.14 kB
text/typescript
import {
Directive,
HostListener,
Input,
OnInit
} from '@angular/core';
import { TooltipComponent } from '../../components/tooltips/tooltip-component';
import { setTimeout } from 'core-js/library/web/timers';
export class TooltipDirective {
public tooltip: TooltipComponent;
//@Input() public tooltipDataContext: any;
//@Input() public tooltipTemplate: any;
//@Input() public Content: string;
public stillHover: boolean;
public hoverKey: number;
public x: number;
public y: number;
public mouseMove(event: MouseEvent): void {
this.x = event.clientX;
this.y = event.clientY
}
public onTooltip(event: MouseEvent): void {
this.stillHover = true;
this.hoverKey = Math.random();
setTimeout(() => {
if(this.stillHover)
{
//console.log('mouseOver');
//this.tooltip.DataContext = this.tooltipDataContext;
//this.tooltip.tooltipTemplate = this.tooltipTemplate;
this.tooltip.Show(this.x, this.y);
event.preventDefault();
event.stopPropagation();
}
}
, this.tooltip.Delay);
this.DurationTimer(this.hoverKey);
}
DurationTimer(localKey: number)
{
setTimeout(() => {
if(this.stillHover && localKey == this.hoverKey)
this.tooltip.Hide();
}
, (this.tooltip.Duration + this.tooltip.Delay));
}
public offTooltip(event: MouseEvent): void {
this.stillHover = false;
//console.log('mouseLeave');
//this.tooltip.DataContext = this.tooltipDataContext;
//this.tooltip.tooltipTemplate = this.tooltipTemplate;
this.tooltip.Hide();
}
ngOnInit() {
//this.tooltip.Content = this.Content
}
}