|
1 | 1 | (function($, undefined) {
|
2 | 2 |
|
3 |
| - $.widget('ui.weekpicker', { |
| 3 | + $.widget('lugolabs.weekpicker', { |
4 | 4 | _weekOptions: {
|
5 | 5 | showOtherMonths: true,
|
6 | 6 | selectOtherMonths: true
|
|
11 | 11 | this._dateFormat = this.options.dateFormat || $.datepicker._defaults.dateFormat;
|
12 | 12 | var date = this._initialDate();
|
13 | 13 | this._setWeek(date);
|
14 |
| - var onSuccess = this.options.onSuccess; |
| 14 | + var onSelect = this.options.onSelect; |
15 | 15 | this._picker = $(this.element).datepicker($.extend(this.options, this._weekOptions, {
|
16 | 16 | onSelect: function(dateText, inst) {
|
17 |
| - self._setWeek(self._picker.datepicker('getDate')); |
18 |
| - var startDateText = $.datepicker.formatDate(self._dateFormat, self._startDate, inst.settings); |
19 |
| - self._picker.val(startDateText); |
20 |
| - if (onSuccess) onSuccess(dateText, startDateText, self._startDate, self._endDate, inst); |
| 17 | + self._select(dateText, inst, onSelect); |
21 | 18 | },
|
22 | 19 | beforeShowDay: function(date) {
|
23 |
| - var cssClass = date >= self._startDate && date <= self._endDate ? 'ui-datepicker-current-day' : ''; |
24 |
| - return [true, cssClass]; |
| 20 | + return self._showDay(date); |
25 | 21 | },
|
26 | 22 | onChangeMonthYear: function(year, month, inst) {
|
27 | 23 | self._selectCurrentWeek();
|
|
41 | 37 | }
|
42 | 38 | },
|
43 | 39 |
|
| 40 | + _select: function(dateText, inst, onSelect) { |
| 41 | + this._setWeek(this._picker.datepicker('getDate')); |
| 42 | + var startDateText = $.datepicker.formatDate(this._dateFormat, this._startDate, inst.settings); |
| 43 | + this._picker.val(startDateText); |
| 44 | + if (onSelect) onSelect(dateText, startDateText, this._startDate, this._endDate, inst); |
| 45 | + }, |
| 46 | + |
| 47 | + _showDay: function(date) { |
| 48 | + var cssClass = date >= this._startDate && date <= this._endDate ? 'ui-datepicker-current-day' : ''; |
| 49 | + return [true, cssClass]; |
| 50 | + }, |
| 51 | + |
44 | 52 | _setWeek: function(date) {
|
45 |
| - this._startDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay()); |
46 |
| - this._endDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 6); |
| 53 | + var year = date.getFullYear(), |
| 54 | + month = date.getMonth(), |
| 55 | + day = date.getDate() - date.getDay(); |
| 56 | + this._startDate = new Date(year, month, day); |
| 57 | + this._endDate = new Date(year, month, day + 6); |
47 | 58 | },
|
48 | 59 |
|
49 | 60 | _selectCurrentWeek: function() {
|
|
0 commit comments