1 import {CommonModule} from '@angular/common';
2 import {AfterViewInit, Component, ElementRef, EventEmitter, Input, NgModule, OnDestroy, OnInit, Output, Renderer} from '@angular/core';
4 import {DomHandler} from '../domhandler';
7 selector: 'plx-overlay-panel',
9 <div [ngClass]="'ui-overlaypanel ui-widget ui-widget-content ui-corner-all ui-shadow'" [ngStyle]="style" [class]="styleClass"
10 [style.display]="visible ? 'block' : 'none'" (click)="onPanelClick()">
11 <div class="ui-overlaypanel-content">
12 <ng-content></ng-content>
14 <a href="#" *ngIf="showCloseIcon" class="ui-overlaypanel-close ui-state-default" (click)="onCloseClick($event)">
15 <span class="fa fa-fw fa-close"></span>
19 providers: [DomHandler]
21 export class PlxOverlayPanelComponent implements OnInit, AfterViewInit,
23 @Input() dismissable: boolean = true;
25 @Input() showCloseIcon: boolean;
29 @Input() styleClass: string;
31 @Input() appendTo: any;
33 @Output() onBeforeShow: EventEmitter<any> = new EventEmitter();
35 @Output() onAfterShow: EventEmitter<any> = new EventEmitter();
37 @Output() onBeforeHide: EventEmitter<any> = new EventEmitter();
39 @Output() onAfterHide: EventEmitter<any> = new EventEmitter();
43 visible: boolean = false;
45 documentClickListener: any;
54 public el: ElementRef, public domHandler: DomHandler,
55 public renderer: Renderer) {}
58 if (this.dismissable) {
59 this.documentClickListener =
60 this.renderer.listenGlobal('body', 'click', () => {
61 if (!this.selfClick && !this.targetEvent) {
64 this.selfClick = false;
65 this.targetEvent = false;
71 this.container = this.el.nativeElement.children[0];
73 if (this.appendTo === 'body') {
74 document.body.appendChild(this.container);
76 this.domHandler.appendChild(this.container, this.appendTo);
81 toggle(event: any, target?: any) {
82 let currentTarget = (target || event.currentTarget || event.target);
84 if (!this.target || this.target === currentTarget) {
88 this.show(event, target);
91 this.show(event, target);
94 if (this.dismissable) {
95 this.targetEvent = true;
98 this.target = currentTarget;
101 show(event: any, target?: any) {
102 if (this.dismissable) {
103 this.targetEvent = true;
106 this.onBeforeShow.emit(null);
107 let elementTarget = target || event.currentTarget || event.target;
108 this.container.style.zIndex = ++DomHandler.zindex;
111 this.domHandler.absolutePosition(this.container, elementTarget);
114 this.domHandler.absolutePosition(this.container, elementTarget);
115 this.domHandler.fadeIn(this.container, 250);
117 this.onAfterShow.emit(null);
122 this.onBeforeHide.emit(null);
123 this.visible = false;
124 this.onAfterHide.emit(null);
129 if (this.dismissable) {
130 this.selfClick = true;
134 onCloseClick(event: any) {
137 if (this.dismissable) {
138 this.selfClick = true;
141 event.preventDefault();
145 if (this.documentClickListener) {
146 this.documentClickListener();
150 this.el.nativeElement.appendChild(this.container);
158 imports: [CommonModule],
159 exports: [PlxOverlayPanelComponent],
160 declarations: [PlxOverlayPanelComponent]
162 export class PlxOverlayPanelModule {