comparison life_calendar/index.html @ 138:3bc6b79919dc

myrss2: FEEDS: Add Rest Of World; update Quillete; remove old feeds
author paulo
date Thu, 23 Mar 2023 07:52:22 +0000
parents 256b8df1c686
children
comparison
equal deleted inserted replaced
0:e29e1c14c918 1:4dd7f9305903
77 font-size: 0.75em; 77 font-size: 0.75em;
78 font-weight: normal; 78 font-weight: normal;
79 margin: 1px; 79 margin: 1px;
80 } 80 }
81 81
82 div#tooltip h3 {
83 color: #333333;
84 font-size: 0.8em;
85 margin: 2px;
86 }
87
82 td { 88 td {
83 border-color: #FFFFFF; 89 border-color: #FFFFFF;
84 } 90 }
85 91
86 table { 92 table {
130 136
131 var previousYears; 137 var previousYears;
132 var futureYears; 138 var futureYears;
133 var remainderWeeks; 139 var remainderWeeks;
134 var restOfYearWeeks; 140 var restOfYearWeeks;
141
142 var selecting = false;
143 var start_wyc = null;
144 var end_wyc = null;
135 145
136 function validateBirthday(birthday) { 146 function validateBirthday(birthday) {
137 var birthdayPattern = /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/; 147 var birthdayPattern = /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/;
138 return birthdayPattern.test( $("#birthday").val()); 148 return birthdayPattern.test( $("#birthday").val());
139 } 149 }
190 for (year = 0; year < calParent.childNodes.length; year++) { 200 for (year = 0; year < calParent.childNodes.length; year++) {
191 if (calParent.childNodes[year] === yearParent) { 201 if (calParent.childNodes[year] === yearParent) {
192 break; 202 break;
193 } 203 }
194 } 204 }
195 var cal = getCalendar(birthdayDate, week, year);
196 return { 205 return {
197 week: week, 206 week: week,
198 year: year, 207 year: year,
199 cal: cal, 208 cal: getCalendar(birthdayDate, week, year),
200 } 209 weeks: nWeeks*year + week,
210 }
211 }
212
213 function inSpan(x, s, e) {
214 return x >= s && x <= e;
201 } 215 }
202 216
203 function loop(x, f) { 217 function loop(x, f) {
204 for (var i = 0; i < x; f(i++)); 218 for (var i = 0; i < x; f(i++));
205 } 219 }
208 var ret = []; 222 var ret = [];
209 for (var i = 0; i < x; i++) { 223 for (var i = 0; i < x; i++) {
210 ret.push(f(i)); 224 ret.push(f(i));
211 } 225 }
212 return ret; 226 return ret;
227 }
228
229 function setStyle(e) {
230 var styles = [];
231
232 if (e["_fill_color"] != undefined) {
233 styles.push("background-color: " + e._fill_color);
234 }
235 if (e["_border_color"] != undefined) {
236 styles.push("border-color: " + e._border_color);
237 }
238
239 if (styles.length == 0) {
240 e.setAttribute("style", undefined);
241 } else {
242 e.setAttribute("style", styles.join('; '));
243 }
244 }
245
246 function highlightDistance(e0, e1_wyc, e2_wyc) {
247 var calParent = e0.parentNode.parentNode;
248 var min_wyc = (e1_wyc.weeks <= e2_wyc.weeks) ? e1_wyc : e2_wyc;
249 var max_wyc = (e2_wyc == min_wyc) ? e1_wyc : e2_wyc;
250 for (var year = 0; year < lifespan; year++) {
251 for (var week = 0; week < nWeeks; week++) {
252 w = nWeeks*year + week;
253 e = calParent.childNodes[year].childNodes[week]
254 if (inSpan(w, min_wyc.weeks, max_wyc.weeks)) {
255 e._border_color = "black";
256 } else {
257 e._border_color = undefined;
258 }
259 setStyle(e);
260 }
261 }
213 } 262 }
214 263
215 function cycleColors(e) { 264 function cycleColors(e) {
216 var colors = [ 265 var colors = [
217 undefined, 266 undefined,
223 ]; 272 ];
224 273
225 var i = 0; 274 var i = 0;
226 for (; i < colors.length, colors[i] != e._fill_color; i++); 275 for (; i < colors.length, colors[i] != e._fill_color; i++);
227 e._fill_color = colors[(i + 1) % colors.length]; 276 e._fill_color = colors[(i + 1) % colors.length];
228 if (e._fill_color != undefined) { 277 setStyle(e);
229 e.setAttribute("style", "background-color: " + e._fill_color);
230 } else {
231 e.setAttribute("style", undefined);
232 }
233 } 278 }
234 279
235 function _createElement(tagName, className) { 280 function _createElement(tagName, className) {
236 var e = document.createElement(tagName); 281 var e = document.createElement(tagName);
237 if (className) { 282 if (className) {
260 e.addEventListener("mouseover", function(evt) { 305 e.addEventListener("mouseover", function(evt) {
261 var wyc = getWeekYearCal(e, i); 306 var wyc = getWeekYearCal(e, i);
262 var calYear = wyc.cal.getFullYear(); 307 var calYear = wyc.cal.getFullYear();
263 var calMonth = wyc.cal.getMonth() + 1; 308 var calMonth = wyc.cal.getMonth() + 1;
264 var calDay = wyc.cal.getDate(); 309 var calDay = wyc.cal.getDate();
265 createTooltip(evt, calYear + '-' + calMonth + '-' + calDay, "(Week: " + wyc.week + ", Year: " + wyc.year + ")"); 310 var title = calYear + '-' + calMonth + '-' + calDay;
311 var text = "(Week: " + wyc.week + ", Year: " + wyc.year + ")";
312 var subtext = null;
313 if (selecting) {
314 end_wyc = wyc;
315 highlightDistance(e, start_wyc, end_wyc);
316 }
317 if (start_wyc && end_wyc) {
318 var min_wyc = (start_wyc.weeks <= end_wyc.weeks) ? start_wyc : end_wyc;
319 var max_wyc = (end_wyc == min_wyc) ? start_wyc : end_wyc;
320 if (inSpan(wyc.weeks, min_wyc.weeks, max_wyc.weeks)) {
321 var sel_weeks = max_wyc.weeks - min_wyc.weeks;
322 var sel_years = sel_weeks/nWeeks;
323 subtext = "[Selected: weeks: " + sel_weeks + " years: " + sel_years.toFixed(2) + "]";
324 }
325 }
326 createTooltip(evt, title, text, subtext);
266 }); 327 });
267 e.addEventListener("click", function() { 328 e.addEventListener("click", function() {
268 cycleColors(e); 329 var wyc = getWeekYearCal(e, i);
330 highlightDistance(e, wyc, wyc);
331 if (start_wyc && end_wyc) {
332 start_wyc = null;
333 end_wyc = null;
334 } else {
335 cycleColors(e);
336 }
337 });
338 e.addEventListener("mousedown", function() {
339 selecting = true;
340 start_wyc = getWeekYearCal(e, i);
341 });
342 e.addEventListener("mouseup", function() {
343 selecting = false;
269 }); 344 });
270 } 345 }
271 346
272 $( document ).ready(function() { 347 $( document ).ready(function() {
273 $( "#settingsForm" ).isHappy({ 348 $( "#settingsForm" ).isHappy({