UNPKG

11.6 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/animations'), require('@angular/common'), require('primeng/dom')) :
3 typeof define === 'function' && define.amd ? define('primeng/sidebar', ['exports', '@angular/core', '@angular/animations', '@angular/common', 'primeng/dom'], factory) :
4 (global = global || self, factory((global.primeng = global.primeng || {}, global.primeng.sidebar = {}), global.ng.core, global.ng.animations, global.ng.common, global.primeng.dom));
5}(this, (function (exports, core, animations, common, dom) { 'use strict';
6
7 var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
8 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
10 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;
11 return c > 3 && r && Object.defineProperty(target, key, r), r;
12 };
13 var Sidebar = /** @class */ (function () {
14 function Sidebar(el, renderer) {
15 this.el = el;
16 this.renderer = renderer;
17 this.position = 'left';
18 this.blockScroll = false;
19 this.autoZIndex = true;
20 this.baseZIndex = 0;
21 this.modal = true;
22 this.dismissible = true;
23 this.showCloseIcon = true;
24 this.closeOnEscape = true;
25 this.onShow = new core.EventEmitter();
26 this.onHide = new core.EventEmitter();
27 this.visibleChange = new core.EventEmitter();
28 }
29 Sidebar.prototype.ngAfterViewInit = function () {
30 this.initialized = true;
31 if (this.appendTo) {
32 if (this.appendTo === 'body')
33 document.body.appendChild(this.containerViewChild.nativeElement);
34 else
35 dom.DomHandler.appendChild(this.containerViewChild.nativeElement, this.appendTo);
36 }
37 if (this.visible) {
38 this.show();
39 }
40 };
41 Object.defineProperty(Sidebar.prototype, "visible", {
42 get: function () {
43 return this._visible;
44 },
45 set: function (val) {
46 this._visible = val;
47 if (this.initialized && this.containerViewChild && this.containerViewChild.nativeElement) {
48 if (this._visible)
49 this.show();
50 else {
51 if (this.preventVisibleChangePropagation)
52 this.preventVisibleChangePropagation = false;
53 else
54 this.hide();
55 }
56 }
57 },
58 enumerable: true,
59 configurable: true
60 });
61 Sidebar.prototype.ngAfterViewChecked = function () {
62 if (this.executePostDisplayActions) {
63 this.onShow.emit({});
64 this.executePostDisplayActions = false;
65 }
66 };
67 Sidebar.prototype.show = function () {
68 this.executePostDisplayActions = true;
69 if (this.autoZIndex) {
70 this.containerViewChild.nativeElement.style.zIndex = String(this.baseZIndex + (++dom.DomHandler.zindex));
71 }
72 if (this.modal) {
73 this.enableModality();
74 }
75 };
76 Sidebar.prototype.hide = function () {
77 this.onHide.emit({});
78 if (this.modal) {
79 this.disableModality();
80 }
81 };
82 Sidebar.prototype.close = function (event) {
83 this.preventVisibleChangePropagation = true;
84 this.hide();
85 this.visibleChange.emit(false);
86 event.preventDefault();
87 };
88 Sidebar.prototype.enableModality = function () {
89 var _this = this;
90 if (!this.mask) {
91 this.mask = document.createElement('div');
92 this.mask.style.zIndex = String(parseInt(this.containerViewChild.nativeElement.style.zIndex) - 1);
93 dom.DomHandler.addMultipleClasses(this.mask, 'ui-widget-overlay ui-sidebar-mask');
94 if (this.dismissible) {
95 this.maskClickListener = this.renderer.listen(this.mask, 'click', function (event) {
96 if (_this.dismissible) {
97 _this.close(event);
98 }
99 });
100 }
101 document.body.appendChild(this.mask);
102 if (this.blockScroll) {
103 dom.DomHandler.addClass(document.body, 'ui-overflow-hidden');
104 }
105 }
106 };
107 Sidebar.prototype.disableModality = function () {
108 if (this.mask) {
109 this.unbindMaskClickListener();
110 document.body.removeChild(this.mask);
111 if (this.blockScroll) {
112 dom.DomHandler.removeClass(document.body, 'ui-overflow-hidden');
113 }
114 this.mask = null;
115 }
116 };
117 Sidebar.prototype.onAnimationStart = function (event) {
118 switch (event.toState) {
119 case 'visible':
120 if (this.closeOnEscape) {
121 this.bindDocumentEscapeListener();
122 }
123 break;
124 case 'hidden':
125 this.unbindGlobalListeners();
126 break;
127 }
128 };
129 Sidebar.prototype.bindDocumentEscapeListener = function () {
130 var _this = this;
131 this.documentEscapeListener = this.renderer.listen('document', 'keydown', function (event) {
132 if (event.which == 27) {
133 if (parseInt(_this.containerViewChild.nativeElement.style.zIndex) === (dom.DomHandler.zindex + _this.baseZIndex)) {
134 _this.close(event);
135 }
136 }
137 });
138 };
139 Sidebar.prototype.unbindDocumentEscapeListener = function () {
140 if (this.documentEscapeListener) {
141 this.documentEscapeListener();
142 this.documentEscapeListener = null;
143 }
144 };
145 Sidebar.prototype.unbindMaskClickListener = function () {
146 if (this.maskClickListener) {
147 this.maskClickListener();
148 this.maskClickListener = null;
149 }
150 };
151 Sidebar.prototype.unbindGlobalListeners = function () {
152 this.unbindMaskClickListener();
153 this.unbindDocumentEscapeListener();
154 };
155 Sidebar.prototype.ngOnDestroy = function () {
156 this.initialized = false;
157 if (this.visible) {
158 this.hide();
159 }
160 if (this.appendTo) {
161 this.el.nativeElement.appendChild(this.containerViewChild.nativeElement);
162 }
163 this.unbindGlobalListeners();
164 };
165 Sidebar.ctorParameters = function () { return [
166 { type: core.ElementRef },
167 { type: core.Renderer2 }
168 ]; };
169 __decorate([
170 core.Input()
171 ], Sidebar.prototype, "position", void 0);
172 __decorate([
173 core.Input()
174 ], Sidebar.prototype, "fullScreen", void 0);
175 __decorate([
176 core.Input()
177 ], Sidebar.prototype, "appendTo", void 0);
178 __decorate([
179 core.Input()
180 ], Sidebar.prototype, "blockScroll", void 0);
181 __decorate([
182 core.Input()
183 ], Sidebar.prototype, "style", void 0);
184 __decorate([
185 core.Input()
186 ], Sidebar.prototype, "styleClass", void 0);
187 __decorate([
188 core.Input()
189 ], Sidebar.prototype, "ariaCloseLabel", void 0);
190 __decorate([
191 core.Input()
192 ], Sidebar.prototype, "autoZIndex", void 0);
193 __decorate([
194 core.Input()
195 ], Sidebar.prototype, "baseZIndex", void 0);
196 __decorate([
197 core.Input()
198 ], Sidebar.prototype, "modal", void 0);
199 __decorate([
200 core.Input()
201 ], Sidebar.prototype, "dismissible", void 0);
202 __decorate([
203 core.Input()
204 ], Sidebar.prototype, "showCloseIcon", void 0);
205 __decorate([
206 core.Input()
207 ], Sidebar.prototype, "closeOnEscape", void 0);
208 __decorate([
209 core.ViewChild('container')
210 ], Sidebar.prototype, "containerViewChild", void 0);
211 __decorate([
212 core.Output()
213 ], Sidebar.prototype, "onShow", void 0);
214 __decorate([
215 core.Output()
216 ], Sidebar.prototype, "onHide", void 0);
217 __decorate([
218 core.Output()
219 ], Sidebar.prototype, "visibleChange", void 0);
220 __decorate([
221 core.Input()
222 ], Sidebar.prototype, "visible", null);
223 Sidebar = __decorate([
224 core.Component({
225 selector: 'p-sidebar',
226 template: "\n <div #container [ngClass]=\"{'ui-sidebar ui-widget ui-widget-content ui-shadow':true, 'ui-sidebar-active': visible, \n 'ui-sidebar-left': (position === 'left'), 'ui-sidebar-right': (position === 'right'),\n 'ui-sidebar-top': (position === 'top'), 'ui-sidebar-bottom': (position === 'bottom'), \n 'ui-sidebar-full': fullScreen}\"\n [@panelState]=\"visible ? 'visible' : 'hidden'\" (@panelState.start)=\"onAnimationStart($event)\" [ngStyle]=\"style\" [class]=\"styleClass\" role=\"complementary\" [attr.aria-modal]=\"modal\">\n <a [ngClass]=\"{'ui-sidebar-close ui-corner-all':true}\" *ngIf=\"showCloseIcon\" tabindex=\"0\" role=\"button\" (click)=\"close($event)\" (keydown.enter)=\"close($event)\" [attr.aria-label]=\"ariaCloseLabel\">\n <span class=\"pi pi-times\"></span>\n </a>\n <ng-content></ng-content>\n </div>\n ",
227 animations: [
228 animations.trigger('panelState', [
229 animations.state('hidden', animations.style({
230 opacity: 0
231 })),
232 animations.state('visible', animations.style({
233 opacity: 1
234 })),
235 animations.transition('visible => hidden', animations.animate('300ms ease-in')),
236 animations.transition('hidden => visible', animations.animate('300ms ease-out'))
237 ])
238 ],
239 changeDetection: core.ChangeDetectionStrategy.Default
240 })
241 ], Sidebar);
242 return Sidebar;
243 }());
244 var SidebarModule = /** @class */ (function () {
245 function SidebarModule() {
246 }
247 SidebarModule = __decorate([
248 core.NgModule({
249 imports: [common.CommonModule],
250 exports: [Sidebar],
251 declarations: [Sidebar]
252 })
253 ], SidebarModule);
254 return SidebarModule;
255 }());
256
257 exports.Sidebar = Sidebar;
258 exports.SidebarModule = SidebarModule;
259
260 Object.defineProperty(exports, '__esModule', { value: true });
261
262})));
263//# sourceMappingURL=primeng-sidebar.umd.js.map