/
template.js
46 lines (41 loc) · 1.23 KB
/
template.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
var html = require('bel')
module.exports = {
headerContent: function(date) {
return html`<span>${date.toString().slice(0,3)}</span>`
},
headerTemplate: function(content, options) {
if(options.noHeader)
return
return html`<th>${content}</th>`
},
dateContent: function(date) {
return html`<span>${date.getDate()}</span>`
},
dateTemplate: function(content, options) {
return function(date, info) {
var classList = []
var day = info.dayOfMonth
if(info.siblingMonth)
classList.push(options.classPrefix + 'inactive')
if(options.selected && options.selected.hasOwnProperty(day)) {
classList = classList.concat(options.selected[day])
}
var element = html`<td>${content}</td>`
if(classList.length)
element.className = classList.join(' ')
return element
}
},
containerTemplate: function(month, options) {
var className = options.classPrefix + 'block'
var headers = html`<tr>${month[0]}</tr>`
var weeks = month.slice(1).map(function(row) {
return html`<tr>${row}</tr>`
})
return html`
<table class="${className}">
${options.noHeader ? null : headers}
${weeks}
</table>`
}
}