import { forwardRef, EventEmitter, Component, ChangeDetectionStrategy, ChangeDetectorRef, Input, Output, HostListener, NgModule } from '@angular/core'; import { NG_VALUE_ACCESSOR } from '@angular/forms'; import { CommonModule } from '@angular/common'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const RATING_CONTROL_VALUE_ACCESSOR = { provide: NG_VALUE_ACCESSOR, /* tslint:disable-next-line: no-use-before-declare */ useExisting: forwardRef((/** * @return {?} */ () => RatingComponent)), multi: true }; class RatingComponent { /** * @param {?} changeDetection */ constructor(changeDetection) { this.changeDetection = changeDetection; /** * number of icons */ this.max = 5; /** * fired when icon selected, $event:number equals to selected rating */ this.onHover = new EventEmitter(); /** * fired when icon selected, $event:number equals to previous rating value */ this.onLeave = new EventEmitter(); // tslint:disable-next-line:no-any this.onChange = Function.prototype; // tslint:disable-next-line:no-any this.onTouched = Function.prototype; } /** * @param {?} event * @return {?} */ onKeydown(event) { /* tslint:disable-next-line: deprecation */ if ([37, 38, 39, 40].indexOf(event.which) === -1) { return; } event.preventDefault(); event.stopPropagation(); /* tslint:disable-next-line: deprecation */ /** @type {?} */ const sign = event.which === 38 || event.which === 39 ? 1 : -1; this.rate(this.value + sign); } /** * @return {?} */ ngOnInit() { this.max = typeof this.max !== 'undefined' ? this.max : 5; this.titles = typeof this.titles !== 'undefined' && this.titles.length > 0 ? this.titles : []; this.range = this.buildTemplateObjects(this.max); } // model -> view /** * @param {?} value * @return {?} */ writeValue(value) { if (value % 1 !== value) { this.value = Math.round(value); this.preValue = value; this.changeDetection.markForCheck(); return; } this.preValue = value; this.value = value; this.changeDetection.markForCheck(); } /** * @param {?} value * @return {?} */ enter(value) { if (!this.readonly) { this.value = value; this.changeDetection.markForCheck(); this.onHover.emit(value); } } /** * @return {?} */ reset() { this.value = this.preValue; this.changeDetection.markForCheck(); this.onLeave.emit(this.value); } /** * @param {?} fn * @return {?} */ registerOnChange(fn) { this.onChange = fn; } /** * @param {?} fn * @return {?} */ registerOnTouched(fn) { this.onTouched = fn; } /** * @param {?} value * @return {?} */ rate(value) { if (!this.readonly && value >= 0 && value <= this.range.length) { this.writeValue(value); this.onChange(value); } } /** * @protected * @param {?} max * @return {?} */ buildTemplateObjects(max) { /** @type {?} */ const result = []; for (let i = 0; i < max; i++) { result.push({ index: i, title: this.titles[i] || i + 1 }); } return result; } } RatingComponent.decorators = [ { type: Component, args: [{ selector: 'rating', template: "\n {{ index < value ? '★' : '☆' }}\n \n ({{ index < value ? '*' : ' ' }})\n \n \n \n \n \n\n", providers: [RATING_CONTROL_VALUE_ACCESSOR], changeDetection: ChangeDetectionStrategy.OnPush }] } ]; /** @nocollapse */ RatingComponent.ctorParameters = () => [ { type: ChangeDetectorRef } ]; RatingComponent.propDecorators = { max: [{ type: Input }], readonly: [{ type: Input }], titles: [{ type: Input }], customTemplate: [{ type: Input }], onHover: [{ type: Output }], onLeave: [{ type: Output }], onKeydown: [{ type: HostListener, args: ['keydown', ['$event'],] }] }; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class RatingModule { /** * @return {?} */ static forRoot() { return { ngModule: RatingModule, providers: [] }; } } RatingModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule], declarations: [RatingComponent], exports: [RatingComponent] },] } ]; export { RatingComponent, RatingModule, RATING_CONTROL_VALUE_ACCESSOR as ɵa }; //# sourceMappingURL=ngx-bootstrap-rating.js.map