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
| <!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="utf-8">
<title>Вертикальный календарь</title>
<style type="text/css">
@import url('https://fonts.googleapis.com/css?family=Baumans&display=swap');
body { width: 1023px; }
body, select, input { font: 14px serif; }
#calendar { width: 380px; height: 375px; display: inline-block; border: 1px solid hsl(0,0%,66%); border-radius: 6px/4px; padding: 5px; margin: 0 0 5px 0; }
#navigation_panel {
background-color: hsl(210,100%,92%);
width: 359px;
min-height: 34px;
max-height: 78px;
border: 1px solid hsl(0,0%,66%);
border-radius: 6px/4px;
padding: 10px;
margin-bottom: 5px;
text-align: center;
vertical-align: middle;
display: -webkit-box;
display: -webkit-flex;
display: flex;
-webkit-box-align: center;
-webkit-align-items: center;
align-items: center;
-webkit-box-pack: center;
-webkit-justify-content: center;
justify-content: center;
-webkit-flex-wrap: wrap;
flex-wrap: wrap; }
#navigation_panel button,
#navigation_panel #calendar_year {
background-color: hsl(210,100%,85%);
color: hsl(210,100%,45%);
font: 14px serif;
border: 1px solid hsl(210,100%,45%); }
#calendar_month {
background-color: transparent;
color: hsl(210,100%,45%);
font: 14px serif;
border: 1px solid hsl(210,100%,45%); }
#navigation_panel button {
height: 34px;
vertical-align: middle; }
#background_month {
background-color: hsl(210,100%,85%);
display: inline-block; }
button.minus {
width: 28px;
text-align: center;
border-radius: 12px 0 0 12px / 10px 0 0 10px;
margin-right: -1px; }
button.plus {
width: 28px;
text-align: center;
border-radius: 0 12px 12px 0 / 0 10px 10px 0;
margin-left: -1px; }
.month_plus, .year_plus {
margin-right: 15px; }
.arrow {
display: inline-block;
line-height: 0.5; }
#rotate_table { width: 34px; text-align: center; border-radius: 5px 18px 18px 5px / 5px 12px 12px 5px; margin: -2px 0 0 0; }
.arrow { display: inline-block; line-height: 0.5; }
#presently {
width: 234px;
margin-top: 10px;
border-radius: 12px/10px; }
#calendar_month {
width: 89px;
display: inline-block; }
#calendar_year {
width: 54px;
display: inline-block; }
select {
height: 34px; }
input {
height: 30px;
display: inline-block;
text-align: center; }
#table {
font-family: 'Baumans', cursive;
table-layout: fixed;
width: 100%;
height: 413px;
padding: 2px; }
#table, td {
border: 1px solid hsl(0,0%,66%);
border-radius: 6px/4px; }
td {
margin: 1px;
text-align: center; }
#table tbody td.prevMonth {
background-color: hsl(210,100%,95%);
color: hsl(210,100%,80%);
border: 1px solid hsl(0,0%,80%); } /* будние дни предыдущего месяца */
#table tbody tr:nth-child(n + 6) td.prevMonth {
background-color: hsl(348,100%,95%);
color: hsl(348,100%,80%);
border: 1px solid hsl(0,0%,80%); } /* выходные дни предыдущего месяца */
#table tbody td.nextMonth {
background-color: hsl(210,100%,95%);
color: hsl(210,100%,80%);
border: 1px solid hsl(0,0%,80%); } /* будние дни следующего месяца */
#table tbody tr:nth-child(n + 6) td.nextMonth {
background-color: hsl(348,100%,95%);
color: hsl(348,100%,80%);
border: 1px solid hsl(0,0%,80%); } /* выходные дни следующего месяца */
#presently.hide {
display: none; }
#table tbody tr td.week-day {
background-color: hsl(210,100%,85%);
color: hsl(210,100%,50%);
border: 1px solid hsl(0,0%,60%);
width: 20%; } /* день недели */
#table tbody tr:nth-child(n + 6) td.week-day {
background-color: hsl(348,100%,85%);
color: hsl(348,100%,50%);
border: 1px solid hsl(0,0%,60%); } /* день недели выходной*/
#table tbody tr td.week-day.curDay {
border: 1px solid hsl(210,100%,50%);
background-color: hsl(210,100%,75%);
color: hsl(210,100%,98%);
font-weight: bold;
text-shadow:
1px 1px hsl(210,100%,50%),
-1px 1px hsl(210,100%,50%),
1px -1px hsl(210,100%,50%),
-1px -1px hsl(210,100%,50%),
1px 0 hsl(210,100%,50%),
0 1px hsl(210,100%,50%),
-1px 0 hsl(210,100%,50%),
0 -1px hsl(210,100%,50%);
letter-spacing: 2px; } /* сегодн день недели */
#table tbody tr:nth-child(n + 6) td.week-day.curDay { border: 1px solid hsl(348,100%,50%); background-color: hsl(348,100%,75%); color: hsl(348,100%,98%); font-weight: bold; text-shadow: 1px 1px hsl(348,100%,50%), 1px -1px hsl(348,100%,50%), -1px 1px hsl(348,100%,50%), -1px -1px hsl(348,100%,50%), 1px 0 hsl(348,100%,50%), -1px 0 hsl(348,100%,50%), 0 1px hsl(348,100%,50%), 0 -1px hsl(348,100%,50%); letter-spacing: 2px; } /* сегодн день недели выходной */
#table tbody td {
background-color: hsl(210,100%,90%);
color: hsl(210,100%,50%); } /* будние дни текущего месяца */
#table tbody tr:nth-child(n + 6) td{ background-color: hsl(348,100%,90%); color: hsl(348,100%,50%); } /* выходные дни текущего месяца */
#table tbody tr td.curMonth.curDay { background-color: hsl(210,100%,80%); border: 1px solid hsl(210,100%,50%); font-weight: bold; color: hsl(210,100%,100%); text-shadow: 1px 1px hsl(210,100%,50%), -1px 1px hsl(210,100%,50%), 1px -1px hsl(210,100%,50%), -1px -1px hsl(210,100%,50%), 1px 0 hsl(210,100%,50%), 0 1px hsl(210,100%,50%), -1px 0 hsl(210,100%,50%), 0 -1px hsl(210,100%,50%); letter-spacing: 3px; } /* сегодня будний */
#table tbody tr:nth-child(n + 6) td.curMonth.curDay { background-color: hsl(348,100%,80%); border: 1px solid hsl(348,100%,50%); color: hsl(348,100%,100%); text-shadow: 1px 1px hsl(348,100%,50%), 1px -1px hsl(348,100%,50%), -1px 1px hsl(348,100%,50%), -1px -1px hsl(348,100%,50%), 1px 0 hsl(348,100%,50%), -1px 0 hsl(348,100%,50%), 0 1px hsl(348,100%,50%), 0 -1px hsl(348,100%,50%); letter-spacing: 3px; } /* сегодня выходной */
#calendar { display: flex; flex-direction: column; }
.content_month { flex: 1; }
#table { height:100%; }
button, select, input { outline: none; }
</style>
</head>
<body>
<div id="calendar">
<div id="navigation_panel">
<button class="month_minus minus"><span class="arrow">◀</span></button>
<span id="background_month"><select id="calendar_month"></select></span>
<button class="month_plus plus"><span class="arrow">▶</span></button>
<button class="year_minus minus"><span class="arrow">◀</span></button>
<input type="number" size="4" id="calendar_year"/>
<button class="year_plus plus"><span class="arrow">▶</span></button>
<button id="rotate_table"><span class="arrow">➙</span></button><br/>
<button id="presently">сегодня</button>
</div>
<div class="content_month">
<table id="table">
<tbody></tbody>
</table></div>
</div>
<script>
Date.prototype.reduce = function(callback, value) {
var year = this.getFullYear();
var month = this.getMonth();
var step = new Date(year, month, 1);
var last = new Date(year, month + 1, 0);
step.setHours(24 * (0 - ((step.getDay() + 6) % 7)));
last.setHours(24 * (6 - ((last.getDay() + 6) % 7)));
for (var i = 0; step <= last; i++) {
value = callback(value, new Date(+step), i, this);
step.setHours(24);
}
return value;
};
var data = new Date();
var selectMonth = document.querySelector('#calendar_month');
var monthNames = [ 'Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь',];
monthNames.forEach(function(monthName, i) {
selectMonth.options[i] = new Option(monthName, i);
});
selectMonth.addEventListener('change', function() {
data.setMonth(this.value);
createCalendar(data);
});
var minusMonth = document.querySelector('.month_minus');
minusMonth.addEventListener('click', function() {
data.setMonth(data.getMonth() - 1);
createCalendar(data);
});
var plusMonth = document.querySelector('.month_plus');
plusMonth.addEventListener('click', function() {
data.setMonth(data.getMonth() + 1);
createCalendar(data);
});
var minusYear = document.querySelector('.year_minus');
minusYear.addEventListener('click', function() {
data.setYear(data.getFullYear() - 1);
createCalendar(data);
});
var plusYear = document.querySelector('.year_plus');
plusYear.addEventListener('click', function() {
data.setYear(data.getFullYear() + 1);
createCalendar(data);
});
var inputYear = document.querySelector('#calendar_year');
inputYear.addEventListener('input', function() {
if (/^\d{4}$/.test(this.value)) {
data.setYear(this.value);
createCalendar(data);
}
});
var currentButton = document.querySelector('#presently');
currentButton.addEventListener('click', function() {
data = new Date();
createCalendar(data);
});
function createCalendar(data) {
var now = new Date().setHours(0, 0, 0, 0);
var year = data.getFullYear();
inputYear.value = year;
var month = data.getMonth();
selectMonth.selectedIndex = month;
currentButton.classList.remove('hide');
var indexcurDay;
var cls = ['prevMonth', 'curMonth', 'nextMonth'],
indexCls = 0;
var html = data.reduce(function(value, current, index, source) {
var date = current.getDate();
if (date == 1) indexCls++;
var className = cls[indexCls];
if (+now == +current && indexCls == 1) {
className += ' curDay';
currentButton.classList.add('hide');
indexcurDay = index % 7;
}
value[index % 7] += '<td class="' + className + '">' + date;
return value
}, ['<tr><td class="week-day">Пн.',
'<tr><td class="week-day">Вт.',
'<tr><td class="week-day">Ср.',
'<tr><td class="week-day">Чт.',
'<tr><td class="week-day">Пт.',
'<tr><td class="week-day">Сб.',
'<tr><td class="week-day">Вс.']);
document.querySelector('#table tbody').innerHTML = html.join('');
var daysTd = document.querySelectorAll('.week-day');
if(indexcurDay !== void 0) daysTd[indexcurDay].classList.add('curDay');
}
createCalendar(data);
var timer;
function refresh() {
window.clearTimeout(timer);
var finish = new Date().setHours(24, 0, 0, 0);
finish -= data;
timer = window.setTimeout(function() {
createCalendar(data);
refresh();
}, finish);
}
refresh();
</script>
</body>
</html> |