-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
298 lines (237 loc) · 8.55 KB
/
index.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style type="text/css">
html,
body {
padding: 0;
margin: 0;
}
*,
*::after,
*::before {
box-sizing: border-box;
}
.container {
width: 100%;
max-width: 1080px;
margin: 0 auto;
padding: 0 16px;
}
.calendar-header-wrapper {
display: flex;
background-color: #eee;
border-bottom: 2px solid #888;
padding-top: 8px;
padding-bottom: 8px;
}
.calendar-header {
padding-top: 40px;
display: flex;
justify-content: space-between;
align-items: center;
}
.calendar-search__button svg {
width: 14px;
height: 14px;
}
.calendar-search__button {
height: 20px;
}
.calendar-search {
display: flex;
align-items: center;
}
.calendar-search__input {
width: 200px;
}
.calendar-search input {
height: 20px;
}
.calendar-header__button {
background-color: #0398ee;
color: #fff;
border: none;
height: 20px;
padding: 0 8px;
}
.calendar-navigation {
display: flex;
align-items: center;
gap: 16px;
margin: 16px 0;
}
.calendar-row {
display: flex;
}
.calendar-row button {
flex: 0 0 120px;
height: 120px;
display: flex;
}
.calendar__current-date {
width: 110px;
text-align: center;
white-space: nowrap;
}
</style>
</head>
<body>
<div class="calenar-page">
<div class="calendar-header-wrapper">
<div class="calendar-header container">
<div class="calendar-header__buttons">
<button class="calendar-header__button">
Добавить
</button>
<button class="calendar-header__button">
Обновить
</button>
</div>
<div class="calendar-search">
<button class="calendar-search__button">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"
id="Layer_1" x="0px" y="0px" width="122.879px" height="119.799px" viewBox="0 0 122.879 119.799"
enable-background="new 0 0 122.879 119.799" xml:space="preserve">
<g>
<path
d="M49.988,0h0.016v0.007C63.803,0.011,76.298,5.608,85.34,14.652c9.027,9.031,14.619,21.515,14.628,35.303h0.007v0.033v0.04 h-0.007c-0.005,5.557-0.917,10.905-2.594,15.892c-0.281,0.837-0.575,1.641-0.877,2.409v0.007c-1.446,3.66-3.315,7.12-5.547,10.307 l29.082,26.139l0.018,0.016l0.157,0.146l0.011,0.011c1.642,1.563,2.536,3.656,2.649,5.78c0.11,2.1-0.543,4.248-1.979,5.971 l-0.011,0.016l-0.175,0.203l-0.035,0.035l-0.146,0.16l-0.016,0.021c-1.565,1.642-3.654,2.534-5.78,2.646 c-2.097,0.111-4.247-0.54-5.971-1.978l-0.015-0.011l-0.204-0.175l-0.029-0.024L78.761,90.865c-0.88,0.62-1.778,1.209-2.687,1.765 c-1.233,0.755-2.51,1.466-3.813,2.115c-6.699,3.342-14.269,5.222-22.272,5.222v0.007h-0.016v-0.007 c-13.799-0.004-26.296-5.601-35.338-14.645C5.605,76.291,0.016,63.805,0.007,50.021H0v-0.033v-0.016h0.007 c0.004-13.799,5.601-26.296,14.645-35.338C23.683,5.608,36.167,0.016,49.955,0.007V0H49.988L49.988,0z M50.004,11.21v0.007h-0.016 h-0.033V11.21c-10.686,0.007-20.372,4.35-27.384,11.359C15.56,29.578,11.213,39.274,11.21,49.973h0.007v0.016v0.033H11.21 c0.007,10.686,4.347,20.367,11.359,27.381c7.009,7.012,16.705,11.359,27.403,11.361v-0.007h0.016h0.033v0.007 c10.686-0.007,20.368-4.348,27.382-11.359c7.011-7.009,11.358-16.702,11.36-27.4h-0.006v-0.016v-0.033h0.006 c-0.006-10.686-4.35-20.372-11.358-27.384C70.396,15.56,60.703,11.213,50.004,11.21L50.004,11.21z" />
</g>
</svg>
</button>
<input type="text" placeholder="Событие, дата или участник" class="calendar-search__input">
</div>
</div>
</div>
<div class="container">
<div class="calendar-navigation">
<button class="calendar-navigation__button" onclick="slideToPrevMonth()">
←
</button>
<div id="current-date" class="calendar__current-date">
</div>
<button class="calendar-navigation__button" onclick="slideToNextMonth()">
→
</button>
</div>
<div class="calendar" id="calendar"></div>
</div>
</div>
<script>
const store = {
selectedDate: new Date(2024, 2, 0)
}
const setSelectedDate = (date) => {
store.selectedDate = date
}
const DAYS_IN_WEEK = 7
const TOTAL_MONTH_COUNT = 12
const LOCALE = 'ru-ru'
// DOM Elements:
const calendarEl = document.getElementById('calendar')
const capitalizeFirstLetter = (value) => {
return value.charAt(0).toUpperCase() + value.slice(1);
}
const getMonthAndDateText = (date) => {
const formatter = new Intl.DateTimeFormat(LOCALE, { month: 'long' });
const monthNow = formatter.format(date)
return `${capitalizeFirstLetter(monthNow)} ${date.getFullYear()}`
}
const getWeekDayName = (date) => {
return date.toLocaleDateString(LOCALE, { weekday: 'long' })
}
const getDaysCount = (year, month) => {
return new Date(year, month, 0).getDate();
}
const getMonthDays = (date) => {
const year = date.getFullYear()
const month = date.getMonth()
const day = date.getDay()
const monthDate = date.getDate()
const countDaysInMonth = getDaysCount(year, month + 1)
const firstDayForMonth = ((Math.abs(monthDate - day - 1)) % (DAYS_IN_WEEK))
calendarEl.innerHTML = ''
const monthDays = []
for (let index = 0; index < countDaysInMonth; index += 1) {
monthDays.push(new Date(year, month, index + 1))
}
return monthDays
}
const setMonth = (date, delta) => {
date.setMonth(date.getMonth() + delta % TOTAL_MONTH_COUNT)
}
const createCalendarRow = () => {
const calendarRow = document.createElement('div')
calendarRow.className = 'calendar-row'
return calendarRow
}
const renderDays = (date) => {
const monthDays = getMonthDays(date)
const firstDay = monthDays.at(0).getDay()
const lastDay = monthDays.at(-1).getDay()
const prevMonthDays = []
const nextMonthDays = []
if (firstDay === 0) {
const prevMonth = new Date(date)
prevMonth.setDate(0)
const fullPrevMonthsDays = getMonthDays(prevMonth)
prevMonthDays.push(...fullPrevMonthsDays.slice(fullPrevMonthsDays.length - 6, fullPrevMonthsDays.length))
} else if (firstDay > 1) {
const prevMonth = new Date(date)
prevMonth.setDate(0)
const fullPrevMonthsDays = getMonthDays(prevMonth)
prevMonthDays.push(...fullPrevMonthsDays.slice(fullPrevMonthsDays.length - firstDay + 1, fullPrevMonthsDays.length))
}
if (lastDay !== 0) {
const nextMonth = new Date(date)
setMonth(nextMonth, 1)
const fullNextMonthsDays = getMonthDays(nextMonth)
nextMonthDays.push(...fullNextMonthsDays.slice(0, DAYS_IN_WEEK - lastDay))
}
let calendarRow = createCalendarRow();
[
...prevMonthDays,
...monthDays,
...nextMonthDays,
].forEach((monthDay, index) => {
const calendarButtonEl = document.createElement('button')
calendarButtonEl.innerHTML = monthDay.getDate()
if (index < DAYS_IN_WEEK) {
calendarButtonEl.innerHTML = capitalizeFirstLetter(getWeekDayName(monthDay)) + ', ' + calendarButtonEl.innerHTML
}
if (monthDay.getMonth() !== store.selectedDate.getMonth()) {
calendarButtonEl.disabled = true
}
if (index % DAYS_IN_WEEK === 0) {
calendarRow = createCalendarRow()
calendarEl.append(calendarRow)
}
calendarRow.appendChild(calendarButtonEl)
})
}
const updateCalendar = () => {
renderDays(store.selectedDate)
document.getElementById('current-date').innerText = getMonthAndDateText(store.selectedDate)
}
const slide = (delta) => {
let month = store.selectedDate.getMonth() + delta % TOTAL_MONTH_COUNT
if (month < 0) {
month = 11
store.selectedDate.setFullYear(store.selectedDate.getFullYear() - 1)
}
store.selectedDate.setMonth(month)
updateCalendar(store.selectedDate)
}
const slideToPrevMonth = () => {
slide(-1)
}
const slideToNextMonth = () => {
slide(1)
}
updateCalendar()
</script>
</body>
</html>