UNPKG

angularcli-star-rating

Version:

Star rating for Angualr Cli framework

142 lines (141 loc) 5.27 kB
import { Component, Input, Output, EventEmitter, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ var AngularcliStarRatingComponent = /** @class */ (function () { function AngularcliStarRatingComponent() { this.rating = 0; this.starReadonly = true; this.onStarRate = new EventEmitter(); this.rateText = "Click to Rate."; this.star = ["false", "false", "false", "false", "false"]; this.hoverStar = [false, false, false, false, false]; } /** * @return {?} */ AngularcliStarRatingComponent.prototype.ngAfterViewInit = function () { this.checkRating(); }; /** * @param {?} index * @return {?} */ AngularcliStarRatingComponent.prototype.addHoverClass = function (index) { this.hoverStar = [false, false, false, false, false]; for (var /** @type {?} */ p = 0; p < 5; p++) { if (p <= index) this.hoverStar[p] = true; } }; /** * @return {?} */ AngularcliStarRatingComponent.prototype.resetHover = function () { this.hoverStar = [false, false, false, false, false]; }; /** * @return {?} */ AngularcliStarRatingComponent.prototype.checkRating = function () { if (this.rating <= 5 && this.rating >= 0) { if (this.rating > 0) this.loadStar(this.rating); } else { console.log("Rating should be between 0 and 5"); } }; /** * @return {?} */ AngularcliStarRatingComponent.prototype.resetStar = function () { this.star = ["false", "false", "false", "false", "false"]; }; /** * @param {?} num * @return {?} */ AngularcliStarRatingComponent.prototype.rateIt = function (num) { this.rating = num; this.resetStar(); this.fillStar(this.rating); var /** @type {?} */ value = num + 1; this.onStarRate.emit([value]); }; /** * @param {?} num * @return {?} */ AngularcliStarRatingComponent.prototype.fillStar = function (num) { for (var /** @type {?} */ x = 0; x < 5; x++) { if (num >= x) this.star[x] = "full"; } }; /** * @param {?} num * @return {?} */ AngularcliStarRatingComponent.prototype.loadStar = function (num) { var /** @type {?} */ halfStar = num % 1 != 0 ? true : false; // check number is round or double var /** @type {?} */ halfNum = Math.floor(num); // for (var /** @type {?} */ x = 0; x < 5; x++) { if (x < num) this.star[x] = "full"; if (halfStar && halfNum == x) this.star[x] = "half"; } }; return AngularcliStarRatingComponent; }()); AngularcliStarRatingComponent.decorators = [ { type: Component, args: [{ selector: 'cli-star-rating', template: "<span class=\"cli-star\" *ngIf=\"starReadonly\">\n <i *ngFor=\"let i of star\" class=\"fa\" aria-hidden=\"true\"\n [ngClass]=\"{'fa-star-o':i == 'false','fa-star' :i == 'full', 'fa-star-half-o' : i == 'half'}\"></i>\n</span>\n<span title=\"{{rateText}}\" class=\"cli-star cli-star-hover\" *ngIf=\"!starReadonly\">\n <i *ngFor=\"let i of star;let ix = index\" class=\"fa\" aria-hidden=\"true\"\n (click) = \"rateIt(ix)\" (mouseover)=\"addHoverClass(ix)\" (mouseleave)=\"resetHover()\"\n [ngClass]=\"{'fa-star-o':i == 'false','fa-star' :i == 'full' || hoverStar[ix],\n 'fa-star-half-o' : i == 'half'}\"></i>\n</span>", styles: [".cli-star{display:inline-block;}\n.cli-star-hover i:hover~i{opacity:0.3;}\n.cli-star-hover:hover .fa-star-o.fa-star:before,\n.cli-star-hover:hover .fa-star-half-o.fa-star:before{content:'\\F005';}"] },] }, ]; /** @nocollapse */ AngularcliStarRatingComponent.ctorParameters = function () { return []; }; AngularcliStarRatingComponent.propDecorators = { "rating": [{ type: Input, args: ['rating',] },], "starReadonly": [{ type: Input, args: ['starReadonly',] },], "onStarRate": [{ type: Output },], "rateText": [{ type: Input, args: ['starRateText',] },], }; /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ var AngularcliStarRatingModule = /** @class */ (function () { function AngularcliStarRatingModule() { } return AngularcliStarRatingModule; }()); AngularcliStarRatingModule.decorators = [ { type: NgModule, args: [{ imports: [ CommonModule ], declarations: [AngularcliStarRatingComponent], exports: [AngularcliStarRatingComponent] },] }, ]; /** @nocollapse */ AngularcliStarRatingModule.ctorParameters = function () { return []; }; /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * Generated bundle index. Do not edit. */ export { AngularcliStarRatingModule, AngularcliStarRatingComponent as ɵa }; //# sourceMappingURL=angularcli-star-rating.js.map