-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstar-rate.html
98 lines (94 loc) · 2.15 KB
/
star-rate.html
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-icons/iron-icons.html">
<dom-module id="star-rate">
<template>
<style is="custom-style">
iron-icon {
@apply --star-rate-style;
}
</style>
<template is="dom-repeat" items="{{currentStars}}">
<template is="dom-if" if="{{_hideFullStar(item)}}">
<iron-icon icon="{{_checkStarType(item)}}">
</iron-icon>
</template>
<template is="dom-if" if="{{_hideHalfStar(item)}}">
<iron-icon icon="star-half">
</iron-icon>
</template>
</template>
</template>
<script>
Polymer({
is:'star-rate',
properties:{
default: {
type: 'Number',
value: this.value
},
readOnly:{
type: 'Boolean',
value: false,
reflectToAttribute:true
},
rated: {
type: 'Boolean',
value: false,
reflectToAttribute:true
},
stars:{
type: 'Number',
value: 5,
reflectToAttribute:true
},
value:{
type: 'Number',
value: 0,
reflectToAttribute:true
},
},
onHovered: function(e,d,t) {
if (!this.readOnly && !this.rated){
this.value = parseFloat(t.dataset.item, 10 );
}
},
ready : function() {
this.currentStars = [];
for (var i = 0; i<= this.stars - 1; i++) {
this.push('currentStars',i+1);
};
this.default = this.value;
},
setvalue: function(e,d,t) {
if (!this.readOnly &&!this.rated) {
this.value = parseFloat(t.dataset.item, 10 );
this.rated=true;
}
},
halfStar: function(e,d,t) {
if (!this.readOnly &&!this.rated) {
this.value = parseFloat(t.dataset.item,10);
}
},
fullStar: function(e,d,t) {
if (!this.readOnly &&!this.rated) {
this.value = parseFloat(t.dataset.item,10);
}
},
onMouseout: function(e,d,t) {
if (!this.readOnly &&!this.rated) {
this.value=this.default;
}
},
_checkStarType: function(item){
return item <= this.value ? 'star': 'star-border';
},
_hideFullStar: function(item){
return (item-this.value)!=0.5
},
_hideHalfStar: function(item){
return this.value==item-0.5;
}
})
</script>
</dom-module>