@lidorsystems/integralui-web
Version:
IntegralUI Web - Advanced UI Components for Angular
15 lines (12 loc) • 14.8 kB
JavaScript
/*
filename: integralui.numeric-updown.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 n(){this.constructor=t}t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}();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"),forms_1=require("@angular/forms"),i0=require("@angular/core"),i1=require("../services/integralui.common.service"),i2=require("@angular/common"),_c0=["ctrlValue"],_c1=["inboundButtons"],_c2=["leftrightButtons"],_c3=["topBottomButtons"],_c4=["topBottomButtonsChild"],_c5=function(e){return{"margin-top":e}},_c6=function(e){return{width:e}};function IntegralUINumericUpDown_span_2_Template(e,t){if(1&e){var i=i0.ɵɵgetCurrentView();i0.ɵɵelementStart(0,"span");i0.ɵɵelementStart(1,"div",4,5);i0.ɵɵlistener("click",function(){i0.ɵɵrestoreView(i);return i0.ɵɵnextContext().decreaseValue()})("mousedown",function(e){i0.ɵɵrestoreView(i);return i0.ɵɵnextContext().onMouseDown(e)})("mouseup",function(e){i0.ɵɵrestoreView(i);return i0.ɵɵnextContext().onMouseUp(e)});i0.ɵɵelement(3,"span",6);i0.ɵɵelementEnd();i0.ɵɵelementStart(4,"div",7,8);i0.ɵɵtext(6);i0.ɵɵelementEnd();i0.ɵɵelementStart(7,"div",9);i0.ɵɵlistener("click",function(){i0.ɵɵrestoreView(i);return i0.ɵɵnextContext().increaseValue()})("mousedown",function(e){i0.ɵɵrestoreView(i);return i0.ɵɵnextContext().onMouseDown(e,!0)})("mouseup",function(e){i0.ɵɵrestoreView(i);return i0.ɵɵnextContext().onMouseUp(e)});i0.ɵɵelement(8,"span",10);i0.ɵɵelementEnd();i0.ɵɵelementEnd()}if(2&e){var n=i0.ɵɵnextContext();i0.ɵɵadvance(1);i0.ɵɵproperty("ngStyle",i0.ɵɵpureFunction1(4,_c5,n.leftRightMarginTop+"px"));i0.ɵɵadvance(3);i0.ɵɵproperty("ngStyle",i0.ɵɵpureFunction1(6,_c6,n.ctrlValueWidth+"px"));i0.ɵɵadvance(2);i0.ɵɵtextInterpolate(n.value);i0.ɵɵadvance(1);i0.ɵɵproperty("ngStyle",i0.ɵɵpureFunction1(8,_c5,n.leftRightMarginTop+"px"))}}var _c7=function(e){return{"margin-left":e}};function IntegralUINumericUpDown_span_3_Template(e,t){if(1&e){var i=i0.ɵɵgetCurrentView();i0.ɵɵelementStart(0,"span");i0.ɵɵelementStart(1,"div",11,12);i0.ɵɵlistener("click",function(){i0.ɵɵrestoreView(i);return i0.ɵɵnextContext().increaseValue()})("mousedown",function(e){i0.ɵɵrestoreView(i);return i0.ɵɵnextContext().onMouseDown(e,!0)})("mouseup",function(e){i0.ɵɵrestoreView(i);return i0.ɵɵnextContext().onMouseUp(e)});i0.ɵɵelement(3,"span",13,14);i0.ɵɵelementEnd();i0.ɵɵelementStart(5,"div",15,8);i0.ɵɵtext(7);i0.ɵɵelementEnd();i0.ɵɵelementStart(8,"div",11);i0.ɵɵlistener("click",function(){i0.ɵɵrestoreView(i);return i0.ɵɵnextContext().decreaseValue()})("mousedown",function(e){i0.ɵɵrestoreView(i);return i0.ɵɵnextContext().onMouseDown(e)})("mouseup",function(e){i0.ɵɵrestoreView(i);return i0.ɵɵnextContext().onMouseUp(e)});i0.ɵɵelement(9,"span",16);i0.ɵɵelementEnd();i0.ɵɵelementEnd()}if(2&e){var n=i0.ɵɵnextContext();i0.ɵɵadvance(3);i0.ɵɵproperty("ngStyle",i0.ɵɵpureFunction1(3,_c7,n.topBotomMarginLeft+"px"));i0.ɵɵadvance(4);i0.ɵɵtextInterpolate(n.value);i0.ɵɵadvance(2);i0.ɵɵproperty("ngStyle",i0.ɵɵpureFunction1(5,_c7,n.topBotomMarginLeft+"px"))}}function IntegralUINumericUpDown_span_4_Template(e,t){if(1&e){var i=i0.ɵɵgetCurrentView();i0.ɵɵelementStart(0,"span");i0.ɵɵelementStart(1,"div",17,18);i0.ɵɵelementStart(3,"div",19);i0.ɵɵlistener("click",function(){i0.ɵɵrestoreView(i);return i0.ɵɵnextContext().increaseValue()})("mousedown",function(e){i0.ɵɵrestoreView(i);return i0.ɵɵnextContext().onMouseDown(e,!0)})("mouseup",function(e){i0.ɵɵrestoreView(i);return i0.ɵɵnextContext().onMouseUp(e)});i0.ɵɵelement(4,"span",20);i0.ɵɵelementEnd();i0.ɵɵelementStart(5,"div",19);i0.ɵɵlistener("click",function(){i0.ɵɵrestoreView(i);return i0.ɵɵnextContext().decreaseValue()})("mousedown",function(e){i0.ɵɵrestoreView(i);return i0.ɵɵnextContext().onMouseDown(e)})("mouseup",function(e){i0.ɵɵrestoreView(i);return i0.ɵɵnextContext().onMouseUp(e)});i0.ɵɵelement(6,"span",21);i0.ɵɵelementEnd();i0.ɵɵelementEnd();i0.ɵɵelementStart(7,"div",22,8);i0.ɵɵtext(9);i0.ɵɵelementEnd();i0.ɵɵelementEnd()}if(2&e){var n=i0.ɵɵnextContext();i0.ɵɵadvance(7);i0.ɵɵproperty("ngStyle",i0.ɵɵpureFunction1(2,_c6,n.ctrlValueWidth+"px"));i0.ɵɵadvance(2);i0.ɵɵtextInterpolate(n.value)}}var IntegralUINumericUpDown=function(e){__extends(t,e);function t(t,i){var n=e.call(this,t,i)||this;n.elemRef=t;n.commonService=i;n.ctrlMaxValue=100;n.ctrlMinValue=0;n.currentStep=1;n.currentAccelerator=0;n.valueTimer=null;n.valueCount=0;n.isChangeActive=!1;n.stopTimer=!0;n.contentSize={width:0,height:0};n.ctrlValueWidth=0;n.leftRightMarginTop=0;n.topBotomMarginLeft=0;n.currentDisplayMode=integralui_core_1.IntegralUINumericDisplayMode.InBound;n.mouseWheelSpeed=integralui_core_1.IntegralUISpeedMode.Normal;n.displayModeChanged=new core_1.EventEmitter;return n}Object.defineProperty(t.prototype,"accelerator",{get:function(){return this.currentAccelerator},set:function(e){if(this.currentAccelerator!=e)this.currentAccelerator=e},enumerable:!0,configurable:!0});Object.defineProperty(t.prototype,"displayMode",{get:function(){return this.currentDisplayMode},set:function(e){if(this.currentDisplayMode!=e){this.currentDisplayMode=e;this.updateLayout();this.displayModeChanged.emit(null)}},enumerable:!0,configurable:!0});Object.defineProperty(t.prototype,"max",{get:function(){return this.ctrlMaxValue},set:function(e){e=Math.floor(e);if(this.ctrlMaxValue!=e)this.ctrlMaxValue=e},enumerable:!0,configurable:!0});Object.defineProperty(t.prototype,"min",{get:function(){return this.ctrlMinValue},set:function(e){e=Math.floor(e);if(this.ctrlMinValue!=e)this.ctrlMinValue=e},enumerable:!0,configurable:!0});Object.defineProperty(t.prototype,"step",{get:function(){return this.currentStep},set:function(e){if(this.currentStep!=e)this.currentStep=e},enumerable:!0,configurable:!0});Object.defineProperty(t.prototype,"value",{get:function(){return Math.floor(this.currentValue)},set:function(e){e=Math.floor(e);if((e=Math.max(this.ctrlMinValue,Math.min(this.ctrlMaxValue,e)))!==this.currentValue&&e>=this.ctrlMinValue&&e<=this.ctrlMaxValue){this.currentValue=e;this.onChange(e);this.processValueChange();this.valueChanged.emit({value:this.currentValue})}},enumerable:!0,configurable:!0});t.prototype.ngOnInit=function(){this.generalClassName="iui-numeric";this.contentClassName=this.generalClassName+"-content";this.initStyle()};t.prototype.ngAfterViewInit=function(){this.updateLayout()};t.prototype.ngOnDestroy=function(){if(this.valueTimer)clearInterval(this.valueTimer)};t.prototype.ngAfterContentChecked=function(){if(1==this.autoUpdate){this.clientRect={width:this.elemRef.nativeElement.firstElementChild.clientWidth,height:this.elemRef.nativeElement.firstElementChild.clientHeight};if(this.clientRect.width!=this.prevClientRect.width){this.updateLayout();this.prevClientRect.width=this.clientRect.width}else if(this.clientRect.height!=this.prevClientRect.height){this.updateLayout();this.prevClientRect.height=this.clientRect.height}}};t.prototype.getContentWidth=function(){return this.contentSize.width};t.prototype.updateLayout=function(){var e=this,t=setTimeout(function(){var i=e.commonService.getPadding(e.elemRef.nativeElement.firstElementChild);e.clientRect={width:e.elemRef.nativeElement.firstElementChild.clientWidth-(i.left+i.right),height:e.elemRef.nativeElement.firstElementChild.clientHeight-(i.top+i.bottom)};e.contentSize={width:e.currentValue<100?Math.floor(e.clientRect.width*e.currentValue/100):e.clientRect.width,height:e.clientRect.height};var n=e.commonService.getBorderWidth(e.valueElem.nativeElement),r=e.commonService.getMargin(e.valueElem.nativeElement),o=e.commonService.getPadding(e.valueElem.nativeElement);switch(e.displayMode){case integralui_core_1.IntegralUINumericDisplayMode.LeftRight:if(e.leftrightButtonsElem){e.ctrlValueWidth=e.clientRect.width-(n.left+n.right+r.left+r.right+o.left+o.right+2*e.leftrightButtonsElem.nativeElement.offsetWidth);if(e.valueElem)e.leftRightMarginTop=(e.valueElem.nativeElement.offsetHeight-e.leftrightButtonsElem.nativeElement.offsetHeight)/2}break;case integralui_core_1.IntegralUINumericDisplayMode.UpDown:if(e.topBottomButtonsChildElem&&e.valueElem)e.topBotomMarginLeft=(e.valueElem.nativeElement.offsetWidth-e.topBottomButtonsChildElem.nativeElement.offsetWidth)/2;break;default:if(e.inboundButtonsElem)e.ctrlValueWidth=e.clientRect.width-(n.left+n.right+r.left+r.right+o.left+o.right+e.inboundButtonsElem.nativeElement.offsetWidth)}clearTimeout(t)},1)};t.prototype.changeValueTimerElapsed=function(e){if(0==this.valueCount)this.valueCount=1;this.valueCount+=this.currentAccelerator*this.step;this.stopTimer=!1;this.changeValue(e);if(this.stopTimer){clearInterval(this.valueTimer);this.isChangeActive=!1}};t.prototype.changeValue=function(e){if(e)if(this.value+this.valueCount<this.ctrlMaxValue)this.value+=this.valueCount;else{this.stopTimer=!0;this.value=this.ctrlMaxValue}else if(this.value-this.valueCount>0)this.value-=this.valueCount;else{this.stopTimer=!0;this.value=this.ctrlMinValue}};t.prototype.decreaseValue=function(){this.value-=this.step};t.prototype.increaseValue=function(){this.value+=this.step};t.prototype.startChange=function(e){var t=this;if(t.valueTimer)clearInterval(this.valueTimer);t.valueCount=0;t.isChangeActive=!0;t.valueTimer=setInterval(function(){t.changeValueTimerElapsed(e)},100)};t.prototype.stopChange=function(){if(this.valueTimer)clearInterval(this.valueTimer);this.isChangeActive=!1};t.prototype.ctrlMouseWheel=function(e){if(this.isEnabled){e.preventDefault();var t=Math.max(-1,Math.min(1,e.wheelDelta||-e.detail)),i=5;switch(this.mouseWheelSpeed){case integralui_core_1.IntegralUISpeedMode.VerySlow:i=1;break;case integralui_core_1.IntegralUISpeedMode.Slow:i=2;break;case integralui_core_1.IntegralUISpeedMode.Fast:i=10;break;case integralui_core_1.IntegralUISpeedMode.VeryFast:i=100}var n=this.step*i;this.value+=n*t;e.stopPropagation()}};t.prototype.onMouseDown=function(e,t){this.startChange(t)};t.prototype.onMouseUp=function(e){this.stopChange()};t.prototype.getControlStyle=function(){var e={};if(this.ctrlSize.width>0)e.width=this.ctrlSize.width+"px";if(this.ctrlSize.height>0)e.height=this.ctrlSize.height+"px";return e};t.ɵfac=function(e){return new(e||t)(i0.ɵɵdirectiveInject(i0.ElementRef),i0.ɵɵdirectiveInject(i1.IntegralUICommonService))};t.ɵcmp=i0.ɵɵdefineComponent({type:t,selectors:[["iui-numeric-updown"]],viewQuery:function(e,t){if(1&e){i0.ɵɵviewQuery(_c0,!0);i0.ɵɵviewQuery(_c1,!0);i0.ɵɵviewQuery(_c2,!0);i0.ɵɵviewQuery(_c3,!0);i0.ɵɵviewQuery(_c4,!0)}if(2&e){var i;i0.ɵɵqueryRefresh(i=i0.ɵɵloadQuery())&&(t.valueElem=i.first);i0.ɵɵqueryRefresh(i=i0.ɵɵloadQuery())&&(t.inboundButtonsElem=i.first);i0.ɵɵqueryRefresh(i=i0.ɵɵloadQuery())&&(t.leftrightButtonsElem=i.first);i0.ɵɵqueryRefresh(i=i0.ɵɵloadQuery())&&(t.topBottomButtonsElem=i.first);i0.ɵɵqueryRefresh(i=i0.ɵɵloadQuery())&&(t.topBottomButtonsChildElem=i.first)}},inputs:{autoUpdate:"autoUpdate",controlStyle:"controlStyle",data:"data",enabled:"enabled",name:"name",size:"size",state:"state",value:"value",accelerator:"accelerator",displayMode:"displayMode",max:"max",min:"min",mouseWheelSpeed:"mouseWheelSpeed",step:"step"},outputs:{valueChanged:"valueChanged",displayModeChanged:"displayModeChanged"},features:[i0.ɵɵProvidersFeature([{provide:forms_1.NG_VALUE_ACCESSOR,useExisting:core_1.forwardRef(function(){return t}),multi:!0}]),i0.ɵɵInheritDefinitionFeature],decls:5,vars:5,consts:[["draggable","true",3,"ngClass","ngStyle","dragstart","DOMMouseScroll","mousewheel"],[3,"ngSwitch"],[4,"ngSwitchCase"],[4,"ngSwitchDefault"],[1,"iui-numeric-leftright-buttons",2,"float","left",3,"ngStyle","click","mousedown","mouseup"],["leftrightButtons",""],[1,"iui-numeric-leftright-decrease"],[1,"iui-numeric-leftright-value",3,"ngStyle"],["ctrlValue",""],[1,"iui-numeric-leftright-buttons",2,"float","right",3,"ngStyle","click","mousedown","mouseup"],[1,"iui-numeric-leftright-increase"],[1,"iui-numeric-updown-buttons",3,"click","mousedown","mouseup"],["topBottomButtons",""],[1,"iui-numeric-updown-increase",3,"ngStyle"],["topBottomButtonsChild",""],[1,"iui-numeric-updown-value"],[1,"iui-numeric-updown-decrease",3,"ngStyle"],[1,"iui-numeric-inbound-buttons"],["inboundButtons",""],[1,"iui-numeric-inbound-btn",3,"click","mousedown","mouseup"],[1,"iui-numeric-inbound-button-up"],[1,"iui-numeric-inbound-button-down"],[1,"iui-numeric-inbound-value",3,"ngStyle"]],template:function(e,t){if(1&e){i0.ɵɵelementStart(0,"div",0);i0.ɵɵlistener("dragstart",function(e){return t.preventDragStart(e)})("DOMMouseScroll",function(e){return t.ctrlMouseWheel(e)})("mousewheel",function(e){return t.ctrlMouseWheel(e)});i0.ɵɵelementStart(1,"span",1);i0.ɵɵtemplate(2,IntegralUINumericUpDown_span_2_Template,9,10,"span",2);i0.ɵɵtemplate(3,IntegralUINumericUpDown_span_3_Template,10,7,"span",2);i0.ɵɵtemplate(4,IntegralUINumericUpDown_span_4_Template,10,4,"span",3);i0.ɵɵelementEnd();i0.ɵɵelementEnd()}if(2&e){i0.ɵɵproperty("ngClass",t.getControlClass())("ngStyle",t.getControlStyle());i0.ɵɵadvance(1);i0.ɵɵproperty("ngSwitch",t.displayMode);i0.ɵɵadvance(1);i0.ɵɵproperty("ngSwitchCase",1);i0.ɵɵadvance(1);i0.ɵɵproperty("ngSwitchCase",2)}},directives:[i2.NgClass,i2.NgStyle,i2.NgSwitch,i2.NgSwitchCase,i2.NgSwitchDefault],encapsulation:2});return t}(integralui_core_1.IntegralUIBaseValueComponent);exports.IntegralUINumericUpDown=IntegralUINumericUpDown;