Skip to content

Commit

Permalink
fix(tooltip): fix tooltip after upgrade to angular2 2.0.0-beta.12
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierceulemans committed Mar 27, 2016
1 parent 10181c0 commit 87a57f5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
50 changes: 26 additions & 24 deletions components/tooltip/tooltip-container.component.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,62 @@
import {
Component,
OnInit, Input, HostListener,
ElementRef, EventEmitter,
DynamicComponentLoader, ComponentRef, Inject, AfterViewChecked
ChangeDetectorRef,
ChangeDetectionStrategy,
ElementRef,
Inject, AfterViewChecked
} from 'angular2/core';
import {NgClass, NgStyle} from 'angular2/common';
import {positionService} from '../position';
import {TooltipOptions} from './tooltip-options.class';

@Component({
selector: 'tooltip-container',
directives: [NgClass, NgStyle],
template: `<div class="tooltip" role="tooltip"
[ngStyle]="{top: top, left: left, display: display}"
[ngClass]="classMap">
<div class="tooltip-arrow"></div>
<div class="tooltip-inner">
{{content}}
</div>
</div>`
</div>`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class TooltipContainer implements AfterViewChecked {
private classMap:any;
private positionMap:any;
private top:string;
private left:string;
private display:string;
private top:string = '-1000px';
private left:string = '-1000px';
private display:string = 'block';
private content:string;
private placement:string;
private appendToBody:boolean;

private popupClass:string;
private animation:boolean;
private isOpen:boolean;
private appendToBody:boolean;
private hostEl:ElementRef;

constructor(public element:ElementRef, @Inject(TooltipOptions) options:TooltipOptions) {
constructor(
private element:ElementRef,
private cdr:ChangeDetectorRef,
@Inject(TooltipOptions) options:TooltipOptions) {
Object.assign(this, options);
this.classMap = {'in': false};
this.classMap = {'in': false, 'fade': false};
this.classMap[options.placement] = true;
}

ngAfterViewChecked() {
if (this.hostEl !== null) {
setTimeout(() => {
let p = positionService
.positionElements(this.hostEl.nativeElement,
.positionElements(
this.hostEl.nativeElement,
this.element.nativeElement.children[0],
this.placement, this.appendToBody);
this.top = p.top + 'px';
this.left = p.left + 'px';
this.classMap['in'] = true;
}
}

public position(hostEl:ElementRef) {
this.display = 'block';
this.top = '-1000px';
this.left = '-1000px';
this.hostEl = hostEl;
this.classMap.in = true;
if (this.animation) {
this.classMap.fade = true;
}
this.cdr.markForCheck();
});
}
}
6 changes: 4 additions & 2 deletions components/tooltip/tooltip.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class Tooltip implements OnInit {
@Input('tooltipPlacement') public placement:string = 'top';
@Input('tooltipIsOpen') public isOpen:boolean;
@Input('tooltipEnable') public enable:boolean;
@Input('tooltipAnimation') public animation:boolean = true;
@Input('tooltipAppendToBody') public appendToBody:boolean;

private visible:boolean = false;
Expand All @@ -43,7 +44,9 @@ export class Tooltip implements OnInit {

let options = new TooltipOptions({
content: this.content,
placement: this.placement
placement: this.placement,
animation: this.animation,
hostEl: this.element
});

let binding = Injector.resolve([
Expand All @@ -53,7 +56,6 @@ export class Tooltip implements OnInit {
this.tooltip = this.loader
.loadNextToLocation(TooltipContainer, this.element, binding)
.then((componentRef:ComponentRef) => {
componentRef.instance.position(this.element);
return componentRef;
});
}
Expand Down

0 comments on commit 87a57f5

Please sign in to comment.