UNPKG

11.9 kBJavaScriptView Raw
1!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common"),require("primeng/dom"),require("@angular/forms")):"function"==typeof define&&define.amd?define("primeng/slider",["exports","@angular/core","@angular/common","primeng/dom","@angular/forms"],t):t(((e=e||self).primeng=e.primeng||{},e.primeng.slider={}),e.ng.core,e.ng.common,e.primeng.dom,e.ng.forms)}(this,(function(e,t,n,i,a){"use strict";var l=this&&this.__decorate||function(e,t,n,i){var a,l=arguments.length,o=l<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(a=e[s])&&(o=(l<3?a(o):l>3?a(t,n,o):a(t,n))||o);return l>3&&o&&Object.defineProperty(t,n,o),o},o={provide:a.NG_VALUE_ACCESSOR,useExisting:t.forwardRef((function(){return s})),multi:!0},s=function(){function e(e,n,i,a){this.el=e,this.renderer=n,this.ngZone=i,this.cd=a,this.min=0,this.max=100,this.orientation="horizontal",this.tabindex=0,this.onChange=new t.EventEmitter,this.onSlideEnd=new t.EventEmitter,this.handleValues=[],this.onModelChange=function(){},this.onModelTouched=function(){},this.handleIndex=0}return e.prototype.onMouseDown=function(e,t){this.disabled||(this.dragging=!0,this.updateDomData(),this.sliderHandleClick=!0,this.handleIndex=t,this.bindDragListeners(),e.target.focus(),e.preventDefault())},e.prototype.onTouchStart=function(e,t){if(!this.disabled){var n=e.changedTouches[0];this.startHandleValue=this.range?this.handleValues[t]:this.handleValue,this.dragging=!0,this.handleIndex=t,"horizontal"===this.orientation?(this.startx=parseInt(n.clientX,10),this.barWidth=this.el.nativeElement.children[0].offsetWidth):(this.starty=parseInt(n.clientY,10),this.barHeight=this.el.nativeElement.children[0].offsetHeight),e.preventDefault()}},e.prototype.onTouchMove=function(e,t){if(!this.disabled){var n=e.changedTouches[0],i=0;i="horizontal"===this.orientation?Math.floor(100*(parseInt(n.clientX,10)-this.startx)/this.barWidth)+this.startHandleValue:Math.floor(100*(this.starty-parseInt(n.clientY,10))/this.barHeight)+this.startHandleValue,this.setValueFromHandle(e,i),e.preventDefault()}},e.prototype.onTouchEnd=function(e,t){this.disabled||(this.dragging=!1,this.range?this.onSlideEnd.emit({originalEvent:e,values:this.values}):this.onSlideEnd.emit({originalEvent:e,value:this.value}),e.preventDefault())},e.prototype.onBarClick=function(e){this.disabled||(this.sliderHandleClick||(this.updateDomData(),this.handleChange(e)),this.sliderHandleClick=!1)},e.prototype.onHandleKeydown=function(e,t){38==e.which||39==e.which?this.spin(e,1,t):37!=e.which&&40!=e.which||this.spin(e,-1,t)},e.prototype.spin=function(e,t,n){var i=(this.step||1)*t;this.range?(this.handleIndex=n,this.updateValue(this.values[this.handleIndex]+i),this.updateHandleValue()):(this.updateValue(this.value+i),this.updateHandleValue()),e.preventDefault()},e.prototype.handleChange=function(e){var t=this.calculateHandleValue(e);this.setValueFromHandle(e,t)},e.prototype.bindDragListeners=function(){var e=this;this.ngZone.runOutsideAngular((function(){e.dragListener||(e.dragListener=e.renderer.listen("document","mousemove",(function(t){e.dragging&&e.ngZone.run((function(){e.handleChange(t)}))}))),e.mouseupListener||(e.mouseupListener=e.renderer.listen("document","mouseup",(function(t){e.dragging&&(e.dragging=!1,e.ngZone.run((function(){e.range?e.onSlideEnd.emit({originalEvent:t,values:e.values}):e.onSlideEnd.emit({originalEvent:t,value:e.value})})))})))}))},e.prototype.unbindDragListeners=function(){this.dragListener&&this.dragListener(),this.mouseupListener&&this.mouseupListener()},e.prototype.setValueFromHandle=function(e,t){var n=this.getValueFromHandle(t);this.range?this.step?this.handleStepChange(n,this.values[this.handleIndex]):(this.handleValues[this.handleIndex]=t,this.updateValue(n,e)):this.step?this.handleStepChange(n,this.value):(this.handleValue=t,this.updateValue(n,e))},e.prototype.handleStepChange=function(e,t){var n=e-t,i=t;n<0?i=t+Math.ceil(e/this.step-t/this.step)*this.step:n>0&&(i=t+Math.floor(e/this.step-t/this.step)*this.step),this.updateValue(i),this.updateHandleValue()},e.prototype.writeValue=function(e){this.range?this.values=e||[0,0]:this.value=e||0,this.updateHandleValue(),this.cd.markForCheck()},e.prototype.registerOnChange=function(e){this.onModelChange=e},e.prototype.registerOnTouched=function(e){this.onModelTouched=e},e.prototype.setDisabledState=function(e){this.disabled=e},Object.defineProperty(e.prototype,"rangeStartLeft",{get:function(){return this.isVertical()?"auto":this.handleValues[0]+"%"},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rangeStartBottom",{get:function(){return this.isVertical()?this.handleValues[0]+"%":"auto"},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rangeEndLeft",{get:function(){return this.isVertical()?"auto":this.handleValues[1]+"%"},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rangeEndBottom",{get:function(){return this.isVertical()?this.handleValues[1]+"%":"auto"},enumerable:!0,configurable:!0}),e.prototype.isVertical=function(){return"vertical"===this.orientation},e.prototype.updateDomData=function(){var e=this.el.nativeElement.children[0].getBoundingClientRect();this.initX=e.left+i.DomHandler.getWindowScrollLeft(),this.initY=e.top+i.DomHandler.getWindowScrollTop(),this.barWidth=this.el.nativeElement.children[0].offsetWidth,this.barHeight=this.el.nativeElement.children[0].offsetHeight},e.prototype.calculateHandleValue=function(e){return"horizontal"===this.orientation?100*(e.pageX-this.initX)/this.barWidth:100*(this.initY+this.barHeight-e.pageY)/this.barHeight},e.prototype.updateHandleValue=function(){this.range?(this.handleValues[0]=100*(this.values[0]<this.min?0:this.values[0]-this.min)/(this.max-this.min),this.handleValues[1]=100*(this.values[1]>this.max?100:this.values[1]-this.min)/(this.max-this.min)):this.value<this.min?this.handleValue=0:this.value>this.max?this.handleValue=100:this.handleValue=100*(this.value-this.min)/(this.max-this.min)},e.prototype.updateValue=function(e,t){if(this.range){var n=e;0==this.handleIndex?(n<this.min?(n=this.min,this.handleValues[0]=0):n>this.values[1]&&(n=this.values[1],this.handleValues[0]=this.handleValues[1]),this.sliderHandleStart.nativeElement.focus()):(n>this.max?(n=this.max,this.handleValues[1]=100):n<this.values[0]&&(n=this.values[0],this.handleValues[1]=this.handleValues[0]),this.sliderHandleEnd.nativeElement.focus()),this.values[this.handleIndex]=this.getNormalizedValue(n),this.values=this.values.slice(),this.onModelChange(this.values),this.onChange.emit({event:t,values:this.values})}else e<this.min?(e=this.min,this.handleValue=0):e>this.max&&(e=this.max,this.handleValue=100),this.value=this.getNormalizedValue(e),this.onModelChange(this.value),this.onChange.emit({event:t,value:this.value}),this.sliderHandle.nativeElement.focus()},e.prototype.getValueFromHandle=function(e){return(this.max-this.min)*(e/100)+this.min},e.prototype.getDecimalsCount=function(e){return e&&Math.floor(e)!==e&&e.toString().split(".")[1].length||0},e.prototype.getNormalizedValue=function(e){var t=this.getDecimalsCount(this.step);return t>0?+e.toFixed(t):Math.floor(e)},e.prototype.ngOnDestroy=function(){this.unbindDragListeners()},e.ctorParameters=function(){return[{type:t.ElementRef},{type:t.Renderer2},{type:t.NgZone},{type:t.ChangeDetectorRef}]},l([t.Input()],e.prototype,"animate",void 0),l([t.Input()],e.prototype,"disabled",void 0),l([t.Input()],e.prototype,"min",void 0),l([t.Input()],e.prototype,"max",void 0),l([t.Input()],e.prototype,"orientation",void 0),l([t.Input()],e.prototype,"step",void 0),l([t.Input()],e.prototype,"range",void 0),l([t.Input()],e.prototype,"style",void 0),l([t.Input()],e.prototype,"styleClass",void 0),l([t.Input()],e.prototype,"ariaLabelledBy",void 0),l([t.Input()],e.prototype,"tabindex",void 0),l([t.Output()],e.prototype,"onChange",void 0),l([t.Output()],e.prototype,"onSlideEnd",void 0),l([t.ViewChild("sliderHandle")],e.prototype,"sliderHandle",void 0),l([t.ViewChild("sliderHandleStart")],e.prototype,"sliderHandleStart",void 0),l([t.ViewChild("sliderHandleEnd")],e.prototype,"sliderHandleEnd",void 0),e=l([t.Component({selector:"p-slider",template:'\n <div [ngStyle]="style" [class]="styleClass" [ngClass]="{\'ui-slider ui-widget ui-widget-content ui-corner-all\':true,\'ui-state-disabled\':disabled,\n \'ui-slider-horizontal\':orientation == \'horizontal\',\'ui-slider-vertical\':orientation == \'vertical\',\'ui-slider-animate\':animate}"\n (click)="onBarClick($event)">\n <span *ngIf="range && orientation == \'horizontal\'" class="ui-slider-range ui-widget-header ui-corner-all" [ngStyle]="{\'left\':handleValues[0] + \'%\',width: (handleValues[1] - handleValues[0] + \'%\')}"></span>\n <span *ngIf="range && orientation == \'vertical\'" class="ui-slider-range ui-widget-header ui-corner-all" [ngStyle]="{\'bottom\':handleValues[0] + \'%\',height: (handleValues[1] - handleValues[0] + \'%\')}"></span>\n <span *ngIf="!range && orientation==\'vertical\'" class="ui-slider-range ui-slider-range-min ui-widget-header ui-corner-all" [ngStyle]="{\'height\': handleValue + \'%\'}"></span>\n <span *ngIf="!range && orientation==\'horizontal\'" class="ui-slider-range ui-slider-range-min ui-widget-header ui-corner-all" [ngStyle]="{\'width\': handleValue + \'%\'}"></span>\n <span #sliderHandle *ngIf="!range" [attr.tabindex]="tabindex" (keydown)="onHandleKeydown($event)" class="ui-slider-handle ui-state-default ui-corner-all ui-clickable" (mousedown)="onMouseDown($event)" (touchstart)="onTouchStart($event)" (touchmove)="onTouchMove($event)" (touchend)="onTouchEnd($event)"\n [style.transition]="dragging ? \'none\': null" [ngStyle]="{\'left\': orientation == \'horizontal\' ? handleValue + \'%\' : null,\'bottom\': orientation == \'vertical\' ? handleValue + \'%\' : null}"\n [attr.aria-valuemin]="min" [attr.aria-valuenow]="value" [attr.aria-valuemax]="max" [attr.aria-labelledby]="ariaLabelledBy"></span>\n <span #sliderHandleStart *ngIf="range" [attr.tabindex]="tabindex" (keydown)="onHandleKeydown($event,0)" (mousedown)="onMouseDown($event,0)" (touchstart)="onTouchStart($event,0)" (touchmove)="onTouchMove($event,0)" (touchend)="onTouchEnd($event)" [style.transition]="dragging ? \'none\': null" class="ui-slider-handle ui-state-default ui-corner-all ui-clickable" \n [ngStyle]="{\'left\': rangeStartLeft, \'bottom\': rangeStartBottom}" [ngClass]="{\'ui-slider-handle-active\':handleIndex==0}"\n [attr.aria-valuemin]="min" [attr.aria-valuenow]="value ? value[0] : null" [attr.aria-valuemax]="max" [attr.aria-labelledby]="ariaLabelledBy"></span>\n <span #sliderHandleEnd *ngIf="range" [attr.tabindex]="tabindex" (keydown)="onHandleKeydown($event,1)" (mousedown)="onMouseDown($event,1)" (touchstart)="onTouchStart($event,1)" (touchmove)="onTouchMove($event,1)" (touchend)="onTouchEnd($event)" [style.transition]="dragging ? \'none\': null" class="ui-slider-handle ui-state-default ui-corner-all ui-clickable" \n [ngStyle]="{\'left\': rangeEndLeft, \'bottom\': rangeEndBottom}" [ngClass]="{\'ui-slider-handle-active\':handleIndex==1}"\n [attr.aria-valuemin]="min" [attr.aria-valuenow]="value ? value[1] : null" [attr.aria-valuemax]="max" [attr.aria-labelledby]="ariaLabelledBy"></span>\n </div>\n ',providers:[o],changeDetection:t.ChangeDetectionStrategy.Default})],e)}(),r=function(){function e(){}return e=l([t.NgModule({imports:[n.CommonModule],exports:[s],declarations:[s]})],e)}();e.SLIDER_VALUE_ACCESSOR=o,e.Slider=s,e.SliderModule=r,Object.defineProperty(e,"__esModule",{value:!0})}));
2//# sourceMappingURL=primeng-slider.umd.min.js.map
\No newline at end of file