UNPKG

6.33 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('@angular/forms')) :
3 typeof define === 'function' && define.amd ? define('primeng/rating', ['exports', '@angular/core', '@angular/common', '@angular/forms'], factory) :
4 (global = global || self, factory((global.primeng = global.primeng || {}, global.primeng.rating = {}), global.ng.core, global.ng.common, global.ng.forms));
5}(this, (function (exports, core, common, forms) { 'use strict';
6
7 var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
8 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
10 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
11 return c > 3 && r && Object.defineProperty(target, key, r), r;
12 };
13 var RATING_VALUE_ACCESSOR = {
14 provide: forms.NG_VALUE_ACCESSOR,
15 useExisting: core.forwardRef(function () { return Rating; }),
16 multi: true
17 };
18 var Rating = /** @class */ (function () {
19 function Rating(cd) {
20 this.cd = cd;
21 this.stars = 5;
22 this.cancel = true;
23 this.iconOnClass = 'pi pi-star';
24 this.iconOffClass = 'pi pi-star-o';
25 this.iconCancelClass = 'pi pi-ban';
26 this.onRate = new core.EventEmitter();
27 this.onCancel = new core.EventEmitter();
28 this.onModelChange = function () { };
29 this.onModelTouched = function () { };
30 }
31 Rating.prototype.ngOnInit = function () {
32 this.starsArray = [];
33 for (var i = 0; i < this.stars; i++) {
34 this.starsArray[i] = i;
35 }
36 };
37 Rating.prototype.rate = function (event, i) {
38 if (!this.readonly && !this.disabled) {
39 this.value = (i + 1);
40 this.onModelChange(this.value);
41 this.onModelTouched();
42 this.onRate.emit({
43 originalEvent: event,
44 value: (i + 1)
45 });
46 }
47 event.preventDefault();
48 };
49 Rating.prototype.clear = function (event) {
50 if (!this.readonly && !this.disabled) {
51 this.value = null;
52 this.onModelChange(this.value);
53 this.onModelTouched();
54 this.onCancel.emit(event);
55 }
56 event.preventDefault();
57 };
58 Rating.prototype.writeValue = function (value) {
59 this.value = value;
60 this.cd.detectChanges();
61 };
62 Rating.prototype.registerOnChange = function (fn) {
63 this.onModelChange = fn;
64 };
65 Rating.prototype.registerOnTouched = function (fn) {
66 this.onModelTouched = fn;
67 };
68 Rating.prototype.setDisabledState = function (val) {
69 this.disabled = val;
70 };
71 Rating.ctorParameters = function () { return [
72 { type: core.ChangeDetectorRef }
73 ]; };
74 __decorate([
75 core.Input()
76 ], Rating.prototype, "disabled", void 0);
77 __decorate([
78 core.Input()
79 ], Rating.prototype, "readonly", void 0);
80 __decorate([
81 core.Input()
82 ], Rating.prototype, "stars", void 0);
83 __decorate([
84 core.Input()
85 ], Rating.prototype, "cancel", void 0);
86 __decorate([
87 core.Input()
88 ], Rating.prototype, "iconOnClass", void 0);
89 __decorate([
90 core.Input()
91 ], Rating.prototype, "iconOnStyle", void 0);
92 __decorate([
93 core.Input()
94 ], Rating.prototype, "iconOffClass", void 0);
95 __decorate([
96 core.Input()
97 ], Rating.prototype, "iconOffStyle", void 0);
98 __decorate([
99 core.Input()
100 ], Rating.prototype, "iconCancelClass", void 0);
101 __decorate([
102 core.Input()
103 ], Rating.prototype, "iconCancelStyle", void 0);
104 __decorate([
105 core.Output()
106 ], Rating.prototype, "onRate", void 0);
107 __decorate([
108 core.Output()
109 ], Rating.prototype, "onCancel", void 0);
110 Rating = __decorate([
111 core.Component({
112 selector: 'p-rating',
113 template: "\n <div class=\"ui-rating\" [ngClass]=\"{'ui-state-disabled': disabled}\">\n <a [attr.tabindex]=\"disabled ? null : '0'\" *ngIf=\"cancel\" (click)=\"clear($event)\" (keydown.enter)=\"clear($event)\" class=\"ui-rating-cancel\">\n <span class=\"ui-rating-icon\" [ngClass]=\"iconCancelClass\" [ngStyle]=\"iconCancelStyle\"></span>\n </a>\n <a [attr.tabindex]=\"disabled ? null : '0'\" *ngFor=\"let star of starsArray;let i=index\" (click)=\"rate($event,i)\" (keydown.enter)=\"rate($event,i)\">\n <span class=\"ui-rating-icon\" \n [ngClass]=\"(!value || i >= value) ? iconOffClass : iconOnClass\"\n [ngStyle]=\"(!value || i >= value) ? iconOffStyle : iconOnStyle\"\n ></span>\n </a>\n </div>\n ",
114 providers: [RATING_VALUE_ACCESSOR],
115 changeDetection: core.ChangeDetectionStrategy.Default
116 })
117 ], Rating);
118 return Rating;
119 }());
120 var RatingModule = /** @class */ (function () {
121 function RatingModule() {
122 }
123 RatingModule = __decorate([
124 core.NgModule({
125 imports: [common.CommonModule],
126 exports: [Rating],
127 declarations: [Rating]
128 })
129 ], RatingModule);
130 return RatingModule;
131 }());
132
133 exports.RATING_VALUE_ACCESSOR = RATING_VALUE_ACCESSOR;
134 exports.Rating = Rating;
135 exports.RatingModule = RatingModule;
136
137 Object.defineProperty(exports, '__esModule', { value: true });
138
139})));
140//# sourceMappingURL=primeng-rating.umd.js.map