1 | import { ɵɵdefineInjectable, Injectable, forwardRef, EventEmitter, Component, ChangeDetectionStrategy, ChangeDetectorRef, Input, Output, HostListener, NgModule } from '@angular/core';
|
2 | import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
3 | import { CommonModule } from '@angular/common';
|
4 |
|
5 |
|
6 | import * as ɵngcc0 from '@angular/core';
|
7 | import * as ɵngcc1 from '@angular/common';
|
8 |
|
9 | function RatingComponent_ng_template_1_Template(rf, ctx) { if (rf & 1) {
|
10 | ɵngcc0.ɵɵtext(0);
|
11 | } if (rf & 2) {
|
12 | const value_r3 = ctx.value;
|
13 | const index_r4 = ctx.index;
|
14 | ɵngcc0.ɵɵtextInterpolate(index_r4 < value_r3 ? "\u2605" : "\u2606");
|
15 | } }
|
16 | function RatingComponent_ng_template_3_ng_template_3_Template(rf, ctx) { }
|
17 | const _c0 = function (a0, a1) { return { index: a0, value: a1 }; };
|
18 | function RatingComponent_ng_template_3_Template(rf, ctx) { if (rf & 1) {
|
19 | const _r9 = ɵngcc0.ɵɵgetCurrentView();
|
20 | ɵngcc0.ɵɵelementStart(0, "span", 3);
|
21 | ɵngcc0.ɵɵtext(1);
|
22 | ɵngcc0.ɵɵelementEnd();
|
23 | ɵngcc0.ɵɵelementStart(2, "span", 4);
|
24 | ɵngcc0.ɵɵlistener("mouseenter", function RatingComponent_ng_template_3_Template_span_mouseenter_2_listener() { ɵngcc0.ɵɵrestoreView(_r9); const index_r6 = ctx.index; const ctx_r8 = ɵngcc0.ɵɵnextContext(); return ctx_r8.enter(index_r6 + 1); })("click", function RatingComponent_ng_template_3_Template_span_click_2_listener() { ɵngcc0.ɵɵrestoreView(_r9); const index_r6 = ctx.index; const ctx_r10 = ɵngcc0.ɵɵnextContext(); return ctx_r10.rate(index_r6 + 1); });
|
25 | ɵngcc0.ɵɵtemplate(3, RatingComponent_ng_template_3_ng_template_3_Template, 0, 0, "ng-template", 5);
|
26 | ɵngcc0.ɵɵelementEnd();
|
27 | } if (rf & 2) {
|
28 | const r_r5 = ctx.$implicit;
|
29 | const index_r6 = ctx.index;
|
30 | const ctx_r2 = ɵngcc0.ɵɵnextContext();
|
31 | const _r0 = ɵngcc0.ɵɵreference(2);
|
32 | ɵngcc0.ɵɵadvance(1);
|
33 | ɵngcc0.ɵɵtextInterpolate1("(", index_r6 < ctx_r2.value ? "*" : " ", ")");
|
34 | ɵngcc0.ɵɵadvance(1);
|
35 | ɵngcc0.ɵɵstyleProp("cursor", ctx_r2.readonly ? "default" : "pointer");
|
36 | ɵngcc0.ɵɵclassProp("active", index_r6 < ctx_r2.value);
|
37 | ɵngcc0.ɵɵproperty("title", r_r5.title);
|
38 | ɵngcc0.ɵɵadvance(1);
|
39 | ɵngcc0.ɵɵproperty("ngTemplateOutlet", ctx_r2.customTemplate || _r0)("ngTemplateOutletContext", ɵngcc0.ɵɵpureFunction2(8, _c0, index_r6, ctx_r2.value));
|
40 | } }
|
41 | class RatingConfig {
|
42 | constructor() {
|
43 |
|
44 | this.ariaLabel = 'rating';
|
45 | }
|
46 | }
|
47 | RatingConfig.ɵfac = function RatingConfig_Factory(t) { return new (t || RatingConfig)(); };
|
48 | RatingConfig.ɵprov = ɵɵdefineInjectable({ factory: function RatingConfig_Factory() { return new RatingConfig(); }, token: RatingConfig, providedIn: "root" });
|
49 | (function () { (typeof ngDevMode === "undefined" || ngDevMode) && ɵngcc0.ɵsetClassMetadata(RatingConfig, [{
|
50 | type: Injectable,
|
51 | args: [{
|
52 | providedIn: 'root'
|
53 | }]
|
54 | }], function () { return []; }, null); })();
|
55 |
|
56 | const RATING_CONTROL_VALUE_ACCESSOR = {
|
57 | provide: NG_VALUE_ACCESSOR,
|
58 | useExisting: forwardRef(() => RatingComponent),
|
59 | multi: true
|
60 | };
|
61 | class RatingComponent {
|
62 | constructor(changeDetection, config) {
|
63 | this.changeDetection = changeDetection;
|
64 |
|
65 | this.max = 5;
|
66 |
|
67 | this.readonly = false;
|
68 |
|
69 | this.titles = [];
|
70 |
|
71 | this.onHover = new EventEmitter();
|
72 |
|
73 | this.onLeave = new EventEmitter();
|
74 | this.onChange = Function.prototype;
|
75 | this.onTouched = Function.prototype;
|
76 |
|
77 | this.ariaLabel = 'rating';
|
78 | this.range = [];
|
79 | this.value = 0;
|
80 | Object.assign(this, config);
|
81 | }
|
82 | onKeydown(event) {
|
83 | if ([37, 38, 39, 40].indexOf(event.which) === -1) {
|
84 | return;
|
85 | }
|
86 | event.preventDefault();
|
87 | event.stopPropagation();
|
88 | const sign = event.which === 38 || event.which === 39 ? 1 : -1;
|
89 | this.rate(this.value + sign);
|
90 | }
|
91 | ngOnInit() {
|
92 | this.max = this.max || 5;
|
93 | this.titles =
|
94 | typeof this.titles !== 'undefined' && this.titles.length > 0
|
95 | ? this.titles
|
96 | : [];
|
97 | this.range = this.buildTemplateObjects(this.max);
|
98 | }
|
99 |
|
100 | writeValue(value) {
|
101 | if (value % 1 !== value) {
|
102 | this.value = Math.round(value);
|
103 | this.preValue = value;
|
104 | this.changeDetection.markForCheck();
|
105 | return;
|
106 | }
|
107 | this.preValue = value;
|
108 | this.value = value;
|
109 | this.changeDetection.markForCheck();
|
110 | }
|
111 | enter(value) {
|
112 | if (!this.readonly) {
|
113 | this.value = value;
|
114 | this.changeDetection.markForCheck();
|
115 | this.onHover.emit(value);
|
116 | }
|
117 | }
|
118 | reset() {
|
119 | if (typeof this.preValue === 'number') {
|
120 | this.value = Math.round(this.preValue);
|
121 | this.changeDetection.markForCheck();
|
122 | this.onLeave.emit(this.value);
|
123 | }
|
124 | }
|
125 | registerOnChange(fn) {
|
126 | this.onChange = fn;
|
127 | }
|
128 | registerOnTouched(fn) {
|
129 | this.onTouched = fn;
|
130 | }
|
131 | rate(value) {
|
132 | if (!this.readonly && this.range
|
133 | && value >= 0 && value <= this.range.length) {
|
134 | this.writeValue(value);
|
135 | this.onChange(value);
|
136 | }
|
137 | }
|
138 | buildTemplateObjects(max) {
|
139 | const result = [];
|
140 | for (let i = 0; i < max; i++) {
|
141 | result.push({
|
142 | index: i,
|
143 | title: this.titles[i] || i + 1
|
144 | });
|
145 | }
|
146 | return result;
|
147 | }
|
148 | }
|
149 | RatingComponent.ɵfac = function RatingComponent_Factory(t) { return new (t || RatingComponent)(ɵngcc0.ɵɵdirectiveInject(ɵngcc0.ChangeDetectorRef), ɵngcc0.ɵɵdirectiveInject(RatingConfig)); };
|
150 | RatingComponent.ɵcmp = ɵngcc0.ɵɵdefineComponent({ type: RatingComponent, selectors: [["rating"]], hostBindings: function RatingComponent_HostBindings(rf, ctx) { if (rf & 1) {
|
151 | ɵngcc0.ɵɵlistener("keydown", function RatingComponent_keydown_HostBindingHandler($event) { return ctx.onKeydown($event); });
|
152 | } }, inputs: { max: "max", readonly: "readonly", titles: "titles", customTemplate: "customTemplate" }, outputs: { onHover: "onHover", onLeave: "onLeave" }, features: [ɵngcc0.ɵɵProvidersFeature([RATING_CONTROL_VALUE_ACCESSOR])], decls: 4, vars: 4, consts: [["tabindex", "0", "role", "slider", "aria-valuemin", "0", 3, "mouseleave", "keydown"], ["star", ""], ["ngFor", "", 3, "ngForOf"], [1, "sr-only", "visually-hidden"], [1, "bs-rating-star", 3, "title", "mouseenter", "click"], [3, "ngTemplateOutlet", "ngTemplateOutletContext"]], template: function RatingComponent_Template(rf, ctx) { if (rf & 1) {
|
153 | ɵngcc0.ɵɵelementStart(0, "span", 0);
|
154 | ɵngcc0.ɵɵlistener("mouseleave", function RatingComponent_Template_span_mouseleave_0_listener() { return ctx.reset(); })("keydown", function RatingComponent_Template_span_keydown_0_listener($event) { return ctx.onKeydown($event); });
|
155 | ɵngcc0.ɵɵtemplate(1, RatingComponent_ng_template_1_Template, 1, 1, "ng-template", null, 1, ɵngcc0.ɵɵtemplateRefExtractor);
|
156 | ɵngcc0.ɵɵtemplate(3, RatingComponent_ng_template_3_Template, 4, 11, "ng-template", 2);
|
157 | ɵngcc0.ɵɵelementEnd();
|
158 | } if (rf & 2) {
|
159 | ɵngcc0.ɵɵattribute("aria-label", ctx.ariaLabel)("aria-valuemax", ctx.range.length)("aria-valuenow", ctx.value);
|
160 | ɵngcc0.ɵɵadvance(3);
|
161 | ɵngcc0.ɵɵproperty("ngForOf", ctx.range);
|
162 | } }, directives: [ɵngcc1.NgForOf, ɵngcc1.NgTemplateOutlet], encapsulation: 2, changeDetection: 0 });
|
163 | RatingComponent.ctorParameters = () => [
|
164 | { type: ChangeDetectorRef },
|
165 | { type: RatingConfig }
|
166 | ];
|
167 | RatingComponent.propDecorators = {
|
168 | max: [{ type: Input }],
|
169 | readonly: [{ type: Input }],
|
170 | titles: [{ type: Input }],
|
171 | customTemplate: [{ type: Input }],
|
172 | onHover: [{ type: Output }],
|
173 | onLeave: [{ type: Output }],
|
174 | onKeydown: [{ type: HostListener, args: ['keydown', ['$event'],] }]
|
175 | };
|
176 | (function () { (typeof ngDevMode === "undefined" || ngDevMode) && ɵngcc0.ɵsetClassMetadata(RatingComponent, [{
|
177 | type: Component,
|
178 | args: [{
|
179 | selector: 'rating',
|
180 | 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 ? '★' : '☆' }}</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",
|
181 | providers: [RATING_CONTROL_VALUE_ACCESSOR],
|
182 | changeDetection: ChangeDetectionStrategy.OnPush
|
183 | }]
|
184 | }], function () { return [{ type: ɵngcc0.ChangeDetectorRef }, { type: RatingConfig }]; }, { max: [{
|
185 | type: Input
|
186 | }], readonly: [{
|
187 | type: Input
|
188 | }], titles: [{
|
189 | type: Input
|
190 | }], onHover: [{
|
191 | type: Output
|
192 | }], onLeave: [{
|
193 | type: Output
|
194 | }], onKeydown: [{
|
195 | type: HostListener,
|
196 | args: ['keydown', ['$event']]
|
197 | }], customTemplate: [{
|
198 | type: Input
|
199 | }] }); })();
|
200 |
|
201 | class RatingModule {
|
202 | static forRoot() {
|
203 | return {
|
204 | ngModule: RatingModule,
|
205 | providers: []
|
206 | };
|
207 | }
|
208 | }
|
209 | RatingModule.ɵmod = ɵngcc0.ɵɵdefineNgModule({ type: RatingModule });
|
210 | RatingModule.ɵinj = ɵngcc0.ɵɵdefineInjector({ factory: function RatingModule_Factory(t) { return new (t || RatingModule)(); }, imports: [[CommonModule]] });
|
211 | (function () { (typeof ngJitMode === "undefined" || ngJitMode) && ɵngcc0.ɵɵsetNgModuleScope(RatingModule, { declarations: function () { return [RatingComponent]; }, imports: function () { return [CommonModule]; }, exports: function () { return [RatingComponent]; } }); })();
|
212 | (function () { (typeof ngDevMode === "undefined" || ngDevMode) && ɵngcc0.ɵsetClassMetadata(RatingModule, [{
|
213 | type: NgModule,
|
214 | args: [{
|
215 | imports: [CommonModule],
|
216 | declarations: [RatingComponent],
|
217 | exports: [RatingComponent]
|
218 | }]
|
219 | }], null, null); })();
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 | export { RatingComponent, RatingConfig, RatingModule, RATING_CONTROL_VALUE_ACCESSOR as ɵa };
|
226 |
|
227 |
|
\ | No newline at end of file |