UNPKG

ngx-bootstrap

Version:
2 lines 3.59 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/forms"),require("@angular/common"),require("@angular/core")):"function"==typeof define&&define.amd?define("ngx-bootstrap/rating",["exports","@angular/forms","@angular/common","@angular/core"],t):t((e["ngx-bootstrap"]=e["ngx-bootstrap"]||{},e["ngx-bootstrap"].rating={}),e.ng.forms,e.ng.common,e.ng.core)}(this,function(e,t,n,o){"use strict";var r={provide:t.NG_VALUE_ACCESSOR,useExisting:o.forwardRef(function(){return i}),multi:!0},i=function(){function e(e){this.changeDetection=e,this.max=5,this.onHover=new o.EventEmitter,this.onLeave=new o.EventEmitter,this.onChange=Function.prototype,this.onTouched=Function.prototype}return e.prototype.onKeydown=function(e){if(-1!==[37,38,39,40].indexOf(e.which)){e.preventDefault(),e.stopPropagation();var t=38===e.which||39===e.which?1:-1;this.rate(this.value+t)}},e.prototype.ngOnInit=function(){this.max="undefined"!=typeof this.max?this.max:5,this.titles="undefined"!=typeof this.titles&&0<this.titles.length?this.titles:[],this.range=this.buildTemplateObjects(this.max)},e.prototype.writeValue=function(e){if(e%1!==e)return this.value=Math.round(e),this.preValue=e,void this.changeDetection.markForCheck();this.preValue=e,this.value=e,this.changeDetection.markForCheck()},e.prototype.enter=function(e){this.readonly||(this.value=e,this.changeDetection.markForCheck(),this.onHover.emit(e))},e.prototype.reset=function(){this.value=this.preValue,this.changeDetection.markForCheck(),this.onLeave.emit(this.value)},e.prototype.registerOnChange=function(e){this.onChange=e},e.prototype.registerOnTouched=function(e){this.onTouched=e},e.prototype.rate=function(e){!this.readonly&&0<=e&&e<=this.range.length&&(this.writeValue(e),this.onChange(e))},e.prototype.buildTemplateObjects=function(e){for(var t=[],n=0;n<e;n++)t.push({index:n,title:this.titles[n]||n+1});return t},e.decorators=[{type:o.Component,args:[{selector:"rating",template:'<span (mouseleave)="reset()" (keydown)="onKeydown($event)" tabindex="0"\n role="slider" aria-valuemin="0" [attr.aria-valuemax]="range.length"\n [attr.aria-valuenow]="value">\n <ng-template #star let-value="value" let-index="index">{{ index < value ? \'&#9733;\' : \'&#9734;\' }}</ng-template>\n <ng-template ngFor let-r [ngForOf]="range" let-index="index">\n <span class="sr-only">({{ index < value ? \'*\' : \' \' }})</span>\n <span class="bs-rating-star"\n (mouseenter)="enter(index + 1)"\n (click)="rate(index + 1)"\n [title]="r.title"\n [style.cursor]="readonly ? \'default\' : \'pointer\'"\n [class.active]="index < value">\n <ng-template [ngTemplateOutlet]="customTemplate || star"\n [ngTemplateOutletContext]="{index: index, value: value}">\n </ng-template>\n </span>\n </ng-template>\n</span>\n',providers:[r],changeDetection:o.ChangeDetectionStrategy.OnPush}]}],e.ctorParameters=function(){return[{type:o.ChangeDetectorRef}]},e.propDecorators={max:[{type:o.Input}],readonly:[{type:o.Input}],titles:[{type:o.Input}],customTemplate:[{type:o.Input}],onHover:[{type:o.Output}],onLeave:[{type:o.Output}],onKeydown:[{type:o.HostListener,args:["keydown",["$event"]]}]},e}(),a=function(){function e(){}return e.forRoot=function(){return{ngModule:e,providers:[]}},e.decorators=[{type:o.NgModule,args:[{imports:[n.CommonModule],declarations:[i],exports:[i]}]}],e}();e.RatingComponent=i,e.RatingModule=a,e.ɵa=r,Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=ngx-bootstrap-rating.umd.min.js.map