-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrating.directive.ts
49 lines (41 loc) · 1.3 KB
/
rating.directive.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { Component, Output, Input, EventEmitter, OnInit } from '@angular/core';
@Component({
selector: '<rating></rating>',
templateUrl: './rating.directive.html',
styleUrls: ['./rating.directive.css'],
})
export class RatingDirective implements OnInit{
@Output() onStarClicked = new EventEmitter<any>();
@Input() mtId;
uniqueId;
stars;
constructor() { }
ngOnInit(){
this.uniqueId = (this.mtId != '' && this.mtId == 'undefined') ? this.mtId : '1';
this.stars = [this.uniqueId+'_star1',this.uniqueId+'_star2',this.uniqueId+'_star3',this.uniqueId+'_star4',this.uniqueId+'_star5'];
}
public starHover(stars, limit){
$('.'+this.uniqueId+'_rate-star').html('star_border');
for (let i = 0; i < limit; i++) {
$('#' + stars[i]).html('star');
$('#' + stars[i]).css('color','#FFC107');
}
}
public starLeave(stars){
stars.forEach( star => {
if($('#'+star).hasClass('activeStar')){
$('#'+star).html('star');
}
else{
$('#'+star).html('star_border');
}
});
}
public starClick(stars, rate){
$('.'+this.uniqueId+'_rate-star').removeClass('activeStar');
for (let i = 0; i < rate; i++) {
$('#' + stars[i]).addClass('activeStar');
}
this.onStarClicked.emit({rateId:this.uniqueId, rate:rate});
}
}