1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | "use strict";
|
8 | var __extends = (this && this.__extends) || (function () {
|
9 | var extendStatics = Object.setPrototypeOf ||
|
10 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
11 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
12 | return function (d, b) {
|
13 | extendStatics(d, b);
|
14 | function __() { this.constructor = d; }
|
15 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
16 | };
|
17 | })();
|
18 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
19 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
20 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
21 | 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;
|
22 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
23 | };
|
24 | var __metadata = (this && this.__metadata) || function (k, v) {
|
25 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
26 | };
|
27 | Object.defineProperty(exports, "__esModule", { value: true });
|
28 | var beanStub_1 = require("../context/beanStub");
|
29 | var context_1 = require("../context/context");
|
30 | var eventService_1 = require("../eventService");
|
31 | var eventKeys_1 = require("../eventKeys");
|
32 | var utils_1 = require("../utils");
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | var HeightScaler = (function (_super) {
|
38 | __extends(HeightScaler, _super);
|
39 | function HeightScaler() {
|
40 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
41 |
|
42 | _this.scrollY = 0;
|
43 |
|
44 | _this.uiBodyHeight = 0;
|
45 | return _this;
|
46 | }
|
47 | HeightScaler.prototype.postConstruct = function () {
|
48 | this.addDestroyableEventListener(this.eventService, eventKeys_1.Events.EVENT_BODY_HEIGHT_CHANGED, this.update.bind(this));
|
49 | this.scrollBarWidth = utils_1._.getScrollbarWidth();
|
50 | this.maxDivHeight = utils_1._.getMaxDivHeight();
|
51 | };
|
52 | HeightScaler.prototype.registerGridComp = function (gridPanel) {
|
53 | this.gridPanel = gridPanel;
|
54 | };
|
55 | HeightScaler.prototype.isScaling = function () {
|
56 | return this.scaling;
|
57 | };
|
58 | HeightScaler.prototype.getOffset = function () {
|
59 | return this.offset;
|
60 | };
|
61 | HeightScaler.prototype.update = function () {
|
62 | if (!this.scaling) {
|
63 | return;
|
64 | }
|
65 | var newScrollY = this.gridPanel.getVScrollPosition().top;
|
66 | var newBodyHeight = this.getUiBodyHeight();
|
67 | var atLeastOneChanged = newScrollY !== this.scrollY || newBodyHeight !== this.uiBodyHeight;
|
68 | if (atLeastOneChanged) {
|
69 | this.scrollY = newScrollY;
|
70 | this.uiBodyHeight = newBodyHeight;
|
71 | this.calculateOffset();
|
72 | }
|
73 | };
|
74 | HeightScaler.prototype.calculateOffset = function () {
|
75 | this.uiContainerHeight = this.maxDivHeight;
|
76 | this.pixelsToShave = this.modelHeight - this.uiContainerHeight;
|
77 | this.maxScrollY = this.uiContainerHeight - this.uiBodyHeight;
|
78 | var scrollPercent = this.scrollY / this.maxScrollY;
|
79 | this.setOffset(scrollPercent * this.pixelsToShave);
|
80 | };
|
81 | HeightScaler.prototype.clearOffset = function () {
|
82 | this.uiContainerHeight = this.modelHeight;
|
83 | this.pixelsToShave = 0;
|
84 | this.setOffset(0);
|
85 | };
|
86 | HeightScaler.prototype.setOffset = function (newOffset) {
|
87 |
|
88 | var newOffsetFloor = typeof newOffset === 'number' ? Math.floor(newOffset) : null;
|
89 | if (this.offset !== newOffsetFloor) {
|
90 | this.offset = newOffsetFloor;
|
91 | this.eventService.dispatchEvent({ type: eventKeys_1.Events.EVENT_HEIGHT_SCALE_CHANGED });
|
92 | }
|
93 | };
|
94 | HeightScaler.prototype.setModelHeight = function (modelHeight) {
|
95 | this.modelHeight = modelHeight;
|
96 | this.scaling = this.maxDivHeight > 0 && modelHeight > this.maxDivHeight;
|
97 | if (this.scaling) {
|
98 | this.calculateOffset();
|
99 | }
|
100 | else {
|
101 | this.clearOffset();
|
102 | }
|
103 | };
|
104 | HeightScaler.prototype.getUiContainerHeight = function () {
|
105 | return this.uiContainerHeight;
|
106 | };
|
107 | HeightScaler.prototype.getRealPixelPosition = function (modelPixel) {
|
108 | var uiPixel = modelPixel - this.offset;
|
109 | return uiPixel;
|
110 | };
|
111 | HeightScaler.prototype.getUiBodyHeight = function () {
|
112 | var pos = this.gridPanel.getVScrollPosition();
|
113 | var bodyHeight = pos.bottom - pos.top;
|
114 | if (this.gridPanel.isHorizontalScrollShowing()) {
|
115 | bodyHeight -= this.scrollBarWidth;
|
116 | }
|
117 | return bodyHeight;
|
118 | };
|
119 | HeightScaler.prototype.getScrollPositionForPixel = function (rowTop) {
|
120 | if (this.pixelsToShave <= 0) {
|
121 | return rowTop;
|
122 | }
|
123 | else {
|
124 | var modelMaxScroll = this.modelHeight - this.getUiBodyHeight();
|
125 | var scrollPercent = rowTop / modelMaxScroll;
|
126 | var scrollPixel = this.maxScrollY * scrollPercent;
|
127 | return scrollPixel;
|
128 | }
|
129 | };
|
130 | __decorate([
|
131 | context_1.Autowired('eventService'),
|
132 | __metadata("design:type", eventService_1.EventService)
|
133 | ], HeightScaler.prototype, "eventService", void 0);
|
134 | __decorate([
|
135 | context_1.PostConstruct,
|
136 | __metadata("design:type", Function),
|
137 | __metadata("design:paramtypes", []),
|
138 | __metadata("design:returntype", void 0)
|
139 | ], HeightScaler.prototype, "postConstruct", null);
|
140 | HeightScaler = __decorate([
|
141 | context_1.Bean('heightScaler')
|
142 | ], HeightScaler);
|
143 | return HeightScaler;
|
144 | }(beanStub_1.BeanStub));
|
145 | exports.HeightScaler = HeightScaler;
|