-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
… changed directive to component
- Loading branch information
1 parent
71c4b02
commit 0b6be11
Showing
8 changed files
with
98 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import {Ng2TooltipDirective} from "./ng2-tooltip-directive"; | ||
import {Ng2TooltipComponent} from "./ng2-tooltip-component"; | ||
import {Ng2TooltipOverlayModule} from './ng2-tooltip-overlay.module'; | ||
|
||
export { Ng2TooltipDirective, Ng2TooltipOverlayModule }; | ||
|
||
export { Ng2TooltipComponent, Ng2TooltipOverlayModule }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { | ||
Component, | ||
ViewContainerRef, | ||
Input, | ||
ViewEncapsulation | ||
} from '@angular/core'; | ||
|
||
import {Ng2OverlayManager, Ng2Overlay} from 'ng2-overlay'; | ||
|
||
@Component({ | ||
selector: '[ng2-tooltip]', | ||
template: '<ng-content></ng-content>', | ||
host: { | ||
'(mouseover)': 'showTooltip($event)', | ||
'(mouseout)': 'hideTooltip($event)' | ||
}, | ||
styles: [` | ||
ng2-tooltip .tooltip-contents { | ||
border: 1px solid #ccc; padding: 5px | ||
} | ||
ng2-tooltip .tooltip-down-arrow { | ||
height: 10px; | ||
} | ||
ng2-tooltip .tooltip-down-arrow:before { | ||
content: ''; | ||
display: block; | ||
position: absolute; | ||
width: 10px; | ||
height: 10px; | ||
left: 45%; | ||
bottom: 5px; | ||
background: #FFFFFF; | ||
border-left:1px solid #ccc; | ||
border-bottom:1px solid #ccc; | ||
transform:rotate(-45deg); | ||
} | ||
`], | ||
encapsulation: ViewEncapsulation.None | ||
}) | ||
export class Ng2TooltipComponent { | ||
|
||
@Input('ng2-tooltip') tooltip: string; | ||
|
||
el: HTMLElement; | ||
ng2Overlay: Ng2Overlay; | ||
|
||
constructor( | ||
public viewContainerRef: ViewContainerRef, | ||
public ng2OverlayManager: Ng2OverlayManager | ||
) { | ||
this.el = this.viewContainerRef.element.nativeElement; | ||
} | ||
|
||
ngAfterViewInit(): void { | ||
this.ng2Overlay = this.getTooltipOverlay(this.el, this.tooltip); | ||
} | ||
|
||
showTooltip($event) { | ||
this.ng2OverlayManager.open(this.ng2Overlay, $event); | ||
$event.stopPropagation(); | ||
} | ||
|
||
hideTooltip($event) { | ||
this.ng2OverlayManager.close(this.ng2Overlay); | ||
$event.stopPropagation(); | ||
} | ||
|
||
getTooltipOverlay(el, tooltip) { | ||
let tooltipEl = document.createElement('ng2-tooltip'); | ||
tooltipEl.style.display = 'none'; | ||
let divEl = document.createElement('div'); | ||
divEl.innerHTML = ` | ||
<div class='tooltip-contents'>${tooltip}</div> | ||
<div class='tooltip-down-arrow'></div> | ||
`; | ||
tooltipEl.appendChild(divEl); | ||
|
||
//el.parentElement.insertBefore(tooltipEl, el.nextSibling); | ||
el.appendChild(tooltipEl); | ||
|
||
let ng2Overlay = new Ng2Overlay(tooltipEl, { | ||
id: 'tooltip-' + (el.id || Math.floor(Math.random()*1000000)), | ||
position: 'top cursor outside' | ||
}); | ||
this.ng2OverlayManager.register(ng2Overlay); | ||
return ng2Overlay; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters