panelmenu.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  16. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  17. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  18. 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;
  19. return c > 3 && r && Object.defineProperty(target, key, r), r;
  20. };
  21. var __metadata = (this && this.__metadata) || function (k, v) {
  22. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. var core_1 = require("@angular/core");
  26. var animations_1 = require("@angular/animations");
  27. var common_1 = require("@angular/common");
  28. var router_1 = require("@angular/router");
  29. var BasePanelMenuItem = /** @class */ (function () {
  30. function BasePanelMenuItem(ref) {
  31. this.ref = ref;
  32. }
  33. BasePanelMenuItem.prototype.handleClick = function (event, item) {
  34. if (item.disabled) {
  35. event.preventDefault();
  36. return;
  37. }
  38. item.expanded = !item.expanded;
  39. this.ref.detectChanges();
  40. if (!item.url) {
  41. event.preventDefault();
  42. }
  43. if (item.command) {
  44. item.command({
  45. originalEvent: event,
  46. item: item
  47. });
  48. }
  49. };
  50. return BasePanelMenuItem;
  51. }());
  52. exports.BasePanelMenuItem = BasePanelMenuItem;
  53. var PanelMenuSub = /** @class */ (function (_super) {
  54. __extends(PanelMenuSub, _super);
  55. function PanelMenuSub(ref) {
  56. return _super.call(this, ref) || this;
  57. }
  58. __decorate([
  59. core_1.Input(),
  60. __metadata("design:type", Object)
  61. ], PanelMenuSub.prototype, "item", void 0);
  62. __decorate([
  63. core_1.Input(),
  64. __metadata("design:type", Boolean)
  65. ], PanelMenuSub.prototype, "expanded", void 0);
  66. __decorate([
  67. core_1.Input(),
  68. __metadata("design:type", String)
  69. ], PanelMenuSub.prototype, "transitionOptions", void 0);
  70. PanelMenuSub = __decorate([
  71. core_1.Component({
  72. selector: 'p-panelMenuSub',
  73. template: "\n <ul class=\"ui-submenu-list\" [@submenu]=\"expanded ? {value: 'visible', params: {transitionParams: transitionOptions, height: '*'}} : {value: 'hidden', params: {transitionParams: transitionOptions, height: '0'}}\">\n <ng-template ngFor let-child [ngForOf]=\"item.items\">\n <li *ngIf=\"child.separator\" class=\"ui-menu-separator ui-widget-content\">\n <li *ngIf=\"!child.separator\" class=\"ui-menuitem ui-corner-all\" [ngClass]=\"child.styleClass\" [class.ui-helper-hidden]=\"child.visible === false\" [ngStyle]=\"child.style\">\n <a *ngIf=\"!child.routerLink\" [href]=\"child.url||'#'\" class=\"ui-menuitem-link ui-corner-all\" [attr.tabindex]=\"item.expanded ? null : child.tabindex ? child.tabindex : '-1'\" [attr.id]=\"child.id\"\n [ngClass]=\"{'ui-state-disabled':child.disabled, 'ui-state-active': child.expanded}\" \n (click)=\"handleClick($event,child)\" [attr.target]=\"child.target\" [attr.title]=\"child.title\">\n <span class=\"ui-panelmenu-icon pi pi-fw\" [ngClass]=\"{'pi-caret-right':!child.expanded,'pi-caret-down':child.expanded}\" *ngIf=\"child.items\"></span\n ><span class=\"ui-menuitem-icon\" [ngClass]=\"child.icon\" *ngIf=\"child.icon\"></span\n ><span class=\"ui-menuitem-text\">{{child.label}}</span>\n </a>\n <a *ngIf=\"child.routerLink\" [routerLink]=\"child.routerLink\" [queryParams]=\"child.queryParams\" [routerLinkActive]=\"'ui-state-active'\" [routerLinkActiveOptions]=\"child.routerLinkActiveOptions||{exact:false}\" class=\"ui-menuitem-link ui-corner-all\" \n [ngClass]=\"{'ui-state-disabled':child.disabled}\" [attr.tabindex]=\"item.expanded ? null : child.tabindex ? child.tabindex : '-1'\" [attr.id]=\"child.id\"\n (click)=\"handleClick($event,child)\" [attr.target]=\"child.target\" [attr.title]=\"child.title\">\n <span class=\"ui-panelmenu-icon pi pi-fw\" [ngClass]=\"{'pi-caret-right':!child.expanded,'pi-caret-down':child.expanded}\" *ngIf=\"child.items\"></span\n ><span class=\"ui-menuitem-icon\" [ngClass]=\"child.icon\" *ngIf=\"child.icon\"></span\n ><span class=\"ui-menuitem-text\">{{child.label}}</span>\n </a>\n <p-panelMenuSub [item]=\"child\" [expanded]=\"child.expanded\" [transitionOptions]=\"transitionOptions\" *ngIf=\"child.items\"></p-panelMenuSub>\n </li>\n </ng-template>\n </ul>\n ",
  74. animations: [
  75. animations_1.trigger('submenu', [
  76. animations_1.state('hidden', animations_1.style({
  77. height: '0px'
  78. })),
  79. animations_1.state('void', animations_1.style({
  80. height: '{{height}}'
  81. }), { params: { height: '0' } }),
  82. animations_1.state('visible', animations_1.style({
  83. height: '*'
  84. })),
  85. animations_1.transition('visible => hidden', animations_1.animate('{{transitionParams}}')),
  86. animations_1.transition('hidden => visible', animations_1.animate('{{transitionParams}}')),
  87. animations_1.transition('void => hidden', animations_1.animate('{{transitionParams}}')),
  88. animations_1.transition('void => visible', animations_1.animate('{{transitionParams}}'))
  89. ])
  90. ]
  91. }),
  92. __metadata("design:paramtypes", [core_1.ChangeDetectorRef])
  93. ], PanelMenuSub);
  94. return PanelMenuSub;
  95. }(BasePanelMenuItem));
  96. exports.PanelMenuSub = PanelMenuSub;
  97. var PanelMenu = /** @class */ (function (_super) {
  98. __extends(PanelMenu, _super);
  99. function PanelMenu(ref) {
  100. var _this = _super.call(this, ref) || this;
  101. _this.multiple = true;
  102. _this.transitionOptions = '400ms cubic-bezier(0.86, 0, 0.07, 1)';
  103. return _this;
  104. }
  105. PanelMenu.prototype.collapseAll = function () {
  106. for (var _i = 0, _a = this.model; _i < _a.length; _i++) {
  107. var item = _a[_i];
  108. if (item.expanded) {
  109. item.expanded = false;
  110. }
  111. }
  112. };
  113. PanelMenu.prototype.handleClick = function (event, item) {
  114. if (!this.multiple) {
  115. for (var _i = 0, _a = this.model; _i < _a.length; _i++) {
  116. var modelItem = _a[_i];
  117. if (item !== modelItem && modelItem.expanded) {
  118. modelItem.expanded = false;
  119. }
  120. }
  121. }
  122. this.animating = true;
  123. _super.prototype.handleClick.call(this, event, item);
  124. };
  125. PanelMenu.prototype.onToggleDone = function () {
  126. this.animating = false;
  127. };
  128. __decorate([
  129. core_1.Input(),
  130. __metadata("design:type", Array)
  131. ], PanelMenu.prototype, "model", void 0);
  132. __decorate([
  133. core_1.Input(),
  134. __metadata("design:type", Object)
  135. ], PanelMenu.prototype, "style", void 0);
  136. __decorate([
  137. core_1.Input(),
  138. __metadata("design:type", String)
  139. ], PanelMenu.prototype, "styleClass", void 0);
  140. __decorate([
  141. core_1.Input(),
  142. __metadata("design:type", Boolean)
  143. ], PanelMenu.prototype, "multiple", void 0);
  144. __decorate([
  145. core_1.Input(),
  146. __metadata("design:type", String)
  147. ], PanelMenu.prototype, "transitionOptions", void 0);
  148. PanelMenu = __decorate([
  149. core_1.Component({
  150. selector: 'p-panelMenu',
  151. template: "\n <div [class]=\"styleClass\" [ngStyle]=\"style\" [ngClass]=\"'ui-panelmenu ui-widget'\">\n <ng-container *ngFor=\"let item of model;let f=first;let l=last;\">\n <div class=\"ui-panelmenu-panel\" [ngClass]=\"{'ui-helper-hidden': item.visible === false}\">\n <div [ngClass]=\"{'ui-widget ui-panelmenu-header ui-state-default':true,'ui-corner-top':f,'ui-corner-bottom':l&&!item.expanded,\n 'ui-state-active':item.expanded,'ui-state-disabled':item.disabled}\" [class]=\"item.styleClass\" [ngStyle]=\"item.style\">\n <a *ngIf=\"!item.routerLink\" [href]=\"item.url||'#'\" (click)=\"handleClick($event,item)\" [attr.tabindex]=\"item.tabindex ? item.tabindex : '0'\"\n [attr.target]=\"item.target\" [attr.title]=\"item.title\" class=\"ui-panelmenu-header-link\">\n <span *ngIf=\"item.items\" class=\"ui-panelmenu-icon pi pi-fw\" [ngClass]=\"{'pi-chevron-right':!item.expanded,'pi-chevron-down':item.expanded}\"></span\n ><span class=\"ui-menuitem-icon\" [ngClass]=\"item.icon\" *ngIf=\"item.icon\"></span\n ><span class=\"ui-menuitem-text\">{{item.label}}</span>\n </a>\n <a *ngIf=\"item.routerLink\" [routerLink]=\"item.routerLink\" [queryParams]=\"item.queryParams\" [routerLinkActive]=\"'ui-state-active'\" [routerLinkActiveOptions]=\"item.routerLinkActiveOptions||{exact:false}\"\n (click)=\"handleClick($event,item)\" [attr.target]=\"item.target\" [attr.title]=\"item.title\" class=\"ui-panelmenu-header-link\" [attr.id]=\"item.id\" [attr.tabindex]=\"item.tabindex ? item.tabindex : '0'\">\n <span *ngIf=\"item.items\" class=\"ui-panelmenu-icon pi pi-fw\" [ngClass]=\"{'pi-chevron-right':!item.expanded,'pi-chevron-down':item.expanded}\"></span\n ><span class=\"ui-menuitem-icon\" [ngClass]=\"item.icon\" *ngIf=\"item.icon\"></span\n ><span class=\"ui-menuitem-text\">{{item.label}}</span>\n </a>\n </div>\n <div *ngIf=\"item.items\" class=\"ui-panelmenu-content-wrapper\" [@rootItem]=\"item.expanded ? {value: 'visible', params: {transitionParams: animating ? transitionOptions : '0ms', height: '*'}} : {value: 'hidden', params: {transitionParams: transitionOptions, height: '0'}}\" (@rootItem.done)=\"onToggleDone()\"\n [ngClass]=\"{'ui-panelmenu-content-wrapper-overflown': !item.expanded||animating}\">\n <div class=\"ui-panelmenu-content ui-widget-content\">\n <p-panelMenuSub [item]=\"item\" [expanded]=\"true\" [transitionOptions]=\"transitionOptions\" class=\"ui-panelmenu-root-submenu\"></p-panelMenuSub>\n </div>\n </div>\n </div>\n </ng-container>\n </div>\n ",
  152. animations: [
  153. animations_1.trigger('rootItem', [
  154. animations_1.state('hidden', animations_1.style({
  155. height: '0px'
  156. })),
  157. animations_1.state('void', animations_1.style({
  158. height: '{{height}}'
  159. }), { params: { height: '0' } }),
  160. animations_1.state('visible', animations_1.style({
  161. height: '*'
  162. })),
  163. animations_1.transition('visible => hidden', animations_1.animate('{{transitionParams}}')),
  164. animations_1.transition('hidden => visible', animations_1.animate('{{transitionParams}}')),
  165. animations_1.transition('void => hidden', animations_1.animate('{{transitionParams}}')),
  166. animations_1.transition('void => visible', animations_1.animate('{{transitionParams}}'))
  167. ])
  168. ]
  169. }),
  170. __metadata("design:paramtypes", [core_1.ChangeDetectorRef])
  171. ], PanelMenu);
  172. return PanelMenu;
  173. }(BasePanelMenuItem));
  174. exports.PanelMenu = PanelMenu;
  175. var PanelMenuModule = /** @class */ (function () {
  176. function PanelMenuModule() {
  177. }
  178. PanelMenuModule = __decorate([
  179. core_1.NgModule({
  180. imports: [common_1.CommonModule, router_1.RouterModule],
  181. exports: [PanelMenu, router_1.RouterModule],
  182. declarations: [PanelMenu, PanelMenuSub]
  183. })
  184. ], PanelMenuModule);
  185. return PanelMenuModule;
  186. }());
  187. exports.PanelMenuModule = PanelMenuModule;
  188. //# sourceMappingURL=panelmenu.js.map