public
Description: Click-draggable. Range-makeable. A better calendar.
Homepage: http://stephencelis.com/projects/timeframe
Clone URL: git://github.com/stephencelis/timeframe.git
Search Repo:
Click here to lend your support to: timeframe and make a donation at www.pledgie.com !
0.2 Release: Localization! Code-cleanup/reduction. Some camelCase changes.
stephencelis (author)
Sun May 04 15:04:05 -0700 2008
commit  d2e1648f67dcdaf1c13c811b617213c94c9a4e16
tree    f4bbbf808a973ca6032da66593bf1ad262eb85a5
parent  4dd0f5ca7c8f01c6ac284c62805fbe68fec861df
...
12
13
14
15
 
16
17
 
 
 
 
18
19
20
21
22
 
23
24
25
 
26
27
 
28
29
 
30
31
 
32
33
34
35
36
37
38
 
39
40
41
42
43
44
45
 
46
47
48
49
50
51
...
52
53
54
55
56
 
 
57
58
 
59
60
61
62
63
64
65
66
 
 
67
68
69
70
71
72
 
 
73
74
75
...
12
13
14
 
15
16
17
18
19
20
21
22
23
24
25
 
26
27
28
 
29
30
 
31
32
 
33
34
 
35
36
37
38
39
40
41
 
42
43
44
45
46
47
48
 
49
50
51
52
53
54
55
...
56
57
58
 
 
59
60
61
 
62
63
64
65
66
67
68
 
 
69
70
71
72
73
74
 
 
75
76
77
78
79
0
@@ -12,37 +12,41 @@
0
 
0
 ### Options available:
0
 
0
-* `calendars`:
0
+* `months`:
0
   The number of calendar months showing at once (default: `2`).
0
 
0
+* `locale`:
0
+ This two-character code determines the language and overrides the default
0
+ `format` and `weekOffset` (default: `US`).
0
+
0
 * `format`:
0
   The strftime format for the dates in the input fields (default:
0
   `%b %d, %Y`).
0
 
0
-* `weekoffset`:
0
+* `weekOffset`:
0
   The weekday offset (use `1` to start the week on Monday).
0
 
0
-* `startfield`, `endfield`:
0
+* `startField`, `endField`:
0
   Declare the range start and end input tags (by default, these are generated
0
- with the timeframe).
0
+ with the Timeframe).
0
 
0
-* `previousbutton`, `todaybutton`, `nextbutton`, `resetbutton`:
0
+* `previousButton`, `todayButton`, `nextButton`, `resetButton`:
0
   Declare the navigational buttons (these are also generated by default with
0
- the timeframe).
0
+ the Timeframe).
0
 
0
 * `earliest`, `latest`:
0
   The earliest and latest selectable dates (accepts either a `Date` object or
0
   a `String` that can be parsed with `Date.parse()`).
0
 
0
 
0
-### Notes
0
+### Notes:
0
 
0
 * I'm just sick of multiple date pickers on the same page.
0
 
0
 
0
 ### Also!!:
0
 
0
-The `startfield` and `endfield` are parsed with `Date.parse()`, so feel free
0
+The `startField` and `endField` are parsed with `Date.parse()`, so feel free
0
 to use [Datejs](http://datejs.com) for ninja-quick date-parsing.
0
 
0
 
0
0
0
0
@@ -52,24 +56,24 @@
0
     <script type="text/javascript" charset="utf-8">
0
       //<![CDATA[
0
         new Timeframe('calendars', {
0
- startfield: 'start',
0
- endfield: 'end',
0
+ startField: 'start',
0
+ endField: 'end',
0
           earliest: new Date(),
0
- resetbutton: 'reset' });
0
+ resetButton: 'reset' });
0
       //]]>
0
     </script>
0
 
0
 See it in action
0
 [here](http://stephencelis.com/projects/timeframe#example_information).
0
 
0
-Dependencies
0
-------------
0
+Dependencies:
0
+-------------
0
 
0
 Timeframe requires [Prototype](http://prototypejs.org) 1.6 or higher.
0
 
0
 
0
-Download
0
---------
0
+Download:
0
+---------
0
 
0
 Find the latest version of Timeframe on
0
 [Github](http://github.com/stephencelis/timeframe).
0
...
9
10
11
12
 
13
14
15
...
9
10
11
 
12
13
14
15
0
@@ -9,7 +9,7 @@
0
 
0
 * Elegant way to drag to months before and after the displayed calendars
0
 
0
-* Internationalization
0
+* More localizations
0
   
0
 * Prettier initial styles, especially for non-Safari browsers
0
   - Just get the reset button generation out of there
...
35
36
37
38
 
39
 
 
40
41
42
 
43
44
45
46
47
 
 
 
 
48
49
50
51
 
52
53
54
...
56
57
58
59
 
60
61
62
63
...
88
89
90
91
92
 
 
93
94
 
95
96
97
...
102
103
104
 
 
 
 
105
106
107
108
109
...
120
121
122
 
123
124
125
126
127
 
 
128
129
 
130
131
132
...
35
36
37
 
38
39
40
41
42
43
 
44
45
 
 
 
 
46
47
48
49
50
51
52
 
53
54
55
56
...
58
59
60
 
61
62
63
64
65
...
90
91
92
 
 
93
94
95
 
96
97
98
99
...
104
105
106
107
108
109
110
111
112
113
114
115
...
126
127
128
129
130
131
132
 
 
133
134
135
 
136
137
138
139
0
@@ -35,20 +35,22 @@
0
       Options available:
0
     </h3>
0
     <dl>
0
- <dt><code>calendars</code></dt>
0
+ <dt><code>months</code></dt>
0
       <dd>The number of calendar months showing at once (default: <code>2</code>).</dd>
0
+ <dt><code>locale</code></dt>
0
+ <dd>This two-character code determines the language and overrides the default <code>format</code> and <code>weekOffset</code> (default: <code>US</code>).</dd>
0
       <dt><code>format</code></dt>
0
       <dd>The <a href="http://developer.apple.com/documentation/Darwin/Reference/ManPages/man3/strftime.3.html">strftime</a> format for the dates in the input fields (default: <code>%b %d, %Y</code>).</dd>
0
- <dt><code>weekoffset</code></dt>
0
+ <dt><code>weekOffset</code></dt>
0
       <dd>The weekday offset (use <code>1</code> to start the week on Monday).</dd>
0
- <dt><code>startfield</code>, <code>endfield</code></dt>
0
- <dd>Declare the range start and end <code>input</code> tags (by default, these are generated with the timeframe).</dd>
0
- <dt><code>previousbutton</code>, <code>todaybutton</code>, <code>nextbutton</code>, <code>resetbutton</code></dt>
0
- <dd>Declare the navigational buttons (by default, these are also generated with the timeframe).</dd>
0
+ <dt><code>startField</code>, <code>endField</code></dt>
0
+ <dd>Declare the range start and end <code>input</code> tags (by default, these are generated with the Timeframe).</dd>
0
+ <dt><code>previousButton</code>, <code>todayButton</code>, <code>nextButton</code>, <code>resetButton</code></dt>
0
+ <dd>Declare the navigational buttons (by default, these are also generated with the Timeframe).</dd>
0
       <dt><code>earliest</code>, <code>latest</code></dt>
0
       <dd>The earliest and latest selectable dates (accepts either a <code>Date</code> object or a <code>String</code> that can be parsed with <code>Date.parse()</code>).</dd>
0
     </dl>
0
- <h3>Notes</h3>
0
+ <h3>Notes:</h3>
0
     <ul>
0
       <li>I&rsquo;m just sick of multiple date pickers on the same page.</li>
0
     </ul>
0
@@ -56,7 +58,7 @@
0
       Also!!:
0
     </h3>
0
     <p>
0
- The <code>startfield</code> and <code>endfield</code> are parsed with <code>Date.parse()</code>, so feel free to use <a href="http://datejs.com/">Datejs</a> for ninja-quick date-parsing.
0
+ The <code>startField</code> and <code>endField</code> are parsed with <code>Date.parse()</code>, so feel free to use <a href="http://datejs.com/">Datejs</a> for ninja-quick date-parsing.
0
     </p>
0
     <h2 id="example_information">
0
       An example:
0
0
@@ -88,10 +90,10 @@
0
       &lt;script type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;
0
         //&lt;![CDATA[
0
           new Timeframe(&#x27;calendars&#x27;, {
0
- startfield: &#x27;start&#x27;,
0
- endfield: &#x27;end&#x27;,
0
+ startField: &#x27;start&#x27;,
0
+ endField: &#x27;end&#x27;,
0
             earliest: new Date(),
0
- resetbutton: &#x27;reset&#x27; });
0
+ resetButton: &#x27;reset&#x27; });
0
         //]]&gt;
0
       &lt;/script&gt;
0
     </code></pre>
0
@@ -102,6 +104,10 @@
0
     <p>
0
       <a href="http://github.com/stephencelis/timeframe">http://github.com/stephencelis/timeframe</a>
0
     </p>
0
+ <h3>Acknowledgements:</h3>
0
+ <ul>
0
+ <li><a href="http://alternateidea.com">Justin Palmer (&ldquo;Caged&rdquo;)</a>, for <code>Date.prototype.strftime()</code> and Prototype 1.6 optimizations.</li>
0
+ </ul>
0
     <p>
0
       Contact me with questions/comments at
0
       <script type="text/javascript">
0
0
0
@@ -120,13 +126,14 @@
0
   </div>
0
   <script type="text/javascript" charset="utf-8" src="scripts/prototype.js"></script>
0
   <script type="text/javascript" charset="utf-8" src="../timeframe.js"></script>
0
+ <script type="text/javascript" charset="utf-8" src="../timeframe_localizations.js"></script>
0
   <script type="text/javascript" charset="utf-8">
0
     //<![CDATA[
0
       new Timeframe('calendars', {
0
- startfield: 'start',
0
- endfield: 'end',
0
+ startField: 'start',
0
+ endField: 'end',
0
         earliest: new Date(),
0
- resetbutton: 'reset' });
0
+ resetButton: 'reset' });
0
     //]]>
0
   </script>
0
 </body>
...
1
2
 
 
 
 
 
3
 
 
 
 
 
 
 
 
 
 
 
 
 
4
5
6
7
8
9
10
11
12
13
14
15
 
16
17
18
19
20
21
22
23
24
25
26
27
 
 
28
29
 
30
31
 
 
 
 
 
32
33
34
35
36
37
38
39
40
41
42
43
44
 
 
 
 
 
 
45
46
47
48
49
50
 
 
 
 
51
52
53
54
55
56
57
58
59
 
 
 
60
61
62
63
64
65
66
 
67
68
69
70
71
72
 
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
 
 
103
104
105
106
107
108
109
110
 
111
112
113
114
 
115
116
117
118
119
120
121
122
 
 
123
124
125
126
...
129
130
131
132
 
 
 
 
 
 
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
 
 
 
 
153
154
155
...
161
162
163
164
 
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
...
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
 
202
203
204
205
206
207
208
209
210
211
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
213
214
215
216
217
218
219
 
 
 
 
 
 
 
 
 
 
 
220
221
222
223
224
225
226
 
 
 
227
228
229
230
231
232
233
234
235
236
 
 
 
 
 
 
 
 
 
 
237
238
239
240
241
242
243
244
245
246
247
248
 
 
249
250
251
252
253
254
255
256
257
258
259
260
261
262
 
 
 
 
 
 
263
264
265
266
267
268
 
 
 
 
 
 
269
270
271
272
273
274
275
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
276
277
278
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279
280
281
282
 
283
284
285
286
287
 
288
289
290
291
292
293
294
295
 
296
297
298
299
300
301
302
 
303
304
305
306
...
309
310
311
312
 
313
314
315
316
317
318
319
320
321
322
 
 
 
 
323
324
325
...
328
329
330
331
332
 
333
334
335
336
337
338
...
337
338
339
340
341
 
 
342
343
344
345
 
 
346
347
 
348
349
350
351
352
 
353
354
355
356
...
362
363
364
365
366
 
 
367
368
369
370
 
371
372
373
374
375
376
...
375
376
377
378
379
 
 
 
 
 
 
 
380
381
382
383
384
385
386
387
388
389
390
391
 
392
393
394
395
396
397
398
399
 
 
400
401
402
403
404
405
406
407
408
409
410
411
412
...
404
405
406
407
 
408
409
 
410
411
412
413
414
415
416
 
 
417
418
419
420
421
 
422
423
424
425
 
426
427
428
429
430
431
432
433
434
435
436
437
 
438
439
 
440
441
442
 
 
 
 
 
 
 
443
444
445
 
446
447
448
449
450
451
452
453
454
455
 
 
 
 
456
457
458
...
469
470
471
472
473
474
475
476
477
 
478
479
...
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
 
 
 
 
 
 
 
 
23
24
25
26
27
 
 
 
 
 
 
 
 
28
29
30
 
31
32
 
33
34
35
36
37
38
 
 
 
 
 
 
 
 
 
 
 
 
39
40
41
42
43
44
45
 
 
 
 
 
46
47
48
49
50
 
 
 
 
 
 
 
 
51
52
53
54
 
 
 
 
 
 
55
56
57
 
 
 
 
58
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
61
62
 
 
 
 
 
 
 
63
64
65
66
 
67
68
69
70
71
 
 
 
 
72
73
74
75
76
77
...
80
81
82
 
83
84
85
86
87
88
89
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
92
93
94
95
96
97
...
103
104
105
 
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
...
125
126
127
 
 
 
 
 
 
 
 
 
 
 
 
 
128
129
 
130
131
132
 
 
 
 
 
 
 
 
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
 
 
 
 
 
 
152
153
154
155
156
157
158
159
160
161
162
163
164
 
 
 
 
 
165
166
167
168
169
 
 
 
 
 
 
 
 
170
171
172
173
174
175
176
177
178
179
180
181
 
 
 
 
 
 
 
 
 
 
182
183
184
185
 
 
 
 
 
 
 
 
 
 
 
 
186
187
188
189
190
191
192
193
 
 
 
 
194
195
196
197
198
199
200
201
 
 
 
 
 
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
 
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
 
 
245
246
 
247
248
 
249
250
251
252
253
254
255
 
 
256
257
258
259
260
261
262
 
263
264
265
266
267
...
270
271
272
 
273
274
275
276
 
 
 
 
 
 
 
277
278
279
280
281
282
283
...
286
287
288
 
 
289
290
291
292
293
294
295
...
294
295
296
 
 
297
298
299
300
 
 
301
302
303
 
304
305
306
307
308
 
309
310
311
312
313
...
319
320
321
 
 
322
323
324
325
 
 
326
327
328
329
330
331
332
...
331
332
333
 
 
334
335
336
337
338
339
340
341
 
 
 
 
 
 
 
342
343
344
 
345
346
347
348
349
350
351
 
 
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
...
358
359
360
 
361
362
 
363
364
365
366
367
368
 
 
369
370
371
372
 
373
 
374
375
376
377
 
378
379
 
 
 
 
 
 
 
 
 
 
 
380
381
 
382
383
384
385
386
387
388
389
390
391
392
393
394
 
395
396
397
398
399
400
401
 
 
 
 
402
403
404
405
406
407
408
...
419
420
421
 
 
 
 
 
 
422
423
424
0
@@ -1,125 +1,76 @@
0
-Date.weekdays = $w('Sunday Monday Tuesday Wednesday Thursday Friday Saturday');
0
-Date.months = $w('January February March April May June July August September October November December');
0
+/* Timeframe, version 0.2
0
+ * (c) 2008 Stephen Celis
0
+ *
0
+ * Freely distributable under the terms of an MIT-style license.
0
+ * ------------------------------------------------------------- */
0
 
0
+if(typeof Prototype == 'undefined' || parseFloat(Prototype.Version.substring(0, 3)) < 1.6)
0
+ throw 'Timeframe requires Prototype version 1.6 or greater.';
0
+
0
+var Localizations = $H({
0
+ // More localizations included in 'timeframe_localizations.js'
0
+ US: $H({
0
+ format: '%b %d, %Y',
0
+ months: $w('January February March April May June July August September October November December'),
0
+ weekdays: $w('Sunday Monday Tuesday Wednesday Thursday Friday Saturday'),
0
+ weekOffset: 0
0
+ })
0
+});
0
+
0
 var Timeframes = [];
0
 
0
 var Timeframe = Class.create({
0
- /**
0
- * Syntax:
0
- *
0
- * new Timeframe('el_id', {
0
- * months: 2,
0
- * weekoffset: 0
0
- * });
0
- */
0
- Version: '0.1 Calamari',
0
+ Version: '0.2',
0
   
0
   initialize: function(element, options) {
0
     Timeframes.push(this);
0
     
0
- this.container = $(element);
0
-
0
- this.options = $H({
0
- months: 2,
0
- format: '%b %d, %Y',
0
- weekoffset: 0
0
- }).merge(options || {});
0
-
0
+ this.element = $(element);
0
+ this.options = $H({ months: 2, locale: 'US' }).merge(options || {});;
0
     this.months = this.options.get('months');
0
- this.calendars = [];
0
+ this.locale = this.options.get('locale').toUpperCase();
0
     
0
- // Look for custom buttons:
0
+ this.weekdayNames = Localizations.get(this.locale).get('weekdays');
0
+ this.monthNames = Localizations.get(this.locale).get('months');
0
+ this.format = this.options.get('format') || Localizations.get(this.locale).get('format');
0
+ this.weekOffset = this.options.get('weekOffset') || Localizations.get(this.locale).get('weekOffset');
0
+
0
     this.buttons = $H({
0
- previous: $(this.options.get('previousbutton')),
0
- today: $(this.options.get('todaybutton')),
0
- next: $(this.options.get('nextbutton')),
0
- reset: $(this.options.get('resetbutton'))
0
- });
0
- // Or use these default labels:
0
- this.buttonLabels = $H({
0
- previous: '&larr;',
0
- today: 'T',
0
- next: '&rarr;',
0
- reset: 'R'
0
- });
0
+ previous: $H({ label: '&larr;', element: $(this.options.get('previousButton')) }),
0
+ today: $H({ label: 'T', element: $(this.options.get('todayButton')) }),
0
+ reset: $H({ label: 'R', element: $(this.options.get('resetButton')) }),
0
+ next: $H({ label: '&rarr;', element: $(this.options.get('nextButton')) })
0
+ })
0
+ this.fields = $H({ start: $(this.options.get('startField')), end: $(this.options.get('endField')) });
0
     
0
- // Look for custom fields:
0
- this.fields = $H({
0
- start: $(this.options.get('startfield')),
0
- end: $(this.options.get('endfield'))
0
- });
0
+ this.range = $H({});
0
+ this._buildButtons()._buildFields();
0
+ this.earliest = Date.parseToObject(this.options.get('earliest'));
0
+ this.latest = Date.parseToObject(this.options.get('latest'));
0
     
0
- this.earliest = this.parse(this.options.get('earliest'));
0
- this.latest = this.parse(this.options.get('latest'));
0
- this.format = this.options.get('format');
0
- this.weekoffset = this.options.get('weekoffset');
0
- this.weekdayNames = Date.weekdays; // this.weekdayNames = Date.internationalizations.get(this.options.get('locale'));
0
- this.monthNames = Date.months; // this.monthNames = Date.internationalizations.get(this.options.get('locale'));
0
- this.date = new Date();
0
- this.defaultDate = new Date(this.date)
0
+ this.calendars = [];
0
+ this.element.insert(new Element('div', { id: 'calendars_container' }));
0
+ this.months.times(function(month) { this.createCalendar(month) }.bind(this));
0
     
0
- this.disableSelection();
0
- this.buildButtons();
0
- this.months.times(function(month) { this.buildCalendar(month) }.bind(this));
0
- this.buildFields();
0
- this.populate();
0
- this.activate();
0
+ this.register().populate().refreshRange();
0
   },
0
   
0
- parse: function(string) {
0
- var date = new Date(Date.parse(string));
0
- return (date == 'Invalid Date' || date == 'NaN') ? null : date.neutral();
0
- },
0
+ // Scaffolding
0
   
0
- // Make sure dragging doesn't select any calendar text
0
- disableSelection: function() {
0
- this.container.onselectstart = function() { return false; };
0
- this.container.unselectable = 'on';
0
- this.container.style.MozUserSelect = 'none';
0
- this.container.style.cursor = 'default';
0
- },
0
-
0
- buildButtons: function() {
0
- var list = new Element('ul', { id: 'timeframe_menu' });
0
- this.buttons.each(function(pair) {
0
- if(pair.value)
0
- pair.value.addClassName('timeframe_button').addClassName(pair.key);
0
- else {
0
- var item = new Element('li');
0
- var button = new Element('a', { className: 'timeframe_button ' + pair.key, href: '#', onclick: 'return false;' }).update(this.buttonLabels.get(pair.key));
0
- button.onclick = function() { return false; };
0
- this.buttons.set(pair.key, button);
0
- item.insert(this.buttons.get(pair.key));
0
- list.insert(item);
0
- }
0
- }.bind(this))
0
- if(list.childNodes.length > 0) this.container.insert(list);
0
-
0
- this.clearButton = new Element('span', { className: 'clear' }).update(new Element('span').update('X'));
0
- },
0
-
0
- buildCalendar: function(calendarNumber) {
0
- var calendar = new Element('table', { id: 'calendar_' + calendarNumber, border: 0, cellspacing: 0, cellpadding: 5 });
0
+ createCalendar: function() {
0
+ var calendar = new Element('table', { id: 'calendar_' + this.calendars.length, border: 0, cellspacing: 0, cellpadding: 5 });
0
     calendar.insert(new Element('caption'));
0
- calendar.insert(this.buildHead());
0
- calendar.insert(this.buildBody());
0
- this.container.insert(calendar);
0
- this.calendars.push(calendar);
0
- },
0
-
0
- buildHead: function() {
0
+
0
     var head = new Element('thead');
0
     var row = new Element('tr');
0
     this.weekdayNames.length.times(function(column) {
0
- var weekday = this.weekdayNames[(column + this.weekoffset) % 7];
0
+ var weekday = this.weekdayNames[(column + this.weekOffset) % 7];
0
       var cell = new Element('th', { scope: 'col', abbr: weekday }).update(weekday.substring(0,1));
0
       row.insert(cell);
0
     }.bind(this));
0
     head.insert(row);
0
- return head;
0
- },
0
-
0
- buildBody: function() {
0
+ calendar.insert(head);
0
+
0
     var body = new Element('tbody');
0
     (6).times(function(rowNumber) {
0
       var row = new Element('tr');
0
0
@@ -129,27 +80,18 @@
0
       });
0
       body.insert(row);
0
     }.bind(this));
0
- return body;
0
+ calendar.insert(body);
0
+
0
+ this.element.down('div#calendars_container').insert(calendar);
0
+ this.calendars.push(calendar);
0
+ this.months = this.calendars.length;
0
+ return this;
0
   },
0
   
0
- buildFields: function() {
0
- var fieldset = new Element('div', { id: 'timeframe_fields' });
0
- this.fields.each(function(pair) {
0
- if(pair.value)
0
- pair.value.addClassName('timeframe_field').addClassName(pair.key);
0
- else {
0
- var container = new Element('div', { id: pair.key + 'field_container' });
0
- this.fields.set(pair.key, new Element('input', { id: pair.key + 'field', name: pair.key + 'field', type: 'text', value: '' }));
0
- container.insert(new Element('label', { 'for': pair.key + 'field' }).update(pair.key));
0
- container.insert(this.fields.get(pair.key));
0
- fieldset.insert(container);
0
- }
0
- }.bind(this));
0
- if(fieldset.childNodes.length > 0) this.container.insert(fieldset);
0
- this.startfield = this.fields.get('start');
0
- this.endfield = this.fields.get('end');
0
- this.parseStartField();
0
- this.parseEndField();
0
+ destroyCalendar: function() {
0
+ this.calendars.pop().remove();
0
+ this.months = this.calendars.length;
0
+ return this;
0
   },
0
   
0
   populate: function() {
0
@@ -161,7 +103,7 @@
0
       caption.update(this.monthNames[month.getMonth()] + ' ' + month.getFullYear());
0
       
0
       var iterator = new Date(month);
0
- var offset = (iterator.getDay() - this.weekoffset) % 7;
0
+ var offset = (iterator.getDay() - this.weekOffset) % 7;
0
       var inactive = offset > 0 ? 'pre beyond' : false;
0
       iterator.setDate(iterator.getDate() - offset);
0
       if(iterator.getDate() > 1 && !inactive) {
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
@@ -183,123 +125,142 @@
0
         if(iterator.getDate() == 1) inactive = inactive ? false : 'post beyond';
0
       }.bind(this));
0
       
0
- if(this.earliest && n == 0) {
0
- if(month.getMonth() == this.earliest.getMonth() && month.getFullYear() == this.earliest.getFullYear())
0
- this.buttons.get('previous').addClassName('disabled');
0
- else
0
- this.buttons.get('previous').removeClassName('disabled');
0
- }
0
- if(this.latest && n == (this.calendars.length - 1)) {
0
- if(month.getMonth() == this.latest.getMonth() && month.getFullYear == this.latest.getFullYear())
0
- this.buttons.get('next').addClassName('disabled');
0
- else
0
- this.buttons.get('next').removeClassName('disabled');
0
- }
0
-
0
       month.setMonth(month.getMonth() + 1);
0
     }.bind(this));
0
- this.refreshRange();
0
+ return this;
0
   },
0
   
0
- activate: function() {
0
- document.observe('click', this.handleClick.bind(this));
0
- document.observe('mousedown', this.handleMousedown.bind(this));
0
- document.observe('mouseover', this.handleMouseover.bind(this));
0
- document.observe('mouseup', this.setPoint.bind(this));
0
- document.observe('unload', this.deactivate.bind(this));
0
- if(Prototype.Browser.Opera) document.observe('mousemove', this.handleMousemove.bind(this));
0
- this.aimFieldObservers();
0
+ _buildButtons: function() {
0
+ var buttonList = new Element('ul', { id: 'timeframe_menu' });
0
+ this.buttons.each(function(pair) {
0
+ if(pair.value.get('element'))
0
+ pair.value.get('element').addClassName('timeframe_button').addClassName(pair.key);
0
+ else {
0
+ var item = new Element('li');
0
+ var button = new Element('a', { className: 'timeframe_button ' + pair.key, href: '#', onclick: 'return false;' }).update(pair.value.get('label'));
0
+ button.onclick = function() { return false; };
0
+ pair.value.set('element', button);
0
+ item.insert(button);
0
+ buttonList.insert(item);
0
+ }
0
+ }.bind(this))
0
+ if(buttonList.childNodes.length > 0) this.element.insert({ top: buttonList });
0
+ this.clearButton = new Element('span', { className: 'clear' }).update(new Element('span').update('X'));
0
+ return this;
0
   },
0
   
0
- aimFieldObservers: function(field, assignment) {
0
- [this.startfield, this.endfield].invoke('observe', 'focus', this.declareFocus.bind(this));
0
- [this.startfield, this.endfield].invoke('observe', 'blur', this.declareBlur.bind(this));
0
- new Form.Element.Observer(this.startfield, 0.2, function(element, value) {
0
- if(element.hasFocus) {
0
- this.parseStartField(value);
0
+ _buildFields: function() {
0
+ var fieldset = new Element('div', { id: 'timeframe_fields' });
0
+ this.fields.each(function(pair) {
0
+ if(pair.value)
0
+ pair.value.addClassName('timeframe_field').addClassName(pair.key);
0
+ else {
0
+ var container = new Element('div', { id: pair.key + 'field_container' });
0
+ this.fields.set(pair.key, new Element('input', { id: pair.key + 'field', name: pair.key + 'field', type: 'text', value: '' }));
0
+ container.insert(new Element('label', { 'for': pair.key + 'field' }).update(pair.key));
0
+ container.insert(this.fields.get(pair.key));
0
+ fieldset.insert(container);
0
       }
0
     }.bind(this));
0
- new Form.Element.Observer(this.endfield, 0.2, function(element, value) {
0
- if(element.hasFocus) {
0
- this.parseEndField(value);
0
- }
0
- }.bind(this));
0
+ if(fieldset.childNodes.length > 0) this.element.insert(fieldset);
0
+ this.parseField('start').refreshField('start').parseField('end').refreshField('end').initDate = new Date(this.date);
0
+ return this;
0
   },
0
   
0
- parseStartField: function() {
0
- var date = new Date(Date.parse(this.startfield.value));
0
- this.startdate = (date == 'Invalid Date' || date == 'NaN') ? null : (this.enddate && date > this.enddate) ? null : (this.earliest && date < this.earliest) ? null : date.neutral();
0
- if(this.startdate) {
0
- this.date = new Date(this.startdate);
0
- this.populate();
0
- }
0
- else this.refreshRange();
0
+ // Event registration
0
+
0
+ register: function() {
0
+ document.observe('click', this.eventClick.bind(this));
0
+ document.observe('mousedown', this.eventMouseDown.bind(this));
0
+ document.observe('mouseover', this.eventMouseOver.bind(this));
0
+ document.observe('mouseup', this.eventMouseUp.bind(this));
0
+ document.observe('unload', this.unregister.bind(this));
0
+ if(Prototype.Browser.Opera) document.observe('mousemove', this.handleMousemove.bind(this));
0
+ return this._registerFieldObserver('start')._registerFieldObserver('end')._disableTextSelection();
0
   },
0
   
0
- parseEndField: function() {
0
- var date = new Date(Date.parse(this.endfield.value));
0
- this.enddate = (date == 'Invalid Date' || date == 'NaN') ? null : (this.startdate && date < this.startdate) ? null : (this.latest && date >= th