UNPKG

primeng

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primeng.svg)](https://badge.fury.io/js/primeng) [![Build Status](https://travis-ci.org/primefaces/primeng.

266 lines (262 loc) 11.1 kB
import { EventEmitter, ElementRef, Renderer2, ChangeDetectorRef, NgZone, Input, Output, ContentChildren, Component, ChangeDetectionStrategy, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { DomHandler } from 'primeng/dom'; import { PrimeTemplate } from 'primeng/api'; import { trigger, state, style, transition, animate } from '@angular/animations'; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var OverlayPanel = /** @class */ (function () { function OverlayPanel(el, renderer, cd, zone) { this.el = el; this.renderer = renderer; this.cd = cd; this.zone = zone; this.dismissable = true; this.autoZIndex = true; this.baseZIndex = 0; this.showTransitionOptions = '225ms ease-out'; this.hideTransitionOptions = '195ms ease-in'; this.onShow = new EventEmitter(); this.onHide = new EventEmitter(); this.overlayVisible = false; this.render = false; this.isContainerClicked = true; } OverlayPanel.prototype.ngAfterContentInit = function () { var _this = this; this.templates.forEach(function (item) { switch (item.getType()) { case 'content': _this.contentTemplate = item.template; break; default: _this.contentTemplate = item.template; break; } }); }; OverlayPanel.prototype.onContainerClick = function () { this.isContainerClicked = true; }; OverlayPanel.prototype.bindDocumentClickListener = function () { var _this = this; if (!this.documentClickListener && this.dismissable) { this.zone.runOutsideAngular(function () { var documentEvent = DomHandler.isIOS() ? 'touchstart' : 'click'; _this.documentClickListener = _this.renderer.listen('document', documentEvent, function (event) { if (!_this.container.contains(event.target) && _this.target !== event.target && !_this.target.contains(event.target) && !_this.isContainerClicked) { _this.zone.run(function () { _this.hide(); }); } _this.isContainerClicked = false; _this.cd.markForCheck(); }); }); } }; OverlayPanel.prototype.unbindDocumentClickListener = function () { if (this.documentClickListener) { this.documentClickListener(); this.documentClickListener = null; } }; OverlayPanel.prototype.toggle = function (event, target) { var _this = this; if (this.overlayVisible) { if (this.hasTargetChanged(event, target)) { this.destroyCallback = function () { _this.show(null, (target || event.currentTarget || event.target)); }; } this.overlayVisible = false; } else { this.show(event, target); } }; OverlayPanel.prototype.show = function (event, target) { this.target = target || event.currentTarget || event.target; this.overlayVisible = true; this.render = true; }; OverlayPanel.prototype.hasTargetChanged = function (event, target) { return this.target != null && this.target !== (target || event.currentTarget || event.target); }; OverlayPanel.prototype.appendContainer = function () { if (this.appendTo) { if (this.appendTo === 'body') document.body.appendChild(this.container); else DomHandler.appendChild(this.container, this.appendTo); } }; OverlayPanel.prototype.restoreAppend = function () { if (this.container && this.appendTo) { this.el.nativeElement.appendChild(this.container); } }; OverlayPanel.prototype.align = function () { if (this.autoZIndex) { this.container.style.zIndex = String(this.baseZIndex + (++DomHandler.zindex)); } DomHandler.absolutePosition(this.container, this.target); if (DomHandler.getOffset(this.container).top < DomHandler.getOffset(this.target).top) { DomHandler.addClass(this.container, 'ui-overlaypanel-flipped'); } if (Math.floor(DomHandler.getOffset(this.container).left) < Math.floor(DomHandler.getOffset(this.target).left) && DomHandler.getOffset(this.container).left > 0) { DomHandler.addClass(this.container, 'ui-overlaypanel-shifted'); } }; OverlayPanel.prototype.onAnimationStart = function (event) { if (event.toState === 'open') { this.container = event.element; this.onShow.emit(null); this.appendContainer(); this.align(); this.bindDocumentClickListener(); this.bindDocumentResizeListener(); } }; OverlayPanel.prototype.onAnimationEnd = function (event) { switch (event.toState) { case 'void': if (this.destroyCallback) { this.destroyCallback(); this.destroyCallback = null; } break; case 'close': this.onContainerDestroy(); this.onHide.emit({}); this.render = false; break; } }; OverlayPanel.prototype.hide = function () { this.overlayVisible = false; }; OverlayPanel.prototype.onCloseClick = function (event) { this.hide(); event.preventDefault(); }; OverlayPanel.prototype.onWindowResize = function (event) { this.hide(); }; OverlayPanel.prototype.bindDocumentResizeListener = function () { this.documentResizeListener = this.onWindowResize.bind(this); window.addEventListener('resize', this.documentResizeListener); }; OverlayPanel.prototype.unbindDocumentResizeListener = function () { if (this.documentResizeListener) { window.removeEventListener('resize', this.documentResizeListener); this.documentResizeListener = null; } }; OverlayPanel.prototype.onContainerDestroy = function () { this.target = null; this.unbindDocumentClickListener(); this.unbindDocumentResizeListener(); }; OverlayPanel.prototype.ngOnDestroy = function () { this.target = null; this.destroyCallback = null; if (this.container) { this.restoreAppend(); this.onContainerDestroy(); } }; OverlayPanel.ctorParameters = function () { return [ { type: ElementRef }, { type: Renderer2 }, { type: ChangeDetectorRef }, { type: NgZone } ]; }; __decorate([ Input() ], OverlayPanel.prototype, "dismissable", void 0); __decorate([ Input() ], OverlayPanel.prototype, "showCloseIcon", void 0); __decorate([ Input() ], OverlayPanel.prototype, "style", void 0); __decorate([ Input() ], OverlayPanel.prototype, "styleClass", void 0); __decorate([ Input() ], OverlayPanel.prototype, "appendTo", void 0); __decorate([ Input() ], OverlayPanel.prototype, "autoZIndex", void 0); __decorate([ Input() ], OverlayPanel.prototype, "ariaCloseLabel", void 0); __decorate([ Input() ], OverlayPanel.prototype, "baseZIndex", void 0); __decorate([ Input() ], OverlayPanel.prototype, "showTransitionOptions", void 0); __decorate([ Input() ], OverlayPanel.prototype, "hideTransitionOptions", void 0); __decorate([ Output() ], OverlayPanel.prototype, "onShow", void 0); __decorate([ Output() ], OverlayPanel.prototype, "onHide", void 0); __decorate([ ContentChildren(PrimeTemplate) ], OverlayPanel.prototype, "templates", void 0); OverlayPanel = __decorate([ Component({ selector: 'p-overlayPanel', template: "\n <div *ngIf=\"render\" [ngClass]=\"'ui-overlaypanel ui-widget ui-widget-content ui-corner-all ui-shadow'\" [ngStyle]=\"style\" [class]=\"styleClass\" (click)=\"onContainerClick()\"\n [@animation]=\"{value: (overlayVisible ? 'open': 'close'), params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}\" \n (@animation.start)=\"onAnimationStart($event)\" (@animation.done)=\"onAnimationEnd($event)\">\n <div class=\"ui-overlaypanel-content\">\n <ng-content></ng-content>\n <ng-container *ngTemplateOutlet=\"contentTemplate\"></ng-container>\n </div>\n <a tabindex=\"0\" *ngIf=\"showCloseIcon\" class=\"ui-overlaypanel-close ui-state-default\" (click)=\"onCloseClick($event)\" (keydown.enter)=\"hide()\" [attr.aria-label]=\"ariaCloseLabel\">\n <span class=\"ui-overlaypanel-close-icon pi pi-times\"></span>\n </a>\n </div>\n ", animations: [ trigger('animation', [ state('void', style({ transform: 'translateY(5%)', opacity: 0 })), state('close', style({ transform: 'translateY(5%)', opacity: 0 })), state('open', style({ transform: 'translateY(0)', opacity: 1 })), transition('void => open', animate('{{showTransitionParams}}')), transition('open => close', animate('{{hideTransitionParams}}')) ]) ], changeDetection: ChangeDetectionStrategy.Default }) ], OverlayPanel); return OverlayPanel; }()); var OverlayPanelModule = /** @class */ (function () { function OverlayPanelModule() { } OverlayPanelModule = __decorate([ NgModule({ imports: [CommonModule], exports: [OverlayPanel], declarations: [OverlayPanel] }) ], OverlayPanelModule); return OverlayPanelModule; }()); /** * Generated bundle index. Do not edit. */ export { OverlayPanel, OverlayPanelModule }; //# sourceMappingURL=primeng-overlaypanel.js.map