tabview.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. "use strict";
  2. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  3. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  4. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  5. 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;
  6. return c > 3 && r && Object.defineProperty(target, key, r), r;
  7. };
  8. var __metadata = (this && this.__metadata) || function (k, v) {
  9. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
  10. };
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. var core_1 = require("@angular/core");
  13. var common_1 = require("@angular/common");
  14. var tooltip_1 = require("../tooltip/tooltip");
  15. var shared_1 = require("../common/shared");
  16. var idx = 0;
  17. var TabViewNav = /** @class */ (function () {
  18. function TabViewNav() {
  19. this.orientation = 'top';
  20. this.onTabClick = new core_1.EventEmitter();
  21. this.onTabCloseClick = new core_1.EventEmitter();
  22. }
  23. TabViewNav.prototype.getDefaultHeaderClass = function (tab) {
  24. var styleClass = 'ui-state-default ui-corner-' + this.orientation;
  25. if (tab.headerStyleClass) {
  26. styleClass = styleClass + " " + tab.headerStyleClass;
  27. }
  28. return styleClass;
  29. };
  30. TabViewNav.prototype.clickTab = function (event, tab) {
  31. this.onTabClick.emit({
  32. originalEvent: event,
  33. tab: tab
  34. });
  35. };
  36. TabViewNav.prototype.clickClose = function (event, tab) {
  37. this.onTabCloseClick.emit({
  38. originalEvent: event,
  39. tab: tab
  40. });
  41. };
  42. __decorate([
  43. core_1.Input(),
  44. __metadata("design:type", Array)
  45. ], TabViewNav.prototype, "tabs", void 0);
  46. __decorate([
  47. core_1.Input(),
  48. __metadata("design:type", String)
  49. ], TabViewNav.prototype, "orientation", void 0);
  50. __decorate([
  51. core_1.Output(),
  52. __metadata("design:type", core_1.EventEmitter)
  53. ], TabViewNav.prototype, "onTabClick", void 0);
  54. __decorate([
  55. core_1.Output(),
  56. __metadata("design:type", core_1.EventEmitter)
  57. ], TabViewNav.prototype, "onTabCloseClick", void 0);
  58. TabViewNav = __decorate([
  59. core_1.Component({
  60. selector: '[p-tabViewNav]',
  61. host: {
  62. '[class.ui-tabview-nav]': 'true',
  63. '[class.ui-helper-reset]': 'true',
  64. '[class.ui-helper-clearfix]': 'true',
  65. '[class.ui-widget-header]': 'true',
  66. '[class.ui-corner-all]': 'true'
  67. },
  68. template: "\n <ng-template ngFor let-tab [ngForOf]=\"tabs\">\n <li [class]=\"getDefaultHeaderClass(tab)\" [ngStyle]=\"tab.headerStyle\" role=\"presentation\"\n [ngClass]=\"{'ui-tabview-selected ui-state-active': tab.selected, 'ui-state-disabled': tab.disabled}\"\n (click)=\"clickTab($event,tab)\" *ngIf=\"!tab.closed\" tabindex=\"0\" (keydown.enter)=\"clickTab($event,tab)\">\n <a [attr.id]=\"tab.id + '-label'\" role=\"tab\" [attr.aria-selected]=\"tab.selected\" [attr.aria-controls]=\"tab.id\" [pTooltip]=\"tab.tooltip\" [tooltipPosition]=\"tab.tooltipPosition\" [positionStyle]=\"tab.tooltipPositionStyle\" [tooltipStyleClass]=\"tab.tooltipStyleClass\">\n <ng-container *ngIf=\"!tab.headerTemplate\" >\n <span class=\"ui-tabview-left-icon\" [ngClass]=\"tab.leftIcon\" *ngIf=\"tab.leftIcon\"></span>\n <span class=\"ui-tabview-title\">{{tab.header}}</span>\n <span class=\"ui-tabview-right-icon\" [ngClass]=\"tab.rightIcon\" *ngIf=\"tab.rightIcon\"></span>\n </ng-container>\n <ng-container *ngIf=\"tab.headerTemplate\">\n <ng-container *ngTemplateOutlet=\"tab.headerTemplate\"></ng-container>\n </ng-container>\n </a>\n <span *ngIf=\"tab.closable\" class=\"ui-tabview-close pi pi-times\" (click)=\"clickClose($event,tab)\"></span>\n </li>\n </ng-template>\n ",
  69. })
  70. ], TabViewNav);
  71. return TabViewNav;
  72. }());
  73. exports.TabViewNav = TabViewNav;
  74. var TabPanel = /** @class */ (function () {
  75. function TabPanel(viewContainer) {
  76. this.viewContainer = viewContainer;
  77. this.cache = true;
  78. this.tooltipPosition = 'top';
  79. this.tooltipPositionStyle = 'absolute';
  80. this.id = "ui-tabpanel-" + idx++;
  81. }
  82. TabPanel.prototype.ngAfterContentInit = function () {
  83. var _this = this;
  84. this.templates.forEach(function (item) {
  85. switch (item.getType()) {
  86. case 'header':
  87. _this.headerTemplate = item.template;
  88. break;
  89. case 'content':
  90. _this.contentTemplate = item.template;
  91. break;
  92. default:
  93. _this.contentTemplate = item.template;
  94. break;
  95. }
  96. });
  97. };
  98. Object.defineProperty(TabPanel.prototype, "selected", {
  99. get: function () {
  100. return this._selected;
  101. },
  102. set: function (val) {
  103. this._selected = val;
  104. this.loaded = true;
  105. },
  106. enumerable: true,
  107. configurable: true
  108. });
  109. TabPanel.prototype.ngOnDestroy = function () {
  110. this.view = null;
  111. };
  112. __decorate([
  113. core_1.Input(),
  114. __metadata("design:type", String)
  115. ], TabPanel.prototype, "header", void 0);
  116. __decorate([
  117. core_1.Input(),
  118. __metadata("design:type", Boolean)
  119. ], TabPanel.prototype, "disabled", void 0);
  120. __decorate([
  121. core_1.Input(),
  122. __metadata("design:type", Boolean)
  123. ], TabPanel.prototype, "closable", void 0);
  124. __decorate([
  125. core_1.Input(),
  126. __metadata("design:type", Object)
  127. ], TabPanel.prototype, "headerStyle", void 0);
  128. __decorate([
  129. core_1.Input(),
  130. __metadata("design:type", String)
  131. ], TabPanel.prototype, "headerStyleClass", void 0);
  132. __decorate([
  133. core_1.Input(),
  134. __metadata("design:type", String)
  135. ], TabPanel.prototype, "leftIcon", void 0);
  136. __decorate([
  137. core_1.Input(),
  138. __metadata("design:type", String)
  139. ], TabPanel.prototype, "rightIcon", void 0);
  140. __decorate([
  141. core_1.Input(),
  142. __metadata("design:type", Boolean)
  143. ], TabPanel.prototype, "cache", void 0);
  144. __decorate([
  145. core_1.Input(),
  146. __metadata("design:type", Object)
  147. ], TabPanel.prototype, "tooltip", void 0);
  148. __decorate([
  149. core_1.Input(),
  150. __metadata("design:type", String)
  151. ], TabPanel.prototype, "tooltipPosition", void 0);
  152. __decorate([
  153. core_1.Input(),
  154. __metadata("design:type", String)
  155. ], TabPanel.prototype, "tooltipPositionStyle", void 0);
  156. __decorate([
  157. core_1.Input(),
  158. __metadata("design:type", String)
  159. ], TabPanel.prototype, "tooltipStyleClass", void 0);
  160. __decorate([
  161. core_1.ContentChildren(shared_1.PrimeTemplate),
  162. __metadata("design:type", core_1.QueryList)
  163. ], TabPanel.prototype, "templates", void 0);
  164. __decorate([
  165. core_1.Input(),
  166. __metadata("design:type", Boolean),
  167. __metadata("design:paramtypes", [Boolean])
  168. ], TabPanel.prototype, "selected", null);
  169. TabPanel = __decorate([
  170. core_1.Component({
  171. selector: 'p-tabPanel',
  172. template: "\n <div [attr.id]=\"id\" class=\"ui-tabview-panel ui-widget-content\" [ngClass]=\"{'ui-helper-hidden': !selected}\"\n role=\"tabpanel\" [attr.aria-hidden]=\"!selected\" [attr.aria-labelledby]=\"id + '-label'\" *ngIf=\"!closed\">\n <ng-content></ng-content>\n <ng-container *ngIf=\"contentTemplate && (cache ? loaded : selected)\">\n <ng-container *ngTemplateOutlet=\"contentTemplate\"></ng-container>\n </ng-container>\n </div>\n "
  173. }),
  174. __metadata("design:paramtypes", [core_1.ViewContainerRef])
  175. ], TabPanel);
  176. return TabPanel;
  177. }());
  178. exports.TabPanel = TabPanel;
  179. var TabView = /** @class */ (function () {
  180. function TabView(el) {
  181. this.el = el;
  182. this.orientation = 'top';
  183. this.onChange = new core_1.EventEmitter();
  184. this.onClose = new core_1.EventEmitter();
  185. this.activeIndexChange = new core_1.EventEmitter();
  186. }
  187. TabView.prototype.ngAfterContentInit = function () {
  188. var _this = this;
  189. this.initTabs();
  190. this.tabPanels.changes.subscribe(function (_) {
  191. _this.initTabs();
  192. });
  193. };
  194. TabView.prototype.initTabs = function () {
  195. this.tabs = this.tabPanels.toArray();
  196. var selectedTab = this.findSelectedTab();
  197. if (!selectedTab && this.tabs.length) {
  198. if (this.activeIndex != null && this.tabs.length > this.activeIndex)
  199. this.tabs[this.activeIndex].selected = true;
  200. else
  201. this.tabs[0].selected = true;
  202. }
  203. };
  204. TabView.prototype.open = function (event, tab) {
  205. if (tab.disabled) {
  206. if (event) {
  207. event.preventDefault();
  208. }
  209. return;
  210. }
  211. if (!tab.selected) {
  212. var selectedTab = this.findSelectedTab();
  213. if (selectedTab) {
  214. selectedTab.selected = false;
  215. }
  216. tab.selected = true;
  217. var selectedTabIndex = this.findTabIndex(tab);
  218. this.preventActiveIndexPropagation = true;
  219. this.activeIndexChange.emit(selectedTabIndex);
  220. this.onChange.emit({ originalEvent: event, index: selectedTabIndex });
  221. }
  222. if (event) {
  223. event.preventDefault();
  224. }
  225. };
  226. TabView.prototype.close = function (event, tab) {
  227. var _this = this;
  228. if (this.controlClose) {
  229. this.onClose.emit({
  230. originalEvent: event,
  231. index: this.findTabIndex(tab),
  232. close: function () {
  233. _this.closeTab(tab);
  234. }
  235. });
  236. }
  237. else {
  238. this.closeTab(tab);
  239. this.onClose.emit({
  240. originalEvent: event,
  241. index: this.findTabIndex(tab)
  242. });
  243. }
  244. event.stopPropagation();
  245. };
  246. TabView.prototype.closeTab = function (tab) {
  247. if (tab.disabled) {
  248. return;
  249. }
  250. if (tab.selected) {
  251. tab.selected = false;
  252. for (var i = 0; i < this.tabs.length; i++) {
  253. var tabPanel = this.tabs[i];
  254. if (!tabPanel.closed && !tab.disabled) {
  255. tabPanel.selected = true;
  256. break;
  257. }
  258. }
  259. }
  260. tab.closed = true;
  261. };
  262. TabView.prototype.findSelectedTab = function () {
  263. for (var i = 0; i < this.tabs.length; i++) {
  264. if (this.tabs[i].selected) {
  265. return this.tabs[i];
  266. }
  267. }
  268. return null;
  269. };
  270. TabView.prototype.findTabIndex = function (tab) {
  271. var index = -1;
  272. for (var i = 0; i < this.tabs.length; i++) {
  273. if (this.tabs[i] == tab) {
  274. index = i;
  275. break;
  276. }
  277. }
  278. return index;
  279. };
  280. TabView.prototype.getBlockableElement = function () {
  281. return this.el.nativeElement.children[0];
  282. };
  283. Object.defineProperty(TabView.prototype, "activeIndex", {
  284. get: function () {
  285. return this._activeIndex;
  286. },
  287. set: function (val) {
  288. this._activeIndex = val;
  289. if (this.preventActiveIndexPropagation) {
  290. this.preventActiveIndexPropagation = false;
  291. return;
  292. }
  293. if (this.tabs && this.tabs.length && this._activeIndex != null && this.tabs.length > this._activeIndex) {
  294. this.findSelectedTab().selected = false;
  295. this.tabs[this._activeIndex].selected = true;
  296. }
  297. },
  298. enumerable: true,
  299. configurable: true
  300. });
  301. __decorate([
  302. core_1.Input(),
  303. __metadata("design:type", String)
  304. ], TabView.prototype, "orientation", void 0);
  305. __decorate([
  306. core_1.Input(),
  307. __metadata("design:type", Object)
  308. ], TabView.prototype, "style", void 0);
  309. __decorate([
  310. core_1.Input(),
  311. __metadata("design:type", String)
  312. ], TabView.prototype, "styleClass", void 0);
  313. __decorate([
  314. core_1.Input(),
  315. __metadata("design:type", Boolean)
  316. ], TabView.prototype, "controlClose", void 0);
  317. __decorate([
  318. core_1.ContentChildren(TabPanel),
  319. __metadata("design:type", core_1.QueryList)
  320. ], TabView.prototype, "tabPanels", void 0);
  321. __decorate([
  322. core_1.Output(),
  323. __metadata("design:type", core_1.EventEmitter)
  324. ], TabView.prototype, "onChange", void 0);
  325. __decorate([
  326. core_1.Output(),
  327. __metadata("design:type", core_1.EventEmitter)
  328. ], TabView.prototype, "onClose", void 0);
  329. __decorate([
  330. core_1.Output(),
  331. __metadata("design:type", core_1.EventEmitter)
  332. ], TabView.prototype, "activeIndexChange", void 0);
  333. __decorate([
  334. core_1.Input(),
  335. __metadata("design:type", Number),
  336. __metadata("design:paramtypes", [Number])
  337. ], TabView.prototype, "activeIndex", null);
  338. TabView = __decorate([
  339. core_1.Component({
  340. selector: 'p-tabView',
  341. template: "\n <div [ngClass]=\"'ui-tabview ui-widget ui-widget-content ui-corner-all ui-tabview-' + orientation\" [ngStyle]=\"style\" [class]=\"styleClass\">\n <ul p-tabViewNav role=\"tablist\" *ngIf=\"orientation!='bottom'\" [tabs]=\"tabs\" [orientation]=\"orientation\"\n (onTabClick)=\"open($event.originalEvent, $event.tab)\" (onTabCloseClick)=\"close($event.originalEvent, $event.tab)\"></ul>\n <div class=\"ui-tabview-panels\">\n <ng-content></ng-content>\n </div>\n <ul p-tabViewNav role=\"tablist\" *ngIf=\"orientation=='bottom'\" [tabs]=\"tabs\" [orientation]=\"orientation\"\n (onTabClick)=\"open($event.originalEvent, $event.tab)\" (onTabCloseClick)=\"close($event.originalEvent, $event.tab)\"></ul>\n </div>\n ",
  342. }),
  343. __metadata("design:paramtypes", [core_1.ElementRef])
  344. ], TabView);
  345. return TabView;
  346. }());
  347. exports.TabView = TabView;
  348. var TabViewModule = /** @class */ (function () {
  349. function TabViewModule() {
  350. }
  351. TabViewModule = __decorate([
  352. core_1.NgModule({
  353. imports: [common_1.CommonModule, shared_1.SharedModule, tooltip_1.TooltipModule],
  354. exports: [TabView, TabPanel, TabViewNav, shared_1.SharedModule],
  355. declarations: [TabView, TabPanel, TabViewNav]
  356. })
  357. ], TabViewModule);
  358. return TabViewModule;
  359. }());
  360. exports.TabViewModule = TabViewModule;
  361. //# sourceMappingURL=tabview.js.map