neutron-star-rating
Version:
Built on angular 5, star rating library. Can be used for your angular applications.
145 lines (144 loc) • 5.95 kB
JavaScript
import { Component, EventEmitter, Input, NgModule, Output } from '@angular/core';
import { CommonModule } from '@angular/common';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var NeutronRatingComponent = (function () {
function NeutronRatingComponent() {
var _this = this;
this.fullIcon = "★";
this.emptyIcon = "☆";
this.ratingArr = [];
this.existingRatingArr = [];
this.ratingClicked = new EventEmitter();
this.initializeStars = function () {
_this.rating = Math.floor(_this.rating);
var /** @type {?} */ numberOfStars = (_this.starNum) ? _this.starNum : 5;
var /** @type {?} */ newRating = (_this.rating > numberOfStars) ? numberOfStars : _this.rating;
if (_this.rating > numberOfStars) {
console.log("Warning: your rating exceeds the number of stars hence the rating = number of stars ");
}
else { }
for (var /** @type {?} */ i = 0; i < newRating; i++) {
_this.ratingArr.push(_this.fullIcon);
}
var /** @type {?} */ ratingLeft = numberOfStars - _this.rating;
for (var /** @type {?} */ j = 0; j < ratingLeft; j++) {
_this.ratingArr.push(_this.emptyIcon);
}
_this.existingRatingArr = _this.ratingArr;
console.log(_this.ratingArr);
};
this.passNewRating = function (newRating) {
if (!_this.readOnly) {
var /** @type {?} */ numberOfStars = (_this.starNum) ? _this.starNum : 5;
newRating = (newRating > numberOfStars) ? numberOfStars : newRating;
newRating = Math.floor(newRating);
_this.rating = newRating;
//console.log("new rating is " + newRating);
_this.ratingArr = [];
for (var /** @type {?} */ i = 0; i < newRating; i++) {
_this.ratingArr.push(_this.fullIcon);
}
var /** @type {?} */ ratingLeft = numberOfStars - newRating;
for (var /** @type {?} */ j = 0; j < ratingLeft; j++) {
_this.ratingArr.push(_this.emptyIcon);
}
_this.ratingClicked.emit(newRating);
_this.existingRatingArr = _this.ratingArr;
}
return;
};
this.onHoverEvent = function (hoveredRating) {
if (!_this.readOnly) {
var /** @type {?} */ numberOfStars = (_this.starNum) ? _this.starNum : 5;
_this.ratingArr = [];
for (var /** @type {?} */ i = 0; i < hoveredRating; i++) {
_this.ratingArr.push(_this.fullIcon);
}
var /** @type {?} */ ratingLeft = numberOfStars - hoveredRating;
for (var /** @type {?} */ j = 0; j < ratingLeft; j++) {
_this.ratingArr.push(_this.emptyIcon);
}
_this.initialHoveredRating = hoveredRating;
}
return;
};
this.changeHovered = function (a) {
//console.log("moving 1");
//console.log(a);
};
this.overStars = function ($event) {
};
this.onHoverExitEvent = function () {
_this.ratingArr = _this.existingRatingArr;
};
}
/**
* @return {?}
*/
NeutronRatingComponent.prototype.ngOnInit = function () {
this.initializeStars();
};
/**
* @return {?}
*/
NeutronRatingComponent.prototype.ngOnChanges = function () {
};
return NeutronRatingComponent;
}());
NeutronRatingComponent.decorators = [
{ type: Component, args: [{
selector: 'neutron-rating',
template: "<div class=\"crop\" [ngClass]=\"{'clickable': !readOnly}\" [title]=\"rating?rating:''\" (mouseleave)=\"onHoverExitEvent()\">\n <div [style.font-size.em]=\"starSize?starSize:1\">\n <div>\n <span *ngFor=\"let singleRating of ratingArr; let i = index\">\n <a [style.color]=\"starColour?starColour:'yellow'\" (click)=\"passNewRating(i+1)\" (mouseenter)=\"onHoverEvent(i+1)\">{{singleRating}}</a>\n </span>\n </div>\n </div>\n</div>\n\n<!-- <fa name=\"star\" style=\"color: #FDD835; font-size: 4em;\"></fa> (mouseleave) =\"onHoverExitEvent($event)\" (mouseover)=\"overStars($event)\" (mousemove)=\"changeHovered($event)\" -->\n",
styles: [".crop {\n overflow: hidden;\n}\n.clickable {\n cursor: pointer;\n}\n"]
},] },
];
/** @nocollapse */
NeutronRatingComponent.ctorParameters = function () { return []; };
NeutronRatingComponent.propDecorators = {
"rating": [{ type: Input },],
"starSize": [{ type: Input },],
"starColour": [{ type: Input },],
"starNum": [{ type: Input },],
"readOnly": [{ type: Input },],
"ratingClicked": [{ type: Output },],
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var NeutronRatingModule = (function () {
function NeutronRatingModule() {
}
return NeutronRatingModule;
}());
NeutronRatingModule.decorators = [
{ type: NgModule, args: [{
imports: [
CommonModule
],
declarations: [
NeutronRatingComponent
],
exports: [
NeutronRatingComponent
]
},] },
];
/** @nocollapse */
NeutronRatingModule.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 { NeutronRatingModule, NeutronRatingComponent as ɵa };
//# sourceMappingURL=neutron-star-rating.js.map