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