UNPKG

primeng

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Join the chat at https://gitter.im/primefaces/primeng](https://badges.gitter.im/primefaces/primeng.svg)](https://gitter.im/primefaces/primeng?ut

206 lines 10.6 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); var core_1 = require("@angular/core"); var common_1 = require("@angular/common"); var domhandler_1 = require("../dom/domhandler"); var ScrollPanel = /** @class */ (function () { function ScrollPanel(el, zone, domHandler) { this.el = el; this.zone = zone; this.domHandler = domHandler; this.timeoutFrame = function (fn) { return setTimeout(fn, 0); }; } ScrollPanel.prototype.ngAfterViewInit = function () { var _this = this; this.zone.runOutsideAngular(function () { _this.moveBar(); _this.moveBar = _this.moveBar.bind(_this); _this.onXBarMouseDown = _this.onXBarMouseDown.bind(_this); _this.onYBarMouseDown = _this.onYBarMouseDown.bind(_this); _this.onDocumentMouseMove = _this.onDocumentMouseMove.bind(_this); _this.onDocumentMouseUp = _this.onDocumentMouseUp.bind(_this); window.addEventListener('resize', _this.moveBar); _this.contentViewChild.nativeElement.addEventListener('scroll', _this.moveBar); _this.contentViewChild.nativeElement.addEventListener('mouseenter', _this.moveBar); _this.xBarViewChild.nativeElement.addEventListener('mousedown', _this.onXBarMouseDown); _this.yBarViewChild.nativeElement.addEventListener('mousedown', _this.onYBarMouseDown); _this.calculateContainerHeight(); _this.initialized = true; }); }; ScrollPanel.prototype.calculateContainerHeight = function () { var container = this.containerViewChild.nativeElement; var content = this.contentViewChild.nativeElement; var xBar = this.xBarViewChild.nativeElement; var containerStyles = getComputedStyle(container), xBarStyles = getComputedStyle(xBar), pureContainerHeight = this.domHandler.getHeight(container) - parseInt(xBarStyles['height'], 10); if (containerStyles['max-height'] != "none" && pureContainerHeight == 0) { if (content.offsetHeight + parseInt(xBarStyles['height'], 10) > parseInt(containerStyles['max-height'], 10)) { container.style.height = containerStyles['max-height']; } else { container.style.height = content.offsetHeight + parseFloat(containerStyles.paddingTop) + parseFloat(containerStyles.paddingBottom) + parseFloat(containerStyles.borderTopWidth) + parseFloat(containerStyles.borderBottomWidth) + "px"; } } }; ScrollPanel.prototype.moveBar = function () { var _this = this; var container = this.containerViewChild.nativeElement; var content = this.contentViewChild.nativeElement; /* horizontal scroll */ var xBar = this.xBarViewChild.nativeElement; var totalWidth = content.scrollWidth; var ownWidth = content.clientWidth; var bottom = (container.clientHeight - xBar.clientHeight) * -1; this.scrollXRatio = ownWidth / totalWidth; /* vertical scroll */ var yBar = this.yBarViewChild.nativeElement; var totalHeight = content.scrollHeight; var ownHeight = content.clientHeight; var right = (container.clientWidth - yBar.clientWidth) * -1; this.scrollYRatio = ownHeight / totalHeight; this.requestAnimationFrame(function () { if (_this.scrollXRatio >= 1) { _this.domHandler.addClass(xBar, 'ui-scrollpanel-hidden'); } else { _this.domHandler.removeClass(xBar, 'ui-scrollpanel-hidden'); xBar.style.cssText = 'width:' + Math.max(_this.scrollXRatio * 100, 10) + '%; left:' + (content.scrollLeft / totalWidth) * 100 + '%;bottom:' + bottom + 'px;'; } if (_this.scrollYRatio >= 1) { _this.domHandler.addClass(yBar, 'ui-scrollpanel-hidden'); } else { _this.domHandler.removeClass(yBar, 'ui-scrollpanel-hidden'); yBar.style.cssText = 'height:' + Math.max(_this.scrollYRatio * 100, 10) + '%; top: calc(' + (content.scrollTop / totalHeight) * 100 + '% - ' + xBar.clientHeight + 'px);right:' + right + 'px;'; } }); }; ScrollPanel.prototype.onYBarMouseDown = function (e) { this.isYBarClicked = true; this.lastPageY = e.pageY; this.domHandler.addClass(this.yBarViewChild.nativeElement, 'ui-scrollpanel-grabbed'); this.domHandler.addClass(document.body, 'ui-scrollpanel-grabbed'); document.addEventListener('mousemove', this.onDocumentMouseMove); document.addEventListener('mouseup', this.onDocumentMouseUp); e.preventDefault(); }; ScrollPanel.prototype.onXBarMouseDown = function (e) { this.isXBarClicked = true; this.lastPageX = e.pageX; this.domHandler.addClass(this.xBarViewChild.nativeElement, 'ui-scrollpanel-grabbed'); this.domHandler.addClass(document.body, 'ui-scrollpanel-grabbed'); document.addEventListener('mousemove', this.onDocumentMouseMove); document.addEventListener('mouseup', this.onDocumentMouseUp); e.preventDefault(); }; ScrollPanel.prototype.onDocumentMouseMove = function (e) { if (this.isXBarClicked) { this.onMouseMoveForXBar(e); } else if (this.isYBarClicked) { this.onMouseMoveForYBar(e); } else { this.onMouseMoveForXBar(e); this.onMouseMoveForYBar(e); } }; ScrollPanel.prototype.onMouseMoveForXBar = function (e) { var _this = this; var deltaX = e.pageX - this.lastPageX; this.lastPageX = e.pageX; this.requestAnimationFrame(function () { _this.contentViewChild.nativeElement.scrollLeft += deltaX / _this.scrollXRatio; }); }; ScrollPanel.prototype.onMouseMoveForYBar = function (e) { var _this = this; var deltaY = e.pageY - this.lastPageY; this.lastPageY = e.pageY; this.requestAnimationFrame(function () { _this.contentViewChild.nativeElement.scrollTop += deltaY / _this.scrollYRatio; }); }; ScrollPanel.prototype.onDocumentMouseUp = function (e) { this.domHandler.removeClass(this.yBarViewChild.nativeElement, 'ui-scrollpanel-grabbed'); this.domHandler.removeClass(this.xBarViewChild.nativeElement, 'ui-scrollpanel-grabbed'); this.domHandler.removeClass(document.body, 'ui-scrollpanel-grabbed'); document.removeEventListener('mousemove', this.onDocumentMouseMove); document.removeEventListener('mouseup', this.onDocumentMouseUp); this.isXBarClicked = false; this.isYBarClicked = false; }; ScrollPanel.prototype.requestAnimationFrame = function (f) { var frame = window.requestAnimationFrame || this.timeoutFrame; frame(f); }; ScrollPanel.prototype.ngOnDestroy = function () { if (this.initialized) { window.removeEventListener('resize', this.moveBar); this.contentViewChild.nativeElement.removeEventListener('scroll', this.moveBar); this.contentViewChild.nativeElement.removeEventListener('mouseenter', this.moveBar); this.xBarViewChild.nativeElement.removeEventListener('mousedown', this.onXBarMouseDown); this.yBarViewChild.nativeElement.removeEventListener('mousedown', this.onYBarMouseDown); } }; ScrollPanel.prototype.refresh = function () { this.moveBar(); }; __decorate([ core_1.Input(), __metadata("design:type", Object) ], ScrollPanel.prototype, "style", void 0); __decorate([ core_1.Input(), __metadata("design:type", String) ], ScrollPanel.prototype, "styleClass", void 0); __decorate([ core_1.ViewChild('container'), __metadata("design:type", core_1.ElementRef) ], ScrollPanel.prototype, "containerViewChild", void 0); __decorate([ core_1.ViewChild('content'), __metadata("design:type", core_1.ElementRef) ], ScrollPanel.prototype, "contentViewChild", void 0); __decorate([ core_1.ViewChild('xBar'), __metadata("design:type", core_1.ElementRef) ], ScrollPanel.prototype, "xBarViewChild", void 0); __decorate([ core_1.ViewChild('yBar'), __metadata("design:type", core_1.ElementRef) ], ScrollPanel.prototype, "yBarViewChild", void 0); ScrollPanel = __decorate([ core_1.Component({ selector: 'p-scrollPanel', 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 ", providers: [domhandler_1.DomHandler] }), __metadata("design:paramtypes", [core_1.ElementRef, core_1.NgZone, domhandler_1.DomHandler]) ], ScrollPanel); return ScrollPanel; }()); exports.ScrollPanel = ScrollPanel; var ScrollPanelModule = /** @class */ (function () { function ScrollPanelModule() { } ScrollPanelModule = __decorate([ core_1.NgModule({ imports: [common_1.CommonModule], exports: [ScrollPanel], declarations: [ScrollPanel] }) ], ScrollPanelModule); return ScrollPanelModule; }()); exports.ScrollPanelModule = ScrollPanelModule; //# sourceMappingURL=scrollpanel.js.map