UNPKG

12 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('primeng/dom')) :
3 typeof define === 'function' && define.amd ? define('primeng/scrollpanel', ['exports', '@angular/core', '@angular/common', 'primeng/dom'], factory) :
4 (global = global || self, factory((global.primeng = global.primeng || {}, global.primeng.scrollpanel = {}), global.ng.core, global.ng.common, global.primeng.dom));
5}(this, (function (exports, core, 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 ScrollPanel = /** @class */ (function () {
14 function ScrollPanel(el, zone) {
15 this.el = el;
16 this.zone = zone;
17 this.timeoutFrame = function (fn) { return setTimeout(fn, 0); };
18 }
19 ScrollPanel.prototype.ngAfterViewInit = function () {
20 var _this = this;
21 this.zone.runOutsideAngular(function () {
22 _this.moveBar();
23 _this.moveBar = _this.moveBar.bind(_this);
24 _this.onXBarMouseDown = _this.onXBarMouseDown.bind(_this);
25 _this.onYBarMouseDown = _this.onYBarMouseDown.bind(_this);
26 _this.onDocumentMouseMove = _this.onDocumentMouseMove.bind(_this);
27 _this.onDocumentMouseUp = _this.onDocumentMouseUp.bind(_this);
28 window.addEventListener('resize', _this.moveBar);
29 _this.contentViewChild.nativeElement.addEventListener('scroll', _this.moveBar);
30 _this.contentViewChild.nativeElement.addEventListener('mouseenter', _this.moveBar);
31 _this.xBarViewChild.nativeElement.addEventListener('mousedown', _this.onXBarMouseDown);
32 _this.yBarViewChild.nativeElement.addEventListener('mousedown', _this.onYBarMouseDown);
33 _this.calculateContainerHeight();
34 _this.initialized = true;
35 });
36 };
37 ScrollPanel.prototype.calculateContainerHeight = function () {
38 var container = this.containerViewChild.nativeElement;
39 var content = this.contentViewChild.nativeElement;
40 var xBar = this.xBarViewChild.nativeElement;
41 var containerStyles = getComputedStyle(container), xBarStyles = getComputedStyle(xBar), pureContainerHeight = dom.DomHandler.getHeight(container) - parseInt(xBarStyles['height'], 10);
42 if (containerStyles['max-height'] != "none" && pureContainerHeight == 0) {
43 if (content.offsetHeight + parseInt(xBarStyles['height'], 10) > parseInt(containerStyles['max-height'], 10)) {
44 container.style.height = containerStyles['max-height'];
45 }
46 else {
47 container.style.height = content.offsetHeight + parseFloat(containerStyles.paddingTop) + parseFloat(containerStyles.paddingBottom) + parseFloat(containerStyles.borderTopWidth) + parseFloat(containerStyles.borderBottomWidth) + "px";
48 }
49 }
50 };
51 ScrollPanel.prototype.moveBar = function () {
52 var _this = this;
53 var container = this.containerViewChild.nativeElement;
54 var content = this.contentViewChild.nativeElement;
55 /* horizontal scroll */
56 var xBar = this.xBarViewChild.nativeElement;
57 var totalWidth = content.scrollWidth;
58 var ownWidth = content.clientWidth;
59 var bottom = (container.clientHeight - xBar.clientHeight) * -1;
60 this.scrollXRatio = ownWidth / totalWidth;
61 /* vertical scroll */
62 var yBar = this.yBarViewChild.nativeElement;
63 var totalHeight = content.scrollHeight;
64 var ownHeight = content.clientHeight;
65 var right = (container.clientWidth - yBar.clientWidth) * -1;
66 this.scrollYRatio = ownHeight / totalHeight;
67 this.requestAnimationFrame(function () {
68 if (_this.scrollXRatio >= 1) {
69 dom.DomHandler.addClass(xBar, 'ui-scrollpanel-hidden');
70 }
71 else {
72 dom.DomHandler.removeClass(xBar, 'ui-scrollpanel-hidden');
73 var xBarWidth = Math.max(_this.scrollXRatio * 100, 10);
74 var xBarLeft = content.scrollLeft * (100 - xBarWidth) / (totalWidth - ownWidth);
75 xBar.style.cssText = 'width:' + xBarWidth + '%; left:' + xBarLeft + '%;bottom:' + bottom + 'px;';
76 }
77 if (_this.scrollYRatio >= 1) {
78 dom.DomHandler.addClass(yBar, 'ui-scrollpanel-hidden');
79 }
80 else {
81 dom.DomHandler.removeClass(yBar, 'ui-scrollpanel-hidden');
82 var yBarHeight = Math.max(_this.scrollYRatio * 100, 10);
83 var yBarTop = content.scrollTop * (100 - yBarHeight) / (totalHeight - ownHeight);
84 yBar.style.cssText = 'height:' + yBarHeight + '%; top: calc(' + yBarTop + '% - ' + xBar.clientHeight + 'px);right:' + right + 'px;';
85 }
86 });
87 };
88 ScrollPanel.prototype.onYBarMouseDown = function (e) {
89 this.isYBarClicked = true;
90 this.lastPageY = e.pageY;
91 dom.DomHandler.addClass(this.yBarViewChild.nativeElement, 'ui-scrollpanel-grabbed');
92 dom.DomHandler.addClass(document.body, 'ui-scrollpanel-grabbed');
93 document.addEventListener('mousemove', this.onDocumentMouseMove);
94 document.addEventListener('mouseup', this.onDocumentMouseUp);
95 e.preventDefault();
96 };
97 ScrollPanel.prototype.onXBarMouseDown = function (e) {
98 this.isXBarClicked = true;
99 this.lastPageX = e.pageX;
100 dom.DomHandler.addClass(this.xBarViewChild.nativeElement, 'ui-scrollpanel-grabbed');
101 dom.DomHandler.addClass(document.body, 'ui-scrollpanel-grabbed');
102 document.addEventListener('mousemove', this.onDocumentMouseMove);
103 document.addEventListener('mouseup', this.onDocumentMouseUp);
104 e.preventDefault();
105 };
106 ScrollPanel.prototype.onDocumentMouseMove = function (e) {
107 if (this.isXBarClicked) {
108 this.onMouseMoveForXBar(e);
109 }
110 else if (this.isYBarClicked) {
111 this.onMouseMoveForYBar(e);
112 }
113 else {
114 this.onMouseMoveForXBar(e);
115 this.onMouseMoveForYBar(e);
116 }
117 };
118 ScrollPanel.prototype.onMouseMoveForXBar = function (e) {
119 var _this = this;
120 var deltaX = e.pageX - this.lastPageX;
121 this.lastPageX = e.pageX;
122 this.requestAnimationFrame(function () {
123 _this.contentViewChild.nativeElement.scrollLeft += deltaX / _this.scrollXRatio;
124 });
125 };
126 ScrollPanel.prototype.onMouseMoveForYBar = function (e) {
127 var _this = this;
128 var deltaY = e.pageY - this.lastPageY;
129 this.lastPageY = e.pageY;
130 this.requestAnimationFrame(function () {
131 _this.contentViewChild.nativeElement.scrollTop += deltaY / _this.scrollYRatio;
132 });
133 };
134 ScrollPanel.prototype.scrollTop = function (scrollTop) {
135 var scrollableHeight = this.contentViewChild.nativeElement.scrollHeight - this.contentViewChild.nativeElement.clientHeight;
136 scrollTop = scrollTop > scrollableHeight ? scrollableHeight : scrollTop > 0 ? scrollTop : 0;
137 this.contentViewChild.nativeElement.scrollTop = scrollTop;
138 };
139 ScrollPanel.prototype.onDocumentMouseUp = function (e) {
140 dom.DomHandler.removeClass(this.yBarViewChild.nativeElement, 'ui-scrollpanel-grabbed');
141 dom.DomHandler.removeClass(this.xBarViewChild.nativeElement, 'ui-scrollpanel-grabbed');
142 dom.DomHandler.removeClass(document.body, 'ui-scrollpanel-grabbed');
143 document.removeEventListener('mousemove', this.onDocumentMouseMove);
144 document.removeEventListener('mouseup', this.onDocumentMouseUp);
145 this.isXBarClicked = false;
146 this.isYBarClicked = false;
147 };
148 ScrollPanel.prototype.requestAnimationFrame = function (f) {
149 var frame = window.requestAnimationFrame || this.timeoutFrame;
150 frame(f);
151 };
152 ScrollPanel.prototype.ngOnDestroy = function () {
153 if (this.initialized) {
154 window.removeEventListener('resize', this.moveBar);
155 this.contentViewChild.nativeElement.removeEventListener('scroll', this.moveBar);
156 this.contentViewChild.nativeElement.removeEventListener('mouseenter', this.moveBar);
157 this.xBarViewChild.nativeElement.removeEventListener('mousedown', this.onXBarMouseDown);
158 this.yBarViewChild.nativeElement.removeEventListener('mousedown', this.onYBarMouseDown);
159 }
160 };
161 ScrollPanel.prototype.refresh = function () {
162 this.moveBar();
163 };
164 ScrollPanel.ctorParameters = function () { return [
165 { type: core.ElementRef },
166 { type: core.NgZone }
167 ]; };
168 __decorate([
169 core.Input()
170 ], ScrollPanel.prototype, "style", void 0);
171 __decorate([
172 core.Input()
173 ], ScrollPanel.prototype, "styleClass", void 0);
174 __decorate([
175 core.ViewChild('container')
176 ], ScrollPanel.prototype, "containerViewChild", void 0);
177 __decorate([
178 core.ViewChild('content')
179 ], ScrollPanel.prototype, "contentViewChild", void 0);
180 __decorate([
181 core.ViewChild('xBar')
182 ], ScrollPanel.prototype, "xBarViewChild", void 0);
183 __decorate([
184 core.ViewChild('yBar')
185 ], ScrollPanel.prototype, "yBarViewChild", void 0);
186 ScrollPanel = __decorate([
187 core.Component({
188 selector: 'p-scrollPanel',
189 template: "\n <div #container [ngClass]=\"'ui-scrollpanel ui-widget ui-widget-content ui-corner-all'\" [ngStyle]=\"style\" [class]=\"styleClass\">\n <div class=\"ui-scrollpanel-wrapper\">\n <div #content class=\"ui-scrollpanel-content\">\n <ng-content></ng-content>\n </div>\n </div>\n <div #xBar class=\"ui-scrollpanel-bar ui-scrollpanel-bar-x\"></div>\n <div #yBar class=\"ui-scrollpanel-bar ui-scrollpanel-bar-y\"></div> \n </div>\n ",
190 changeDetection: core.ChangeDetectionStrategy.Default
191 })
192 ], ScrollPanel);
193 return ScrollPanel;
194 }());
195 var ScrollPanelModule = /** @class */ (function () {
196 function ScrollPanelModule() {
197 }
198 ScrollPanelModule = __decorate([
199 core.NgModule({
200 imports: [common.CommonModule],
201 exports: [ScrollPanel],
202 declarations: [ScrollPanel]
203 })
204 ], ScrollPanelModule);
205 return ScrollPanelModule;
206 }());
207
208 exports.ScrollPanel = ScrollPanel;
209 exports.ScrollPanelModule = ScrollPanelModule;
210
211 Object.defineProperty(exports, '__esModule', { value: true });
212
213})));
214//# sourceMappingURL=primeng-scrollpanel.umd.js.map