git ssb

0+

Rômulo Alves / dat-letnice



Tree: f9f124743c6d2ed1345bc16c37379f5fe5e01f47

Files: f9f124743c6d2ed1345bc16c37379f5fe5e01f47 / js / letnice.js

2771 bytesRaw
1function Year(letnice)
2{
3 let base = document.getElementById("center");
4 base.innerHTML = "";
5 let year;
6
7 isNaN(letnice) ? year = new Date().getFullYear() : year = String(letnice).replace("#", "").substr(0,4);
8
9 location.hash = year;
10
11 const monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
12 const dayNames = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ]
13
14 let month = 0;
15 let today = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()-1, 0);
16 let style = "";
17
18 while(month < 12)
19 {
20 base.innerHTML += `<div class="month">
21 ${month==0?doHeader():""}
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
102function scrollYear(i)
103{
104 location.hash = parseInt(location.hash.replace('#','')) + parseInt(i);
105}
106
107window.onhashchange = function()
108{
109 Year(parseInt(location.hash.replace('#','')));
110}

Built with git-ssb-web