Files: 1f6537ee5b47f8d5332b0334c11845264d6264d9 / js / letnice.js
2790 bytesRaw
1 | function Year(letnice) |
2 | { |
3 | let base = document.getElementById("center"); |
4 | base.innerHTML = ""; |
5 | let year; |
6 | |
7 | isNaN(letnice) || letnice==null ? year = new Date().getFullYear() : year = String(letnice).replace("#", "").substr(0,4); |
8 | location.hash = year; |
9 | |
10 | const monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]; |
11 | const dayNames = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ] |
12 | |
13 | let month = 0; |
14 | let today = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()-1, 0); |
15 | let style = ""; |
16 | |
17 | base.innerHTML += doHeader(); |
18 | |
19 | while(month < 12) |
20 | { |
21 | base.innerHTML += `<div class="month"> |
22 | <p class="m">${monthNames[new Date(year, month).getMonth()].substr(0,2)}</p> |
23 | <svg class="graph" id="${monthNames[month]}"> |
24 | ${doLabels()} |
25 | ${doMonth(month)} |
26 | </svg></div>` |
27 | month++ |
28 | } |
29 | |
30 | function doHeader() |
31 | { |
32 | return `<div class="header"><p class="y">${year}<a onclick="scrollYear(-1);">-</a><a onclick="scrollYear(1);">+</a></p><p class="p">${yearProgress(year) + "%"}</p></div>`; |
33 | } |
34 | |
35 | function yearProgress(year) |
36 | { |
37 | progress = new Date() - new Date(year, 0, 1, 0); |
38 | return ((progress/31536000000)*100).toFixed(2); |
39 | } |
40 | |
41 | function doLabels() |
42 | { |
43 | let html = ""; |
44 | let y = 0; |
45 | |
46 | for(i = 0; i < 7; i++) |
47 | { |
48 | y = (i * 14) + 1; |
49 | html += `<text class="dayLabel" x="5" y='${y}' dy="10">${dayNames[i].substr(0,1)}</text>` |
50 | } |
51 | return html; |
52 | } |
53 | |
54 | function doMonth(month) |
55 | { |
56 | html = ""; |
57 | monthLength = new Date(year, month+1, 0).getDate(); |
58 | let date = 0; |
59 | let x = 0; |
60 | let y = 0; |
61 | |
62 | while(date < monthLength) |
63 | { |
64 | x += 14; |
65 | let week = 0; |
66 | |
67 | while(week < 7 && date != monthLength) |
68 | { |
69 | y = week * 14 + 2; |
70 | let day = new Date(year, month, date, 0); |
71 | |
72 | if(day.getDay() != week) |
73 | { |
74 | style = "null"; |
75 | date-- |
76 | } |
77 | else if(day < today) |
78 | { |
79 | style = "gone"; |
80 | } |
81 | else if(day.getDay() == 5 || day.getDay() == 6) |
82 | { |
83 | style = "weekend"; |
84 | } |
85 | else if(String(day) == String(today)) |
86 | { |
87 | style = "today"; |
88 | } |
89 | else |
90 | { |
91 | style = "day"; |
92 | } |
93 | html += `<rect class='${style}' x='${x}' y='${y}' title='${(date+1) == 0 ? "null" : dayNames[week] + " " + (date+1)}' width="12px" height="12px" rx="2" ry="2" onclick=""></rect>` |
94 | week++ |
95 | date++ |
96 | } |
97 | } |
98 | return html; |
99 | } |
100 | } |
101 | |
102 | function scrollYear(i) |
103 | { |
104 | location.hash = parseInt(location.hash.replace('#','')) + parseInt(i); |
105 | } |
106 | |
107 | window.onhashchange = function() |
108 | { |
109 | Year(parseInt(location.hash.replace('#',''))); |
110 | } |
Built with git-ssb-web