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 !
Datejs localization support: drop in a localized version, and Timeframe 
should pick up the details
stephencelis (author)
Tue May 06 21:35:47 -0700 2008
commit  102f94b9ea0706f42158ca4cae607c495e6ee09f
tree    d816a93d03f8fde64590e14480bd7edeb1518a4a
parent  f431d309139d62d7800f9116e18a458e5d2c0442
...
15
16
17
18
19
20
21
22
23
24
 
 
25
26
27
28
29
30
...
39
40
41
42
 
43
44
 
 
 
45
46
47
 
48
49
50
 
51
52
53
...
15
16
17
 
 
 
 
18
19
 
20
21
22
23
24
25
26
27
...
36
37
38
 
39
40
 
41
42
43
44
45
 
46
47
 
 
48
49
50
51
0
@@ -15,13 +15,10 @@
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
+ `%b %d, %Y`). (With [Datejs](http://datejs.com), it takes Datejs
0
+ formatting.)
0
 
0
 * `weekOffset`:
0
   The weekday offset (use `1` to start the week on Monday).
0
0
0
0
@@ -39,15 +36,16 @@
0
   a `String` that can be parsed with `Date.parse()`).
0
 
0
 
0
-### Notes:
0
+### Localization:
0
 
0
-* I'm just sick of multiple date pickers on the same page.
0
+Drop in a localized version of [Datejs](http://datejs.com), and it should just
0
+work. An added bonus is that the text fields will live-parse more nicely! Just
0
+try "next tues."
0
 
0
 
0
-### Also!!:
0
+### Notes:
0
 
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
+* I'm just sick of multiple date pickers on the same page.
0
 
0
 
0
 An example:
...
37
38
39
40
41
42
43
 
44
45
46
47
...
50
51
52
53
 
 
 
 
 
 
 
54
55
56
57
58
59
60
61
62
63
64
65
...
126
127
128
129
130
131
132
...
37
38
39
 
 
40
 
41
42
43
44
45
...
48
49
50
 
51
52
53
54
55
56
57
58
59
60
 
 
 
 
 
 
61
62
63
...
124
125
126
 
127
128
129
0
@@ -37,10 +37,8 @@
0
     <dl>
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
+ <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>). (With <a href="http://datejs.com/">Datejs</a>, it takes Datejs formatting.)</dd>
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
0
@@ -50,16 +48,16 @@
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>Localization:</h3>
0
+ <p>
0
+ Drop in a localized version of <a href="http://datejs.com">Datejs</a>, and it should just work. An added bonus is that the text fields will live-parse more nicely! Just try &ldquo;next tues.&rdquo;
0
+ </p>
0
+ <h3>
0
+ Notes:
0
+ </h3>
0
     <ul>
0
       <li>I&rsquo;m just sick of multiple date pickers on the same page.</li>
0
     </ul>
0
- <h3>
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
- </p>
0
     <h2 id="example_information">
0
       An example:
0
     </h2>
0
@@ -126,7 +124,6 @@
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', {
...
7
8
9
10
11
12
13
14
15
16
17
 
 
 
 
 
 
18
19
20
21
22
...
26
27
28
29
 
30
31
32
33
34
35
36
 
 
 
 
37
38
39
...
220
221
222
223
 
 
 
 
224
225
226
227
...
394
395
396
397
 
398
399
400
401
402
403
404
405
406
407
 
 
 
 
408
409
410
...
7
8
9
 
 
 
 
 
 
 
 
10
11
12
13
14
15
16
17
18
19
20
...
24
25
26
 
27
28
 
29
 
 
 
 
30
31
32
33
34
35
36
...
217
218
219
 
220
221
222
223
224
225
226
227
...
394
395
396
 
397
398
399
400
401
402
403
 
 
 
 
404
405
406
407
408
409
410
0
@@ -7,14 +7,12 @@
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
+// Checks for localized Datejs before defaulting to 'en-US'
0
+var Locale = $H({
0
+ format: (typeof Date.CultureInfo == 'undefined' ? '%b %d, %Y' : Date.CultureInfo.formatPatterns.shortDate),
0
+ monthNames: (typeof Date.CultureInfo == 'undefined' ? $w('January February March April May June July August September October November December') : Date.CultureInfo.monthNames),
0
+ dayNames: (typeof Date.CultureInfo == 'undefined' ? $w('Sunday Monday Tuesday Wednesday Thursday Friday Saturday') : Date.CultureInfo.dayNames),
0
+ weekOffset: (typeof Date.CultureInfo == 'undefined' ? 0 : Date.CultureInfo.firstDayOfWeek)
0
 });
0
 
0
 var Timeframes = [];
0
0
0
@@ -26,14 +24,13 @@
0
     Timeframes.push(this);
0
     
0
     this.element = $(element);
0
- this.options = $H({ months: 2, locale: 'US' }).merge(options || {});;
0
+ this.options = $H({ months: 2 }).merge(options || {});;
0
     this.months = this.options.get('months');
0
- this.locale = this.options.get('locale').toUpperCase();
0
     
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
+ this.weekdayNames = Locale.get('dayNames');
0
+ this.monthNames = Locale.get('monthNames');
0
+ this.format = this.options.get('format') || Locale.get('format');
0
+ this.weekOffset = this.options.get('weekOffset') || Locale.get('weekOffset');
0
     
0
     this.buttons = $H({
0
       previous: $H({ label: '&larr;', element: $(this.options.get('previousButton')) }),
0
@@ -220,7 +217,10 @@
0
   refreshField: function(fieldName) {
0
     var field = this.fields.get(fieldName);
0
     var initValue = field.value;
0
- field.value = this.range.get(fieldName) ? this.range.get(fieldName).strftime(this.format, this.locale) : '';
0
+ if(this.range.get(fieldName)) {
0
+ field.value = typeof Date.CultureInfo == 'undefined' ? this.range.get(fieldName).strftime(this.format) : this.range.get(fieldName).toString(this.format);
0
+ } else
0
+ field.value = '';
0
     field.hasFocus && field.value == '' && initValue != '' ? field.addClassName('error') : field.removeClassName('error');
0
     field.hasFocus = false;
0
     return this;
0
0
@@ -394,17 +394,17 @@
0
 
0
 Object.extend(Date.prototype, {
0
   // modified from http://alternateidea.com/blog/articles/2008/2/8/a-strftime-for-prototype
0
- strftime: function(format, locale) {
0
+ strftime: function(format) {
0
     var day = this.getDay(), month = this.getMonth();
0
     var hours = this.getHours(), minutes = this.getMinutes();
0
     function pad(num) { return num.toPaddedString(2); };
0
  
0
     return format.gsub(/\%([aAbBcdHImMpSwyY])/, function(part) {
0
       switch(part[1]) {
0
- case 'a': return Localizations.get(locale).get('weekdays').invoke('substring', 0, 3)[day].escapeHTML(); break;
0
- case 'A': return Localizations.get(locale).get('weekdays')[day].escapeHTML(); break;
0
- case 'b': return Localizations.get(locale).get('months').invoke('substring', 0, 3)[month].escapeHTML(); break;
0
- case 'B': return Localizations.get(locale).get('months')[month].escapeHTML(); break;
0
+ case 'a': return Locale.get('dayNames').invoke('substring', 0, 3)[day].escapeHTML(); break;
0
+ case 'A': return Locale.get('dayNames')[day].escapeHTML(); break;
0
+ case 'b': return Locale.get('monthNames').invoke('substring', 0, 3)[month].escapeHTML(); break;
0
+ case 'B': return Locale.get('monthNames')[month].escapeHTML(); break;
0
         case 'c': return this.toString(); break;
0
         case 'd': return pad(this.getDate()); break;
0
         case 'H': return pad(hours); break;
...
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
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,46 +1 @@
0
-// TODO: use Date.js for localizations
0
-var Localizations = $H({
0
- ES: $H({
0
- format: '%d %b %Y',
0
- months: $w('enero febrero marzo abril mayo junio julio agosto septiembre octubre noviembre diciembre'),
0
- weekdays: $w('domingo lunes martes miércoles jueves viernes sábado'),
0
- weekOffset: 1
0
- }),
0
- FR: $H({
0
- format: '%d %b %Y',
0
- months: $w('janvier février mars avril mai juin juillet août septembre octobre novembre décembre'),
0
- weekdays: $w('dimanche lundi mardi mercredi jeudi vendredi samedi'),
0
- weekOffset: 1
0
- }),
0
- IT: $H({
0
- format: '%d %b %Y',
0
- months: $w('gennaio febbraio marzo aprile maggio guigno luglio agosto settembre ottobre novembre dicembre'),
0
- weekdays: $w('domenica lunedì martedì mercoledì giovedì venerdì sabato'),
0
- weekOffset: 1
0
- }),
0
- NL: $H({
0
- format: '%d %b %Y',
0
- months: $w('januari februari maart april mei juni juli augustus september oktober november december'),
0
- weekdays: $w('zondag maandag dinsdag woensdag donderdag vrijdag zaterdag'),
0
- weekOffset: 1
0
- }),
0
- PT: $H({
0
- format: '%d %b %Y',
0
- months: $w('janeiro fevereiro março abril maio junho julho agosto setembro outubro novembro dezembro'),
0
- weekdays: $w('domingo segunda terça quarta quinta sexta sábado'),
0
- weekOffset: 1
0
- }),
0
- UK: $H({
0
- format: '%d %b %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: 1
0
- }),
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
-});

Comments

    No one has commented yet.