-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtmlBuilderService.js
58 lines (45 loc) · 1.58 KB
/
htmlBuilderService.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
57
58
'use strict';
(function () {
function createDayOfWeekHTML(events, day) {
if (!events.length) {
return '';
}
let beginnig = '<div class="dayOfWeek"><h2>' + day + '</h2>';
let innerHtml = '';
let ending = '</div>';
for (let i = 0; i < events.length; i++) {
innerHtml += createEventHTML(events[i]);
}
return beginnig + innerHtml + ending;
}
function createEventHTML(event) {
function createName(name) {
return '<h3>' + name + '</h3>';
}
function createDescription(description) {
return '<div class="description">' + description + '</div>';
}
function createAddress(address) {
return '<div class="address">' + address + '</div>';
}
function createDate(date) {
let options = {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: 'numeric',
minute: 'numeric'
};
return '<div class="date">' + date.toLocaleString("en-US", options) + '</div>';
}
return '<div class="event">' + createName(event.name) +
createDescription(event.description) +
createAddress(event.address) +
createDate(event.date) +'</div>'
}
window.htmlBuilder = {
createDayOfWeek : function (events, day) {
return createDayOfWeekHTML(events, day);
}
}
})();