1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | "use strict";
|
8 | Object.defineProperty(exports, "__esModule", { value: true });
|
9 | var utils_1 = require("../utils");
|
10 | var TabbedLayout = (function () {
|
11 | function TabbedLayout(params) {
|
12 | var _this = this;
|
13 | this.items = [];
|
14 | this.params = params;
|
15 | this.eGui = document.createElement('div');
|
16 | this.eGui.innerHTML = TabbedLayout.TEMPLATE;
|
17 | this.eHeader = this.eGui.querySelector('[ref="tabHeader"]');
|
18 | this.eBody = this.eGui.querySelector('[ref="tabBody"]');
|
19 | utils_1.Utils.addCssClass(this.eGui, params.cssClass);
|
20 | if (params.items) {
|
21 | params.items.forEach(function (item) { return _this.addItem(item); });
|
22 | }
|
23 | }
|
24 | TabbedLayout.prototype.setAfterAttachedParams = function (params) {
|
25 | this.afterAttachedParams = params;
|
26 | };
|
27 | TabbedLayout.prototype.getMinWidth = function () {
|
28 | var eDummyContainer = document.createElement('span');
|
29 |
|
30 | eDummyContainer.style.position = 'fixed';
|
31 |
|
32 |
|
33 | this.eGui.appendChild(eDummyContainer);
|
34 | var minWidth = 0;
|
35 | this.items.forEach(function (itemWrapper) {
|
36 | utils_1.Utils.removeAllChildren(eDummyContainer);
|
37 | var eClone = itemWrapper.tabbedItem.bodyPromise.resolveNow(null, function (body) { return body.cloneNode(true); });
|
38 | if (eClone == null) {
|
39 | return;
|
40 | }
|
41 | eDummyContainer.appendChild(eClone);
|
42 | if (minWidth < eDummyContainer.offsetWidth) {
|
43 | minWidth = eDummyContainer.offsetWidth;
|
44 | }
|
45 | });
|
46 |
|
47 |
|
48 | if (minWidth < this.eGui.offsetWidth) {
|
49 | minWidth = this.eGui.offsetWidth;
|
50 | }
|
51 | this.eGui.removeChild(eDummyContainer);
|
52 | return minWidth;
|
53 | };
|
54 | TabbedLayout.prototype.showFirstItem = function () {
|
55 | if (this.items.length > 0) {
|
56 | this.showItemWrapper(this.items[0]);
|
57 | }
|
58 | };
|
59 | TabbedLayout.prototype.addItem = function (item) {
|
60 | var eHeaderButton = document.createElement('span');
|
61 | eHeaderButton.appendChild(item.title);
|
62 | utils_1.Utils.addCssClass(eHeaderButton, 'ag-tab');
|
63 | this.eHeader.appendChild(eHeaderButton);
|
64 | var wrapper = {
|
65 | tabbedItem: item,
|
66 | eHeaderButton: eHeaderButton
|
67 | };
|
68 | this.items.push(wrapper);
|
69 | eHeaderButton.addEventListener('click', this.showItemWrapper.bind(this, wrapper));
|
70 | };
|
71 | TabbedLayout.prototype.showItem = function (tabbedItem) {
|
72 | var itemWrapper = utils_1.Utils.find(this.items, function (itemWrapper) {
|
73 | return itemWrapper.tabbedItem === tabbedItem;
|
74 | });
|
75 | if (itemWrapper) {
|
76 | this.showItemWrapper(itemWrapper);
|
77 | }
|
78 | };
|
79 | TabbedLayout.prototype.showItemWrapper = function (wrapper) {
|
80 | var _this = this;
|
81 | if (this.params.onItemClicked) {
|
82 | this.params.onItemClicked({ item: wrapper.tabbedItem });
|
83 | }
|
84 | if (this.activeItem === wrapper) {
|
85 | utils_1.Utils.callIfPresent(this.params.onActiveItemClicked);
|
86 | return;
|
87 | }
|
88 | utils_1.Utils.removeAllChildren(this.eBody);
|
89 | wrapper.tabbedItem.bodyPromise.then(function (body) {
|
90 | _this.eBody.appendChild(body);
|
91 | });
|
92 | if (this.activeItem) {
|
93 | utils_1.Utils.removeCssClass(this.activeItem.eHeaderButton, 'ag-tab-selected');
|
94 | }
|
95 | utils_1.Utils.addCssClass(wrapper.eHeaderButton, 'ag-tab-selected');
|
96 | this.activeItem = wrapper;
|
97 | if (wrapper.tabbedItem.afterAttachedCallback) {
|
98 | wrapper.tabbedItem.afterAttachedCallback(this.afterAttachedParams);
|
99 | }
|
100 | };
|
101 | TabbedLayout.prototype.getGui = function () {
|
102 | return this.eGui;
|
103 | };
|
104 | TabbedLayout.TEMPLATE = '<div>' +
|
105 | '<div ref="tabHeader" class="ag-tab-header"></div>' +
|
106 | '<div ref="tabBody" class="ag-tab-body"></div>' +
|
107 | '</div>';
|
108 | return TabbedLayout;
|
109 | }());
|
110 | exports.TabbedLayout = TabbedLayout;
|