-
-
Notifications
You must be signed in to change notification settings - Fork 153
/
StaticRatingComponent.ux
56 lines (48 loc) · 1.52 KB
/
StaticRatingComponent.ux
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
<StackPanel ux:Class="StaticRatingComponent" Height="40" Orientation="Horizontal">
<int ux:Property="Rating" />
<int ux:Property="Stars" />
<JavaScript>
var Observable = require("FuseJS/Observable");
var total = this.Stars;
var rating = this.Rating.mapTwoWay(function(v) {
return v;
}, function(v, sv) {
return v;
});
var stars = [];
for (var i = 0; i < total.value; i++) {
stars.push(new Star(i));
}
function Star(id) {
this.id = id;
this.isActive = Observable(false);
}
function selectStar(args) {
rating.value = args.data.id + 1;
}
rating.onValueChanged(module, function(x) {
stars.forEach(function(s) {
if (s.id < x) {
s.isActive.value = true;
} else {
s.isActive.value = false;
}
});
});
module.exports = {
stars: stars,
selectStar: selectStar
};
</JavaScript>
<Each Items="{stars}">
<Panel HitTestMode="LocalBounds">
<Clicked>
<Callback Handler="{selectStar}" />
</Clicked>
<WhileTrue Value="{isActive}">
<Change theStar.Color="#FFC107" Duration="0.16" />
</WhileTrue>
<Image ux:Name="theStar" File="Assets/star.png" Color="#9E9E9E" />
</Panel>
</Each>
</StackPanel>