/[health_html]/js/DateSelector.js
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /js/DateSelector.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Fri Sep 7 15:07:17 2001 UTC (22 years, 7 months ago) by ravilov
Branch: MAIN
File MIME type: application/javascript
Modularized some pages. Some pages are now printable. Added a JavaScript date-checking module. Minor bugfixes.

1 ravilov 1.1 function DateSelector(form, date, before, after) {
2     this.sDay = form.day || form.elements[0] || null;
3     this.sMonth = form.month || form.elements[1] || null;
4     this.sYear = form.year || form.elements[2] || null;
5     this.yBefore = before || 0;
6     this.yAfter = after || 0;
7     this.BaseDate = date || new Date();
8     this.Rebuild = function(d, m, y) {
9     var i, sel;
10     // build day selector
11     if (this.sDay != null) {
12     sel = d || this.sDay.selectedIndex;
13     if (sel < 0) sel = this.BaseDate.getDate() - 1;
14     for (i = 0; i < this.sDay.options.length; i++)
15     this.sDay.options[i] = null;
16     for (i = 0; i < this.nDays; i++)
17     this.sDay.options[i] = new Option(String(i + 1), String(i + 1));
18     // this.sDay.options.length = this.nDays;
19     this.sDay.selectedIndex = Math.min(sel, this.sDay.options.length - 1);
20     }
21     // build month selector
22     if (this.sMonth != null) {
23     sel = m || this.sMonth.selectedIndex;
24     if (sel < 0) sel = this.BaseDate.getMonth();
25     for (i = 0; i < this.sMonth.options.length; i++)
26     this.sMonth.options[i] = null;
27     for (i = 0; i < 12; i++) {
28     var mon = null;
29     if (this.Months) mon = this.Months[i];
30     mon = mon || String(i + 1);
31     this.sMonth.options[i] = new Option(mon, String(i + 1));
32     }
33     // this.sMonth.options.length = 12;
34     this.sMonth.selectedIndex = sel;
35     }
36     // build year selector
37     if (this.sYear != null) {
38     sel = y || this.sYear.selectedIndex;
39     if (sel < 0) sel = this.yBefore;
40     var y = this.BaseDate.getYear();
41     if (y < 1900) y += 1900;
42     for (i = 0; i < this.sYear.options.length; i++)
43     this.sYear.options[i] = null;
44     var j = 0;
45     for (i = y - this.yBefore; i <= y + this.yAfter; i++)
46     this.sYear.options[j++] = new Option(String(i), String(i));
47     // this.sYear.options.length = this.yBefore + 1 + this.yAfter;
48     this.sYear.selectedIndex = sel;
49     }
50     }
51     this.Check = function(d, m, y) {
52     var n = new Array(31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
53     m = m || (this.sMonth != null && this.sMonth.options.selectedIndex >= 0) ?
54     parseInt(this.sMonth.options[this.sMonth.selectedIndex].value) : this.BaseDate.getMonth() + 1;
55     y = y || (this.sYear != null && this.sYear.options.selectedIndex >= 0) ?
56     parseInt(this.sYear.options[this.sYear.selectedIndex].text) : this.BaseDate.getYear();
57     if (y < 1900) y += 1900;
58     n[1] = ((y % 4 == 0) && (y % 100 != 0)) ? 29 : 28;
59     this.nDays = n[m - 1];
60     }
61     this.Reset = function() {
62     var d = this.BaseDate.getDate() - 1;
63     var m = this.BaseDate.getMonth();
64     var y = this.yBefore;
65     this.Check(d, m, y);
66     this.Rebuild(d, m, y);
67     }
68     this.Today = function() {
69     var t = new Date();
70     var d = t.getDate() - 1;
71     var m = t.getMonth();
72     var y = this.yBefore;
73     this.Check(d, m, y);
74     this.Rebuild(d, m, y);
75     }
76     this.nDays = null;
77     this.Reset();
78     this.Check();
79     this.Rebuild();
80     return this;
81     }

  ViewVC Help
Powered by ViewVC 1.1.26