Skip to content
This repository has been archived by the owner on Nov 24, 2017. It is now read-only.

Fix AOT compile error #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 41 additions & 20 deletions src/Popover.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
import { Directive, HostListener, ComponentRef, ViewContainerRef, ComponentFactoryResolver, ComponentFactory, Input, OnChanges, SimpleChange, Output, EventEmitter } from "@angular/core";
import {
Directive,
HostListener,
ComponentRef,
ViewContainerRef,
ComponentFactoryResolver,
ComponentFactory,
Input,
OnChanges,
SimpleChange,
Output,
EventEmitter
} from "@angular/core";
import {PopoverContent} from "./PopoverContent";

@Directive({
Expand Down Expand Up @@ -28,67 +40,76 @@ export class Popover implements OnChanges {
// -------------------------------------------------------------------------

@Input("popover")
content: string|PopoverContent;
public content: string | PopoverContent;

@Input()
popoverDisabled: boolean;
public popoverDisabled: boolean;

@Input()
popoverAnimation: boolean;
public popoverAnimation: boolean;

@Input()
popoverPlacement: "top"|"bottom"|"left"|"right"|"auto"|"auto top"|"auto bottom"|"auto left"|"auto right";
public popoverPlacement:
"top"
| "bottom"
| "left"
| "right"
| "auto"
| "auto top"
| "auto bottom"
| "auto left"
| "auto right";

@Input()
popoverTitle: string;
public popoverTitle: string;

@Input()
popoverOnHover: boolean = false;
public popoverOnHover: boolean = false;

@Input()
popoverCloseOnClickOutside: boolean;
public popoverCloseOnClickOutside: boolean;

@Input()
popoverCloseOnMouseOutside: boolean;
public popoverCloseOnMouseOutside: boolean;

@Input()
popoverDismissTimeout: number = 0;
public popoverDismissTimeout: number = 0;

@Output()
onShown = new EventEmitter<Popover>();
public onShown = new EventEmitter<Popover>();

@Output()
onHidden = new EventEmitter<Popover>();
public onHidden = new EventEmitter<Popover>();

// -------------------------------------------------------------------------
// Event listeners
// -------------------------------------------------------------------------

@HostListener("click")
showOrHideOnClick(): void {
public showOrHideOnClick(): void {
if (this.popoverOnHover) return;
if (this.popoverDisabled) return;
this.toggle();
}

@HostListener("focusin")
@HostListener("mouseenter")
showOnHover(): void {
public showOnHover(): void {
if (!this.popoverOnHover) return;
if (this.popoverDisabled) return;
this.show();
}

@HostListener("focusout")
@HostListener("mouseleave")
hideOnHover(): void {
public hideOnHover(): void {
if (this.popoverCloseOnMouseOutside) return; // don't do anything since not we control this
if (!this.popoverOnHover) return;
if (this.popoverDisabled) return;
this.hide();
}

ngOnChanges(changes: {[propertyName: string]: SimpleChange}) {
ngOnChanges(changes: { [propertyName: string]: SimpleChange }) {
if (changes["popoverDisabled"]) {
if (changes["popoverDisabled"].currentValue) {
this.hide();
Expand All @@ -100,15 +121,15 @@ export class Popover implements OnChanges {
// Public Methods
// -------------------------------------------------------------------------

toggle() {
public toggle() {
if (!this.visible) {
this.show();
} else {
this.hide();
}
}

show() {
public show() {
if (this.visible) return;

this.visible = true;
Expand Down Expand Up @@ -160,7 +181,7 @@ export class Popover implements OnChanges {
this.onShown.emit(this);
}

hide() {
public hide() {
if (!this.visible) return;

this.visible = false;
Expand All @@ -173,7 +194,7 @@ export class Popover implements OnChanges {
this.onHidden.emit(this);
}

getElement() {
public getElement() {
return this.viewContainerRef.element.nativeElement;
}

Expand Down
128 changes: 76 additions & 52 deletions src/PopoverContent.ts
Original file line number Diff line number Diff line change
@@ -1,89 +1,112 @@
import {Component, Input, AfterViewInit, ElementRef, ChangeDetectorRef, OnDestroy, ViewChild, EventEmitter, Renderer } from "@angular/core";
import {
Component,
Input,
AfterViewInit,
ElementRef,
ChangeDetectorRef,
OnDestroy,
ViewChild,
EventEmitter,
Renderer
} from "@angular/core";
import {Popover} from "./Popover";

@Component({
selector: "popover-content",
template: `
<div #popoverDiv class="popover {{ effectivePlacement }}"
[style.top]="top + 'px'"
[style.left]="left + 'px'"
[class.in]="isIn"
[class.fade]="animation"
style="display: block"
role="popover">
<div [hidden]="!closeOnMouseOutside" class="virtual-area"></div>
<div class="arrow"></div>
<h3 class="popover-title" [hidden]="!title">{{ title }}</h3>
<div class="popover-content">
<div #popoverDiv class="popover {{ effectivePlacement }}"
[style.top]="top + 'px'"
[style.left]="left + 'px'"
[class.in]="isIn"
[class.fade]="animation"
style="display: block"
role="popover">
<div [hidden]="!closeOnMouseOutside" class="virtual-area"></div>
<div class="arrow"></div>
<h3 class="popover-title" [hidden]="!title">{{ title }}</h3>
<div class="popover-content">
<ng-content></ng-content>
{{ content }}
</div>
</div>
`,
</div>
</div>
`,
styles: [`
.popover .virtual-area {
height: 11px;
width: 100%;
position: absolute;
}
.popover.top .virtual-area {
bottom: -11px;
}
.popover.bottom .virtual-area {
top: -11px;
}
.popover.left .virtual-area {
right: -11px;
}
.popover.right .virtual-area {
left: -11px;
}
`]
.popover .virtual-area {
height: 11px;
width: 100%;
position: absolute;
}

.popover.top .virtual-area {
bottom: -11px;
}

.popover.bottom .virtual-area {
top: -11px;
}

.popover.left .virtual-area {
right: -11px;
}

.popover.right .virtual-area {
left: -11px;
}
`]
})
export class PopoverContent implements AfterViewInit, OnDestroy {

// -------------------------------------------------------------------------
// Inputs / Outputs
// Inputs / Outputs
// -------------------------------------------------------------------------

// @Input()
// hostElement: HTMLElement;

@Input()
content: string;
public content: string;

@Input()
placement: "top"|"bottom"|"left"|"right"|"auto"|"auto top"|"auto bottom"|"auto left"|"auto right" = "bottom";
public placement:
"top"
| "bottom"
| "left"
| "right"
| "auto"
| "auto top"
| "auto bottom"
| "auto left"
| "auto right" = "bottom";

@Input()
title: string;
public title: string;

@Input()
animation: boolean = true;
public animation: boolean = true;

@Input()
closeOnClickOutside: boolean = false;
public closeOnClickOutside: boolean = false;

@Input()
closeOnMouseOutside: boolean = false;
public closeOnMouseOutside: boolean = false;

// -------------------------------------------------------------------------
// Properties
// -------------------------------------------------------------------------

@ViewChild("popoverDiv")
popoverDiv: ElementRef;
public popoverDiv: ElementRef;

popover: Popover;
onCloseFromOutside = new EventEmitter();
top: number = -10000;
left: number = -10000;
isIn: boolean = false;
displayType: string = "none";
effectivePlacement: string;
public popover: Popover;
public onCloseFromOutside = new EventEmitter();
public top: number = -10000;
public left: number = -10000;
public isIn: boolean = false;
public displayType: string = "none";
public effectivePlacement: string;

// -------------------------------------------------------------------------
// Anonymous
// Anonymous
// -------------------------------------------------------------------------

/**
Expand Down Expand Up @@ -112,11 +135,12 @@ export class PopoverContent implements AfterViewInit, OnDestroy {

listenClickFunc: any;
listenMouseFunc: any;

ngAfterViewInit(): void {
if (this.closeOnClickOutside)
this.listenClickFunc = this.renderer.listenGlobal("document", "mousedown", (event: any) => this.onDocumentMouseDown(event));
this.listenClickFunc = this.renderer.listenGlobal("document", "mousedown", (event: any) => this.onDocumentMouseDown(event));
if (this.closeOnMouseOutside)
this.listenMouseFunc = this.renderer.listenGlobal("document", "mouseover", (event: any) => this.onDocumentMouseDown(event));
this.listenMouseFunc = this.renderer.listenGlobal("document", "mouseover", (event: any) => this.onDocumentMouseDown(event));

this.show();
this.cdr.detectChanges();
Expand Down Expand Up @@ -230,7 +254,7 @@ export class PopoverContent implements AfterViewInit, OnDestroy {
}

protected position(nativeEl: HTMLElement): { width: number, height: number, top: number, left: number } {
let offsetParentBCR = { top: 0, left: 0 };
let offsetParentBCR = {top: 0, left: 0};
const elBCR = this.offset(nativeEl);
const offsetParentEl = this.parentOffsetEl(nativeEl);
if (offsetParentEl !== window.document) {
Expand Down