1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/forms'), require('@angular/common')) :
|
3 | typeof define === 'function' && define.amd ? define('ngx-bootstrap/rating', ['exports', '@angular/core', '@angular/forms', '@angular/common'], factory) :
|
4 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global['ngx-bootstrap'] = global['ngx-bootstrap'] || {}, global['ngx-bootstrap'].rating = {}), global.ng.core, global.ng.forms, global.ng.common));
|
5 | }(this, (function (exports, i0, forms, common) { 'use strict';
|
6 |
|
7 |
|
8 | var RatingConfig = (function () {
|
9 | function RatingConfig() {
|
10 |
|
11 | this.ariaLabel = 'rating';
|
12 | }
|
13 | return RatingConfig;
|
14 | }());
|
15 | RatingConfig.ɵprov = i0.ɵɵdefineInjectable({ factory: function RatingConfig_Factory() { return new RatingConfig(); }, token: RatingConfig, providedIn: "root" });
|
16 | RatingConfig.decorators = [
|
17 | { type: i0.Injectable, args: [{
|
18 | providedIn: 'root'
|
19 | },] }
|
20 | ];
|
21 |
|
22 | var RATING_CONTROL_VALUE_ACCESSOR = {
|
23 | provide: forms.NG_VALUE_ACCESSOR,
|
24 | useExisting: i0.forwardRef(function () { return RatingComponent; }),
|
25 | multi: true
|
26 | };
|
27 | var RatingComponent = (function () {
|
28 | function RatingComponent(changeDetection, config) {
|
29 | this.changeDetection = changeDetection;
|
30 |
|
31 | this.max = 5;
|
32 |
|
33 | this.readonly = false;
|
34 |
|
35 | this.titles = [];
|
36 |
|
37 | this.onHover = new i0.EventEmitter();
|
38 |
|
39 | this.onLeave = new i0.EventEmitter();
|
40 | this.onChange = Function.prototype;
|
41 | this.onTouched = Function.prototype;
|
42 |
|
43 | this.ariaLabel = 'rating';
|
44 | this.range = [];
|
45 | this.value = 0;
|
46 | Object.assign(this, config);
|
47 | }
|
48 | RatingComponent.prototype.onKeydown = function (event) {
|
49 | if ([37, 38, 39, 40].indexOf(event.which) === -1) {
|
50 | return;
|
51 | }
|
52 | event.preventDefault();
|
53 | event.stopPropagation();
|
54 | var sign = event.which === 38 || event.which === 39 ? 1 : -1;
|
55 | this.rate(this.value + sign);
|
56 | };
|
57 | RatingComponent.prototype.ngOnInit = function () {
|
58 | this.max = this.max || 5;
|
59 | this.titles =
|
60 | typeof this.titles !== 'undefined' && this.titles.length > 0
|
61 | ? this.titles
|
62 | : [];
|
63 | this.range = this.buildTemplateObjects(this.max);
|
64 | };
|
65 |
|
66 | RatingComponent.prototype.writeValue = function (value) {
|
67 | if (value % 1 !== value) {
|
68 | this.value = Math.round(value);
|
69 | this.preValue = value;
|
70 | this.changeDetection.markForCheck();
|
71 | return;
|
72 | }
|
73 | this.preValue = value;
|
74 | this.value = value;
|
75 | this.changeDetection.markForCheck();
|
76 | };
|
77 | RatingComponent.prototype.enter = function (value) {
|
78 | if (!this.readonly) {
|
79 | this.value = value;
|
80 | this.changeDetection.markForCheck();
|
81 | this.onHover.emit(value);
|
82 | }
|
83 | };
|
84 | RatingComponent.prototype.reset = function () {
|
85 | if (typeof this.preValue === 'number') {
|
86 | this.value = Math.round(this.preValue);
|
87 | this.changeDetection.markForCheck();
|
88 | this.onLeave.emit(this.value);
|
89 | }
|
90 | };
|
91 | RatingComponent.prototype.registerOnChange = function (fn) {
|
92 | this.onChange = fn;
|
93 | };
|
94 | RatingComponent.prototype.registerOnTouched = function (fn) {
|
95 | this.onTouched = fn;
|
96 | };
|
97 | RatingComponent.prototype.rate = function (value) {
|
98 | if (!this.readonly && this.range
|
99 | && value >= 0 && value <= this.range.length) {
|
100 | this.writeValue(value);
|
101 | this.onChange(value);
|
102 | }
|
103 | };
|
104 | RatingComponent.prototype.buildTemplateObjects = function (max) {
|
105 | var result = [];
|
106 | for (var i = 0; i < max; i++) {
|
107 | result.push({
|
108 | index: i,
|
109 | title: this.titles[i] || i + 1
|
110 | });
|
111 | }
|
112 | return result;
|
113 | };
|
114 | return RatingComponent;
|
115 | }());
|
116 | RatingComponent.decorators = [
|
117 | { type: i0.Component, args: [{
|
118 | selector: 'rating',
|
119 | 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",
|
120 | providers: [RATING_CONTROL_VALUE_ACCESSOR],
|
121 | changeDetection: i0.ChangeDetectionStrategy.OnPush
|
122 | },] }
|
123 | ];
|
124 | RatingComponent.ctorParameters = function () { return [
|
125 | { type: i0.ChangeDetectorRef },
|
126 | { type: RatingConfig }
|
127 | ]; };
|
128 | RatingComponent.propDecorators = {
|
129 | max: [{ type: i0.Input }],
|
130 | readonly: [{ type: i0.Input }],
|
131 | titles: [{ type: i0.Input }],
|
132 | customTemplate: [{ type: i0.Input }],
|
133 | onHover: [{ type: i0.Output }],
|
134 | onLeave: [{ type: i0.Output }],
|
135 | onKeydown: [{ type: i0.HostListener, args: ['keydown', ['$event'],] }]
|
136 | };
|
137 |
|
138 | var RatingModule = (function () {
|
139 | function RatingModule() {
|
140 | }
|
141 | RatingModule.forRoot = function () {
|
142 | return {
|
143 | ngModule: RatingModule,
|
144 | providers: []
|
145 | };
|
146 | };
|
147 | return RatingModule;
|
148 | }());
|
149 | RatingModule.decorators = [
|
150 | { type: i0.NgModule, args: [{
|
151 | imports: [common.CommonModule],
|
152 | declarations: [RatingComponent],
|
153 | exports: [RatingComponent]
|
154 | },] }
|
155 | ];
|
156 |
|
157 | |
158 |
|
159 |
|
160 |
|
161 | exports.RatingComponent = RatingComponent;
|
162 | exports.RatingConfig = RatingConfig;
|
163 | exports.RatingModule = RatingModule;
|
164 | exports.ɵa = RATING_CONTROL_VALUE_ACCESSOR;
|
165 |
|
166 | Object.defineProperty(exports, '__esModule', { value: true });
|
167 |
|
168 | })));
|
169 |
|