@lidorsystems/integralui-web
Version:
IntegralUI Web - Advanced UI Components for Angular
15 lines (12 loc) • 10.9 kB
JavaScript
/*
filename: integralui.scrollbar.js
version : 20.2.0
Copyright © 2016-2020 Lidor Systems. All rights reserved.
This file is part of the "IntegralUI Web" Library.
The contents of this file are subject to the IntegralUI Web License, and may not be used except in compliance with the License.
A copy of the License should have been installed in the product's root installation directory or it can be found at
http://www.lidorsystems.com/products/web/studio/license-agreement.aspx.
This SOFTWARE is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language
governing rights and limitations under the License. Any infringement will be prosecuted under applicable laws.
*/
"use strict";var __extends=this&&this.__extends||function(){var e=function(t,i){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)if(t.hasOwnProperty(i))e[i]=t[i]})(t,i)};return function(t,i){e(t,i);function r(){this.constructor=t}t.prototype=null===i?Object.create(i):(r.prototype=i.prototype,new r)}}();Object.defineProperty(exports,"__esModule",{value:!0});var core_1=require("@angular/core"),integralui_core_1=require("./integralui.core"),integralui_common_service_1=require("../services/integralui.common.service"),i0=require("@angular/core"),i1=require("../services/integralui.common.service"),i2=require("@angular/common"),_c0=function(e,t){return{top:e,height:t}};function IntegralUIScrollBar_div_0_Template(e,t){if(1&e){var i=i0.ɵɵgetCurrentView();i0.ɵɵelementStart(0,"div",2);i0.ɵɵlistener("mousedown",function(e){i0.ɵɵrestoreView(i);return i0.ɵɵnextContext().changeScrollPos(e)});i0.ɵɵelementStart(1,"div",3);i0.ɵɵlistener("mousedown",function(e){i0.ɵɵrestoreView(i);return i0.ɵɵnextContext().thumbMouseDown(e)});i0.ɵɵelementEnd();i0.ɵɵelementEnd()}if(2&e){var r=i0.ɵɵnextContext();i0.ɵɵproperty("ngStyle",r.getScrollBarStyle());i0.ɵɵadvance(1);i0.ɵɵproperty("ngStyle",i0.ɵɵpureFunction2(2,_c0,r.thumbPos.y+"px",r.thumbSize.height+"px"))}}var _c1=function(e,t){return{left:e,width:t}};function IntegralUIScrollBar_div_1_Template(e,t){if(1&e){var i=i0.ɵɵgetCurrentView();i0.ɵɵelementStart(0,"div",4);i0.ɵɵlistener("mousedown",function(e){i0.ɵɵrestoreView(i);return i0.ɵɵnextContext().changeScrollPos(e)});i0.ɵɵelementStart(1,"div",5);i0.ɵɵlistener("mousedown",function(e){i0.ɵɵrestoreView(i);return i0.ɵɵnextContext().thumbMouseDown(e)});i0.ɵɵelementEnd();i0.ɵɵelementEnd()}if(2&e){var r=i0.ɵɵnextContext();i0.ɵɵproperty("ngStyle",r.getScrollBarStyle());i0.ɵɵadvance(1);i0.ɵɵproperty("ngStyle",i0.ɵɵpureFunction2(2,_c1,r.thumbPos.x+"px",r.thumbSize.width+"px"))}}var IntegralUIScrollBar=function(e){__extends(t,e);function t(t,i,r){var n=e.call(this,r)||this;n.elemRef=t;n.elemRenderer=i;n.commonService=r;n.currentMaxValue=0;n.currentMinValue=0;n.currentValue=0;n.currentSplitterDistance={x:0,y:0};n.emptySpace=0;n.maxPos={x:0,y:0};n.scrollPos={top:0,right:0,bottom:0,left:0};n.scrollSize={width:0,height:0};n.thumbSize={width:0,height:0};n.thumbPos={x:2,y:2};n.smallChange=0;n.largeChangeValue=0;n.orientation=integralui_core_1.IntegralUIOrientation.Vertical;n.scrollMouseDown=new core_1.EventEmitter;n.scrollStart=new core_1.EventEmitter;n.scrollEnd=new core_1.EventEmitter;n.valueChanged=new core_1.EventEmitter;n.thumbStartPos={x:0,y:0};n.isThumbActive=!1;n.prevPos={x:0,y:0};n.scrollInterval=null;n.scrollTimeout=null;return n}Object.defineProperty(t.prototype,"height",{set:function(e){if(this.scrollSize.height!=e&&e>=0){this.scrollSize.height=e;this.updateLayout()}},enumerable:!0,configurable:!0});Object.defineProperty(t.prototype,"largeChange",{set:function(e){if(this.largeChangeValue!=e&&e>=0)this.largeChangeValue=e},enumerable:!0,configurable:!0});Object.defineProperty(t.prototype,"max",{get:function(){return this.currentMaxValue},set:function(e){if(this.currentMaxValue!=e){if(e<=0)this.currentMaxValue=1;else this.currentMaxValue=e;if(this.currentValue>this.currentMaxValue)this.currentValue=this.currentMaxValue;this.updateLayout()}},enumerable:!0,configurable:!0});Object.defineProperty(t.prototype,"min",{get:function(){return this.currentMinValue},set:function(e){if(this.currentMinValue!=e&&e>=0){this.currentMinValue=e;this.updateLayout()}},enumerable:!0,configurable:!0});Object.defineProperty(t.prototype,"position",{set:function(e){if(e)this.scrollPos={top:this.commonService.isFieldAvailable(e.top,0),right:this.commonService.isFieldAvailable(e.right,0),bottom:this.commonService.isFieldAvailable(e.bottom,0),left:this.commonService.isFieldAvailable(e.left,0)};else this.scrollPos={top:0,right:0,bottom:0,left:0}},enumerable:!0,configurable:!0});Object.defineProperty(t.prototype,"value",{get:function(){return this.currentValue},set:function(e){if(this.currentValue!=e){if(e<this.currentMinValue)this.currentValue=this.currentMinValue;else if(e>this.currentMaxValue)this.currentValue=this.currentMaxValue;else this.currentValue=e;this.updateLayout();this.valueChanged.emit({value:this.currentValue})}},enumerable:!0,configurable:!0});Object.defineProperty(t.prototype,"width",{set:function(e){if(this.scrollSize.width!=e&&e>=0){this.scrollSize.width=e;this.updateLayout()}},enumerable:!0,configurable:!0});t.prototype.ngOnInit=function(){this.generalClassName="iui-scrollbar";this.initStyle()};t.prototype.ngAfterViewInit=function(){};t.prototype.ngAfterContentInit=function(){var e=this,t=setTimeout(function(){e.updateLayout();clearTimeout(t)},1)};t.prototype.ngOnDestroy=function(){this.clearScrolling()};t.prototype.isVertical=function(){return this.orientation==integralui_core_1.IntegralUIOrientation.Vertical?!0:!1};t.prototype.getSize=function(){return{width:this.elemRef.nativeElement.firstElementChild.offsetWidth,height:this.elemRef.nativeElement.firstElementChild.offsetHeight}};t.prototype.setScrollSize=function(e){this.scrollSize=e};t.prototype.updateLayout=function(){if(this.orientation==integralui_core_1.IntegralUIOrientation.Horizontal){if(0==this.largeChangeValue)this.largeChangeValue=this.scrollSize.width;var e=this.scrollSize.width-2,t=0;if(this.currentMaxValue+e>0)t=e*e/(this.currentMaxValue+e);t=e/(this.currentMaxValue+this.largeChangeValue)*this.largeChangeValue;if(this.currentMaxValue<=0)t=e;else if(t<7)t=7;this.thumbSize.width=t;this.emptySpace=e-t;if(this.currentMaxValue>0)this.thumbPos.x=2+this.currentValue*this.emptySpace/this.currentMaxValue}else{if(0==this.largeChangeValue)this.largeChangeValue=this.scrollSize.height;var i=this.scrollSize.height-2,r=0;if(this.currentMaxValue+i>0)r=i*i/(this.currentMaxValue+i);r=i/(this.currentMaxValue+this.largeChangeValue)*this.largeChangeValue;if(this.currentMaxValue<=0)r=i;else if(r<7)r=7;this.thumbSize.height=r;this.emptySpace=i-r;if(this.currentMaxValue>0)this.thumbPos.y=2+this.currentValue*this.emptySpace/this.currentMaxValue}};t.prototype.thumbMouseDown=function(e){if(this.isEnabled){var t=this.commonService.getShiftPos(),i={x:e.pageX-t.x,y:e.pageY-t.y};this.thumbStartPos=i;this.isThumbActive=!0;this.prevPos={x:this.value,y:this.value};this.scrollStart.emit({value:this.currentValue})}this.scrollMouseDown.emit(null);e.stopPropagation()};t.prototype.onWindowMouseMove=function(e){if(this.isEnabled&&1==e.buttons&&this.isThumbActive){var t=this.commonService.getShiftPos(),i={x:e.pageX-t.x,y:e.pageY-t.y},r=0;if(this.orientation==integralui_core_1.IntegralUIOrientation.Horizontal){if(this.emptySpace>0)r=this.prevPos.x+(i.x-this.thumbStartPos.x)*this.currentMaxValue/this.emptySpace}else if(this.emptySpace>0)r=this.prevPos.y+(i.y-this.thumbStartPos.y)*this.currentMaxValue/this.emptySpace;this.value=r}};t.prototype.onWindowMouseUp=function(e){if(this.isEnabled){this.isThumbActive=!1;this.prevPos.y=this.currentValue;this.clearScrolling();this.scrollEnd.emit({value:this.currentValue})}};t.prototype.changeScrollPos=function(e){if(this.isEnabled){var t=this;t.processLargeChange(e);t.clearScrolling();t.scrollTimeout=setTimeout(function(){t.scrollInterval=setInterval(function(){if(t.currentValue>t.currentMinValue&&t.currentValue<t.currentMaxValue)t.processLargeChange(e);else t.clearScrolling()},100);clearTimeout(t.scrollTimeout)},250)}};t.prototype.processLargeChange=function(e){var t=-1;if(this.isVertical())t=e.offsetY<this.thumbPos.y?1:e.offsetY>this.thumbPos.y+this.thumbSize.height?2:-1;else t=e.offsetX<this.thumbPos.x?1:e.offsetX>this.thumbPos.x+this.thumbSize.width?2:-1;switch(t){case 1:this.value-=this.largeChangeValue;break;case 2:this.value+=this.largeChangeValue}};t.prototype.clearScrolling=function(){if(this.scrollTimeout)clearTimeout(this.scrollTimeout);if(this.scrollInterval)clearInterval(this.scrollInterval);this.scrollTimeout=null;this.scrollInterval=null};t.prototype.getScrollBarStyle=function(){if(this.orientation==integralui_core_1.IntegralUIOrientation.Horizontal)return{bottom:this.scrollPos.bottom+"px",left:0,width:this.scrollSize.width+"px"};else return{top:this.scrollPos.top+"px",right:0,height:this.scrollSize.height+"px"}};t.ɵfac=function(e){return new(e||t)(i0.ɵɵdirectiveInject(i0.ElementRef),i0.ɵɵdirectiveInject(i0.Renderer2),i0.ɵɵdirectiveInject(i1.IntegralUICommonService))};t.ɵcmp=i0.ɵɵdefineComponent({type:t,selectors:[["iui-scrollbar"]],hostBindings:function(e,t){if(1&e)i0.ɵɵlistener("mousemove",function(e){return t.onWindowMouseMove(e)},!1,i0.ɵɵresolveDocument)("mouseup",function(e){return t.onWindowMouseUp(e)},!1,i0.ɵɵresolveDocument)},inputs:{controlStyle:"controlStyle",data:"data",enabled:"enabled",name:"name",state:"state",height:"height",largeChange:"largeChange",max:"max",min:"min",orientation:"orientation",position:"position",value:"value",width:"width"},outputs:{scrollMouseDown:"scrollMouseDown",scrollStart:"scrollStart",scrollEnd:"scrollEnd",valueChanged:"valueChanged"},features:[i0.ɵɵInheritDefinitionFeature],decls:2,vars:2,consts:[["class","iui-scrollbar-vertical",3,"ngStyle","mousedown",4,"ngIf"],["class","iui-scrollbar-horizontal",3,"ngStyle","mousedown",4,"ngIf"],[1,"iui-scrollbar-vertical",3,"ngStyle","mousedown"],[1,"iui-scroll-button-thumb-vertical",3,"ngStyle","mousedown"],[1,"iui-scrollbar-horizontal",3,"ngStyle","mousedown"],[1,"iui-scroll-button-thumb-horizontal",3,"ngStyle","mousedown"]],template:function(e,t){if(1&e){i0.ɵɵtemplate(0,IntegralUIScrollBar_div_0_Template,2,5,"div",0);i0.ɵɵtemplate(1,IntegralUIScrollBar_div_1_Template,2,5,"div",1)}if(2&e){i0.ɵɵproperty("ngIf",t.isVertical());i0.ɵɵadvance(1);i0.ɵɵproperty("ngIf",!t.isVertical())}},directives:[i2.NgIf,i2.NgStyle],encapsulation:2});return t}(integralui_core_1.IntegralUIBaseComponent);exports.IntegralUIScrollBar=IntegralUIScrollBar;