git ssb

0+

Rômulo Alves / dat-letnice



Tree: 3e066192afe0e2526a7c7fb27edc12975fff2216

Files: 3e066192afe0e2526a7c7fb27edc12975fff2216 / js / letnice.js

2934 bytesRaw
1function 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 window.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 diff = new Date() - new Date(year, 0, 1, 0);
38 progress = ((diff/31536000000)*100).toFixed(2);
39 yd = Math.abs((progress / 100).toFixed(2));
40
41 return progress < 0 ? yd + ` YEARS AWAY` : progress > 100 ? yd + ` YEARS AGO` : progress+"%";
42 }
43
44 function doLabels()
45 {
46 let html = "";
47 let y = 0;
48
49 for(i = 0; i < 7; i++)
50 {
51 y = (i * 14) + 1;
52 html += `<text class="dayLabel" x="5" y='${y}' dy="10">${dayNames[i].substr(0,1)}</text>`
53 }
54 return html;
55 }
56
57 function doMonth(month)
58 {
59 html = "";
60 monthLength = new Date(year, month+1, 0).getDate();
61 let date = 0;
62 let x = 0;
63 let y = 0;
64
65 while(date < monthLength)
66 {
67 x += 14;
68 let week = 0;
69
70 while(week < 7 && date != monthLength)
71 {
72 y = week * 14 + 2;
73 let day = new Date(year, month, date, 0);
74
75 if(day.getDay() != week)
76 {
77 style = "null";
78 date--
79 }
80 else if(day < today)
81 {
82 style = "gone";
83 }
84 else if(day.getDay() == 5 || day.getDay() == 6)
85 {
86 style = "weekend";
87 }
88 else if(String(day) == String(today))
89 {
90 style = "today";
91 }
92 else
93 {
94 style = "day";
95 }
96 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>`
97 week++
98 date++
99 }
100 }
101 return html;
102 }
103}
104
105function scrollYear(i)
106{
107 location.hash = parseInt(location.hash.replace('#','')) + parseInt(i);
108}
109
110window.onhashchange = function()
111{
112 Year(parseInt(location.hash.replace('#','')));
113}

Built with git-ssb-web