ngx-bootstrap-rating.umd.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 = 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, core, forms, common) { 'use strict';
  6. /**
  7. * @fileoverview added by tsickle
  8. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  9. */
  10. /** @type {?} */
  11. var RATING_CONTROL_VALUE_ACCESSOR = {
  12. provide: forms.NG_VALUE_ACCESSOR,
  13. /* tslint:disable-next-line: no-use-before-declare */
  14. useExisting: core.forwardRef((/**
  15. * @return {?}
  16. */
  17. function () { return RatingComponent; })),
  18. multi: true
  19. };
  20. var RatingComponent = /** @class */ (function () {
  21. function RatingComponent(changeDetection) {
  22. this.changeDetection = changeDetection;
  23. /**
  24. * number of icons
  25. */
  26. this.max = 5;
  27. /**
  28. * fired when icon selected, $event:number equals to selected rating
  29. */
  30. this.onHover = new core.EventEmitter();
  31. /**
  32. * fired when icon selected, $event:number equals to previous rating value
  33. */
  34. this.onLeave = new core.EventEmitter();
  35. // tslint:disable-next-line:no-any
  36. this.onChange = Function.prototype;
  37. // tslint:disable-next-line:no-any
  38. this.onTouched = Function.prototype;
  39. }
  40. /**
  41. * @param {?} event
  42. * @return {?}
  43. */
  44. RatingComponent.prototype.onKeydown = /**
  45. * @param {?} event
  46. * @return {?}
  47. */
  48. function (event) {
  49. /* tslint:disable-next-line: deprecation */
  50. if ([37, 38, 39, 40].indexOf(event.which) === -1) {
  51. return;
  52. }
  53. event.preventDefault();
  54. event.stopPropagation();
  55. /* tslint:disable-next-line: deprecation */
  56. /** @type {?} */
  57. var sign = event.which === 38 || event.which === 39 ? 1 : -1;
  58. this.rate(this.value + sign);
  59. };
  60. /**
  61. * @return {?}
  62. */
  63. RatingComponent.prototype.ngOnInit = /**
  64. * @return {?}
  65. */
  66. function () {
  67. this.max = typeof this.max !== 'undefined' ? this.max : 5;
  68. this.titles =
  69. typeof this.titles !== 'undefined' && this.titles.length > 0
  70. ? this.titles
  71. : [];
  72. this.range = this.buildTemplateObjects(this.max);
  73. };
  74. // model -> view
  75. // model -> view
  76. /**
  77. * @param {?} value
  78. * @return {?}
  79. */
  80. RatingComponent.prototype.writeValue =
  81. // model -> view
  82. /**
  83. * @param {?} value
  84. * @return {?}
  85. */
  86. function (value) {
  87. if (value % 1 !== value) {
  88. this.value = Math.round(value);
  89. this.preValue = value;
  90. this.changeDetection.markForCheck();
  91. return;
  92. }
  93. this.preValue = value;
  94. this.value = value;
  95. this.changeDetection.markForCheck();
  96. };
  97. /**
  98. * @param {?} value
  99. * @return {?}
  100. */
  101. RatingComponent.prototype.enter = /**
  102. * @param {?} value
  103. * @return {?}
  104. */
  105. function (value) {
  106. if (!this.readonly) {
  107. this.value = value;
  108. this.changeDetection.markForCheck();
  109. this.onHover.emit(value);
  110. }
  111. };
  112. /**
  113. * @return {?}
  114. */
  115. RatingComponent.prototype.reset = /**
  116. * @return {?}
  117. */
  118. function () {
  119. this.value = this.preValue;
  120. this.changeDetection.markForCheck();
  121. this.onLeave.emit(this.value);
  122. };
  123. /**
  124. * @param {?} fn
  125. * @return {?}
  126. */
  127. RatingComponent.prototype.registerOnChange = /**
  128. * @param {?} fn
  129. * @return {?}
  130. */
  131. function (fn) {
  132. this.onChange = fn;
  133. };
  134. /**
  135. * @param {?} fn
  136. * @return {?}
  137. */
  138. RatingComponent.prototype.registerOnTouched = /**
  139. * @param {?} fn
  140. * @return {?}
  141. */
  142. function (fn) {
  143. this.onTouched = fn;
  144. };
  145. /**
  146. * @param {?} value
  147. * @return {?}
  148. */
  149. RatingComponent.prototype.rate = /**
  150. * @param {?} value
  151. * @return {?}
  152. */
  153. function (value) {
  154. if (!this.readonly && value >= 0 && value <= this.range.length) {
  155. this.writeValue(value);
  156. this.onChange(value);
  157. }
  158. };
  159. /**
  160. * @protected
  161. * @param {?} max
  162. * @return {?}
  163. */
  164. RatingComponent.prototype.buildTemplateObjects = /**
  165. * @protected
  166. * @param {?} max
  167. * @return {?}
  168. */
  169. function (max) {
  170. /** @type {?} */
  171. var result = [];
  172. for (var i = 0; i < max; i++) {
  173. result.push({
  174. index: i,
  175. title: this.titles[i] || i + 1
  176. });
  177. }
  178. return result;
  179. };
  180. RatingComponent.decorators = [
  181. { type: core.Component, args: [{
  182. selector: 'rating',
  183. template: "<span (mouseleave)=\"reset()\" (keydown)=\"onKeydown($event)\" tabindex=\"0\"\n role=\"slider\" aria-valuemin=\"0\" [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\">({{ 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",
  184. providers: [RATING_CONTROL_VALUE_ACCESSOR],
  185. changeDetection: core.ChangeDetectionStrategy.OnPush
  186. }] }
  187. ];
  188. /** @nocollapse */
  189. RatingComponent.ctorParameters = function () { return [
  190. { type: core.ChangeDetectorRef }
  191. ]; };
  192. RatingComponent.propDecorators = {
  193. max: [{ type: core.Input }],
  194. readonly: [{ type: core.Input }],
  195. titles: [{ type: core.Input }],
  196. customTemplate: [{ type: core.Input }],
  197. onHover: [{ type: core.Output }],
  198. onLeave: [{ type: core.Output }],
  199. onKeydown: [{ type: core.HostListener, args: ['keydown', ['$event'],] }]
  200. };
  201. return RatingComponent;
  202. }());
  203. /**
  204. * @fileoverview added by tsickle
  205. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  206. */
  207. var RatingModule = /** @class */ (function () {
  208. function RatingModule() {
  209. }
  210. /**
  211. * @return {?}
  212. */
  213. RatingModule.forRoot = /**
  214. * @return {?}
  215. */
  216. function () {
  217. return {
  218. ngModule: RatingModule,
  219. providers: []
  220. };
  221. };
  222. RatingModule.decorators = [
  223. { type: core.NgModule, args: [{
  224. imports: [common.CommonModule],
  225. declarations: [RatingComponent],
  226. exports: [RatingComponent]
  227. },] }
  228. ];
  229. return RatingModule;
  230. }());
  231. exports.RatingComponent = RatingComponent;
  232. exports.RatingModule = RatingModule;
  233. exports.ɵa = RATING_CONTROL_VALUE_ACCESSOR;
  234. Object.defineProperty(exports, '__esModule', { value: true });
  235. }));
  236. //# sourceMappingURL=ngx-bootstrap-rating.umd.js.map