UNPKG

4.06 kBJavaScriptView Raw
1!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/forms"),require("@angular/common")):"function"==typeof define&&define.amd?define("ngx-bootstrap/rating",["exports","@angular/core","@angular/forms","@angular/common"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self)["ngx-bootstrap"]=e["ngx-bootstrap"]||{},e["ngx-bootstrap"].rating={}),e.ng.core,e.ng.forms,e.ng.common)}(this,(function(e,t,n,o){"use strict";var r=function(){this.ariaLabel="rating"};r.ɵprov=t.ɵɵdefineInjectable({factory:function(){return new r},token:r,providedIn:"root"}),r.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}];var a={provide:n.NG_VALUE_ACCESSOR,useExisting:t.forwardRef((function(){return i})),multi:!0},i=function(){function e(e,n){this.changeDetection=e,this.max=5,this.readonly=!1,this.titles=[],this.onHover=new t.EventEmitter,this.onLeave=new t.EventEmitter,this.onChange=Function.prototype,this.onTouched=Function.prototype,this.ariaLabel="rating",this.range=[],this.value=0,Object.assign(this,n)}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=this.max||5,this.titles=void 0!==this.titles&&this.titles.length>0?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(){"number"==typeof this.preValue&&(this.value=Math.round(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&&this.range&&e>=0&&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}();i.decorators=[{type:t.Component,args:[{selector:"rating",template:'<span (mouseleave)="reset()" (keydown)="onKeydown($event)" tabindex="0"\n role="slider" aria-valuemin="0"\n [attr.aria-label]="ariaLabel"\n [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 visually-hidden">({{ 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:[a],changeDetection:t.ChangeDetectionStrategy.OnPush}]}],i.ctorParameters=function(){return[{type:t.ChangeDetectorRef},{type:r}]},i.propDecorators={max:[{type:t.Input}],readonly:[{type:t.Input}],titles:[{type:t.Input}],customTemplate:[{type:t.Input}],onHover:[{type:t.Output}],onLeave:[{type:t.Output}],onKeydown:[{type:t.HostListener,args:["keydown",["$event"]]}]};var s=function(){function e(){}return e.forRoot=function(){return{ngModule:e,providers:[]}},e}();s.decorators=[{type:t.NgModule,args:[{imports:[o.CommonModule],declarations:[i],exports:[i]}]}],e.RatingComponent=i,e.RatingConfig=r,e.RatingModule=s,e.ɵa=a,Object.defineProperty(e,"__esModule",{value:!0})}));
2//# sourceMappingURL=ngx-bootstrap-rating.umd.min.js.map
\No newline at end of file