|
2 | 2 | * Copyright (c) 2008 Kelvin Luck (http://www.kelvinluck.com/) |
3 | 3 | * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) |
4 | 4 | * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. |
5 | | - * |
6 | | - * $Id: jquery.datePicker.js 70 2009-04-05 19:25:15Z kelvin.luck $ |
| 5 | + * . |
| 6 | + * $Id$ |
| 7 | + * http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/ |
7 | 8 | **/ |
8 | 9 |
|
9 | 10 | (function($){ |
|
84 | 85 | var tbody = $(dc('tbody')); |
85 | 86 |
|
86 | 87 | var today = (new Date()).zeroTime(); |
| 88 | + today.setHours(12); |
87 | 89 |
|
88 | 90 | var month = s.month == undefined ? today.getMonth() : s.month; |
89 | 91 | var year = s.year || today.getFullYear(); |
90 | 92 |
|
91 | | - var currentDate = new Date(year, month, 1); |
| 93 | + var currentDate = (new Date(year, month, 1, 12, 0, 0)); |
92 | 94 |
|
93 | 95 |
|
94 | 96 | var firstDayOffset = Date.firstDayOfWeek - currentDate.getDay() + 1; |
|
140 | 142 | } |
141 | 143 | // addDays(1) fails in some locales due to daylight savings. See issue 39. |
142 | 144 | //currentDate.addDays(1); |
143 | | - currentDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate()+1); |
| 145 | + // set the time to midday to avoid any weird timezone issues?? |
| 146 | + currentDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate()+1, 12, 0, 0); |
144 | 147 | } |
145 | 148 | tbody.append(r); |
146 | 149 | } |
|
173 | 176 | * @param Object s (optional) Customize your date pickers. |
174 | 177 | * @option Number month The month to render when the date picker is opened (NOTE that months are zero based). Default is today's month. |
175 | 178 | * @option Number year The year to render when the date picker is opened. Default is today's year. |
176 | | - * @option String startDate The first date date can be selected. |
177 | | - * @option String endDate The last date that can be selected. |
| 179 | + * @option String|Date startDate The first date date can be selected. |
| 180 | + * @option String|Date endDate The last date that can be selected. |
178 | 181 | * @option Boolean inline Whether to create the datePicker as inline (e.g. always on the page) or as a model popup. Default is false (== modal popup) |
179 | 182 | * @option Boolean createButton Whether to create a .dp-choose-date anchor directly after the matched element which when clicked will trigger the showing of the date picker. Default is true. |
180 | 183 | * @option Boolean showYearNavigation Whether to display buttons which allow the user to navigate through the months a year at a time. Default is true. |
|
189 | 192 | * @option Number horizontalPosition The horizontal alignment of the popped up date picker to the matched element. One of $.dpConst.POS_LEFT and $.dpConst.POS_RIGHT. |
190 | 193 | * @option Number verticalOffset The number of pixels offset from the defined verticalPosition of this date picker that it should pop up in. Default in 0. |
191 | 194 | * @option Number horizontalOffset The number of pixels offset from the defined horizontalPosition of this date picker that it should pop up in. Default in 0. |
192 | | - * @option (Function|Array) renderCallback A reference to a function (or an array of seperate functions) that is called as each cell is rendered and which can add classes and event listeners to the created nodes. Each callback function will receive four arguments; a jquery object wrapping the created TD, a Date object containing the date this TD represents, a number giving the currently rendered month and a number giving the currently rendered year. Default is no callback. |
| 195 | + * @option (Function|Array) renderCallback A reference to a function (or an array of separate functions) that is called as each cell is rendered and which can add classes and event listeners to the created nodes. Each callback function will receive four arguments; a jquery object wrapping the created TD, a Date object containing the date this TD represents, a number giving the currently rendered month and a number giving the currently rendered year. Default is no callback. |
193 | 196 | * @option String hoverClass The class to attach to each cell when you hover over it (to allow you to use hover effects in IE6 which doesn't support the :hover pseudo-class on elements other than links). Default is dp-hover. Pass false if you don't want a hover class. |
| 197 | + * @option String autoFocusNextInput Whether focus should be passed onto the next input in the form (true) or remain on this input (false) when a date is selected and the calendar closes |
194 | 198 | * @type jQuery |
195 | 199 | * @name datePicker |
196 | 200 | * @cat plugins/datePicker |
|
216 | 220 | var alreadyExists = true; |
217 | 221 |
|
218 | 222 | if (!this._dpId) { |
219 | | - this._dpId = $.event.guid++; |
| 223 | + this._dpId = $.guid++; |
220 | 224 | $.event._dpCache[this._dpId] = new DatePicker(this); |
221 | 225 | alreadyExists = false; |
222 | 226 | } |
|
311 | 315 | /** |
312 | 316 | * Updates the first selectable date for any date pickers on any matched elements. |
313 | 317 | * |
314 | | - * @param String d A string representing the first selectable date (formatted according to Date.format). |
| 318 | + * @param String|Date d A Date object or string representing the first selectable date (formatted according to Date.format). |
315 | 319 | * @type jQuery |
316 | 320 | * @name dpSetStartDate |
317 | 321 | * @cat plugins/datePicker |
|
328 | 332 | /** |
329 | 333 | * Updates the last selectable date for any date pickers on any matched elements. |
330 | 334 | * |
331 | | - * @param String d A string representing the last selectable date (formatted according to Date.format). |
| 335 | + * @param String|Date d A Date object or string representing the last selectable date (formatted according to Date.format). |
332 | 336 | * @type jQuery |
333 | 337 | * @name dpSetEndDate |
334 | 338 | * @cat plugins/datePicker |
|
365 | 369 | /** |
366 | 370 | * Selects or deselects a date on any matched element's date pickers. Deselcting is only useful on date pickers where selectMultiple==true. Selecting will only work if the passed date is within the startDate and endDate boundries for a given date picker. |
367 | 371 | * |
368 | | - * @param String d A string representing the date you want to select (formatted according to Date.format). |
| 372 | + * @param String|Date d A Date object or string representing the date you want to select (formatted according to Date.format). |
369 | 373 | * @param Boolean v Whether you want to select (true) or deselect (false) this date. Optional - default = true. |
370 | 374 | * @param Boolean m Whether you want the date picker to open up on the month of this date when it is next opened. Optional - default = true. |
371 | 375 | * @param Boolean e Whether you want the date picker to dispatch events related to this change of selection. Optional - default = true. |
|
499 | 503 | * $(this).dpClose(); |
500 | 504 | * } |
501 | 505 | * ); |
502 | | - * @desc Creates a date picker and makes it appear when the relevant element is focused and disappear when it is blurred. |
503 | 506 | **/ |
504 | 507 | dpClose : function() |
505 | 508 | { |
506 | 509 | return _w.call(this, '_closeCalendar', false, this[0]); |
507 | 510 | }, |
| 511 | +/** |
| 512 | + * Rerenders the date picker's current month (for use with inline calendars and renderCallbacks). |
| 513 | + * |
| 514 | + * @type jQuery |
| 515 | + * @name dpRerenderCalendar |
| 516 | + * @cat plugins/datePicker |
| 517 | + * @author Kelvin Luck (http://www.kelvinluck.com/) |
| 518 | + * |
| 519 | + **/ |
| 520 | + dpRerenderCalendar : function() |
| 521 | + { |
| 522 | + return _w.call(this, '_rerenderCalendar'); |
| 523 | + }, |
508 | 524 | // private function called on unload to clean up any expandos etc and prevent memory links... |
509 | 525 | _dpDestroy : function() |
510 | 526 | { |
|
584 | 600 | setStartDate : function(d) |
585 | 601 | { |
586 | 602 | if (d) { |
587 | | - this.startDate = Date.fromString(d); |
| 603 | + if (d instanceof Date) { |
| 604 | + this.startDate = d; |
| 605 | + } else { |
| 606 | + this.startDate = Date.fromString(d); |
| 607 | + } |
588 | 608 | } |
589 | 609 | if (!this.startDate) { |
590 | 610 | this.startDate = (new Date()).zeroTime(); |
|
594 | 614 | setEndDate : function(d) |
595 | 615 | { |
596 | 616 | if (d) { |
597 | | - this.endDate = Date.fromString(d); |
| 617 | + if (d instanceof Date) { |
| 618 | + this.endDate = d; |
| 619 | + } else { |
| 620 | + this.endDate = Date.fromString(d); |
| 621 | + } |
598 | 622 | } |
599 | 623 | if (!this.endDate) { |
600 | 624 | this.endDate = (new Date('12/31/2999')); // using the JS Date.parse function which expects mm/dd/yyyy |
|
671 | 695 | }, |
672 | 696 | setSelected : function(d, v, moveToMonth, dispatchEvents) |
673 | 697 | { |
674 | | - if (d < this.startDate || d > this.endDate) { |
| 698 | + if (d < this.startDate || d.zeroTime() > this.endDate.zeroTime()) { |
675 | 699 | // Don't allow people to select dates outside range... |
676 | 700 | return; |
677 | 701 | } |
|
697 | 721 | if (moveToMonth && (this.displayedMonth != d.getMonth() || this.displayedYear != d.getFullYear())) { |
698 | 722 | this.setDisplayedMonth(d.getMonth(), d.getFullYear(), true); |
699 | 723 | } |
700 | | - this.selectedDates[d.toString()] = v; |
| 724 | + this.selectedDates[d.asString()] = v; |
701 | 725 | this.numSelected += v ? 1 : -1; |
702 | | - var selectorString = 'td.' +( d.getMonth() == this.displayedMonth ? 'current-month' : 'other-month'); |
| 726 | + var selectorString = 'td.' + (d.getMonth() == this.displayedMonth ? 'current-month' : 'other-month'); |
703 | 727 | var $td; |
704 | 728 | $(selectorString, this.context).each( |
705 | 729 | function() |
|
727 | 751 | }, |
728 | 752 | isSelected : function(d) |
729 | 753 | { |
730 | | - return this.selectedDates[d.toString()]; |
| 754 | + return this.selectedDates[d.asString()]; |
731 | 755 | }, |
732 | 756 | getSelected : function() |
733 | 757 | { |
734 | 758 | var r = []; |
735 | | - for(s in this.selectedDates) { |
| 759 | + for(var s in this.selectedDates) { |
736 | 760 | if (this.selectedDates[s] == true) { |
737 | | - r.push(Date.parse(s)); |
| 761 | + r.push(Date.fromString(s)); |
738 | 762 | } |
739 | 763 | } |
740 | 764 | return r; |
|
926 | 950 | if (!$this.is('.disabled')) { |
927 | 951 | c.setSelected(d, !$this.is('.selected') || !c.selectMultiple, false, true); |
928 | 952 | if (c.closeOnSelect) { |
| 953 | + // Focus the next input in the form… |
| 954 | + if (c.settings.autoFocusNextInput) { |
| 955 | + var ele = c.ele; |
| 956 | + var found = false; |
| 957 | + $(':input', ele.form).each( |
| 958 | + function() |
| 959 | + { |
| 960 | + if (found) { |
| 961 | + $(this).focus(); |
| 962 | + return false; |
| 963 | + } |
| 964 | + if (this == ele) { |
| 965 | + found = true; |
| 966 | + } |
| 967 | + } |
| 968 | + ); |
| 969 | + } else { |
| 970 | + try { |
| 971 | + c.ele.focus(); |
| 972 | + } catch (e) {} |
| 973 | + } |
929 | 974 | c._closeCalendar(); |
930 | 975 | } |
931 | | - // TODO: Instead of this which doesn't work in IE anyway we should find the next focusable element in the document |
932 | | - // and pass the focus onto that. That would allow the user to continue on the form as expected... |
933 | | - if (!$.browser.msie) |
934 | | - { |
935 | | - $(c.ele).trigger('focus', [$.dpConst.DP_INTERNAL_FOCUS]); |
936 | | - } |
937 | 976 | } |
938 | 977 | } |
939 | 978 | ); |
940 | | - |
941 | 979 | if (c.isSelected(d)) { |
942 | 980 | $td.addClass('selected'); |
943 | 981 | if (c.settings.selectWeek) |
|
1078 | 1116 | function() |
1079 | 1117 | { |
1080 | 1118 | var $this = $(this); |
1081 | | - if (Number($this.text()) > d) { |
| 1119 | + var cellDay = Number($this.text()); |
| 1120 | + if (cellDay < 13 && cellDay > d) { |
1082 | 1121 | $this.addClass('disabled'); |
1083 | 1122 | } |
1084 | 1123 | } |
|
1135 | 1174 | HEADER_FORMAT : 'mmmm yyyy' |
1136 | 1175 | }; |
1137 | 1176 | // version |
1138 | | - $.dpVersion = '$Id: jquery.datePicker.js 70 2009-04-05 19:25:15Z kelvin.luck $'; |
| 1177 | + $.dpVersion = '$Id$'; |
1139 | 1178 |
|
1140 | 1179 | $.fn.datePicker.defaults = { |
1141 | 1180 | month : undefined, |
|
1158 | 1197 | horizontalPosition : $.dpConst.POS_LEFT, |
1159 | 1198 | verticalOffset : 0, |
1160 | 1199 | horizontalOffset : 0, |
1161 | | - hoverClass : 'dp-hover' |
| 1200 | + hoverClass : 'dp-hover', |
| 1201 | + autoFocusNextInput : false |
1162 | 1202 | }; |
1163 | 1203 |
|
1164 | 1204 | function _getController(ele) |
|
0 commit comments