-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathd-calendar-weeks.html
111 lines (81 loc) · 2.82 KB
/
d-calendar-weeks.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
99
100
101
102
103
104
105
106
107
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="d-date-utils.html"/>
<link rel="import" href="d-calendar-theme.html"/>
<!--
Element for displaying the grid of days in each month.
@element d-calendar-week
@blurb Element for displaying the grid of days in each month.
@status alpha
@homepage https://github.com/subpopular/d-calendar-week
-->
<!--
Fired when selecting a specific day of the month.
@event d-calendar-date-selected
@param {Object} detail
@param {string} detail.date the selected date
-->
<polymer-element name="d-calendar-weeks" attributes="date selectedDate">
<template>
<core-style ref="d-calendar-theme-weeks"></core-style>
<d-date-utils id="dateUtils"></d-date-utils>
<div id="days">
<div class="weeks slideleft">
<div layout horizontal wrap>
<template repeat="{{week, w in weeks}}">
<template repeat="{{day, d in week}}">
<div layout horizontal center-justified
class="day {{isSameDay(weeksFull[w][d], nowDate) ? 'currentday':''}} {{!isSameMonth(weeksFull[w][d], date) ? 'offday':''}}"
date="{{weeksFull[w][d]}}"
selected?="{{isSameDay(weeksFull[w][d], selectedDate)}}"
on-tap="{{selectDay}}">
<div layout horizontal center>{{day}}</div>
</div>
</template>
</template>
</div>
</div>
</div>
</template>
<script>
(function(){
Polymer('d-calendar-weeks', {
ready: function() {
this.dateUtils = this.$.dateUtils;
},
created: function() {
this.nowDate = new Date();
},
domReady: function() {
this.updateWeeks();
},
isSameDay: function(d1, d2) {
return this.dateUtils.isEqualDate(d1, d2);
},
isSameMonth: function(d1, d2) {
return this.dateUtils.isEqualMonth(d1, d2);
},
dateChanged: function(oldDate, newDate) {
// if the month & year hasn't changed, no need to update
if (this.dateUtils.isEqualMonth(oldDate, newDate)) {
return;
}
// updates the model data for the weeks grids
this.weeksFull = this.dateUtils.getWeekArray(this.date);
this.weeks = this.dateUtils.getWeekArray(this.date).map(function(week){
if (!week || week == null) return null;
return week.map(function(day){
return day ? day.getDate() : null;
})
});
// hacky - using our parent's methods
this.templateInstance.model.renderNode(this.$.days.querySelector('.weeks'));
},
updateWeeks: function() {
},
selectDay: function(e, detail, sender) {
this.fire('d-calendar-date-selected', {date: sender.getAttribute('date')});
}
})
})()
</script>
</polymer-element>