Files
agent/shared/src/directives/tooltip/tooltip.directive.ts
Róbert Kiss ce55cac380 fix(keymap): Add tooltips to action icons (#366)
* fix(keymap): Add tooltips to action icons

* fix(keymap): Remove console.log write

* feat(tooltip): New design of the tooltip

* feat(keymap): Show the tooltip of "Long press action" downward

* style(tooltip): Fix linting issues
2017-07-19 23:27:25 +02:00

46 lines
1.2 KiB
TypeScript

import { AfterContentInit, Directive, ElementRef, HostBinding, Input, OnChanges, Renderer2, SimpleChanges } from '@angular/core';
@Directive({
selector: '[data-toggle="tooltip"]'
})
export class TooltipDirective implements AfterContentInit, OnChanges {
@HostBinding('attr.data-placement') placement: string;
@Input('title') title: string;
@Input('html') html: boolean;
private customTooltipTemplate = `
<div class="tooltip">
<div class="tooltip-arrow"></div>
<div class="tooltip-inner"></div>
</div>
`;
constructor(private elementRef: ElementRef, private renderer: Renderer2) { }
ngAfterContentInit() {
this.init();
}
public ngOnChanges(changes: SimpleChanges): void {
if (changes['title']) {
this.fixTitle();
}
}
private init() {
jQuery(this.elementRef.nativeElement).tooltip({
placement: this.placement,
html: this.html,
template: this.customTooltipTemplate,
title: this.title
});
}
private fixTitle() {
jQuery(this.elementRef.nativeElement)
.attr('title', this.title)
.tooltip('fixTitle');
}
}