-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathratingDirective.js
57 lines (49 loc) · 1.67 KB
/
ratingDirective.js
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
50
51
52
53
54
55
56
57
app.filter('range', function() {
return function(input, total) {
total = parseInt(total);
for (var i=1; i<=total; i++)
input.push(i);
return input;
};
})
app.directive('hmrating',function(){
return {
restrict: 'EA',
scope: {
//@ reads the attribute value, = provides two-way binding, & works with functions
hmupto:"@",
hmid:"@",
hmcolor:'@',
rate:'=',
setrating : '&',
mouseover : '&',
mouseleave : '&'
},
templateUrl: 'rating.html',
link : function(scope,element,attr){
scope.setrating(0);
},
controller: function($scope){
$scope.setrating = function(r){
ratingEffect(r);
$scope.rate = r;
};
$scope.mouseover = function(r){
ratingEffect(r);
}
$scope.mouseleave = function(){
ratingEffect($scope.rate);
}
function ratingEffect(r){
for(i=0;i<=r;i++)
angular.element(document.querySelector("#"+$scope.hmid+i)).removeClass("fa-star-o");
for(i=0;i<=r;i++)
angular.element(document.querySelector("#"+$scope.hmid+i)).addClass("fa-star");
for(i=r+1;i<=$scope.hmupto;i++){
angular.element(document.querySelector("#"+$scope.hmid+i)).removeClass("fa-star");
angular.element(document.querySelector("#"+$scope.hmid+i)).addClass("fa-star-o");
}
}
}
};
});