-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathweekday-selector.js
56 lines (48 loc) · 1.05 KB
/
weekday-selector.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
Polymer({
is: 'weekday-selector',
properties: {
/**
* selected week day indices
*/
value: {
type: Array,
value: [],
notify: true
},
/**
* set this if the week indices should start with a different value
*/
startIndex: {
type: Number,
value: 0
},
_weekDays: Array,
},
observers: ['_valueChange(value, startIndex)'],
_valueChange: function(value, startIndex) {
var weekDays = [];
value = value || [];
var i;
for (i = startIndex; i < startIndex + 7; i += 1) {
weekDays.push({
i: i,
checked: (value.indexOf(i) !== -1),
label: moment.weekdays(i - startIndex)
});
}
this.set('_weekDays', weekDays);
},
_setValue: function() {
var me = this;
me.debounce('setValue', function() {
var i;
var value = [];
for (i = 0; i < me._weekDays.length; i += 1) {
if (me._weekDays[i].checked) {
value.push(me._weekDays[i].i);
}
}
me.set('value', value);
}, 50);
}
});