Skip to content

Commit 2fe424a

Browse files
committed
refactor
1 parent a9dd81b commit 2fe424a

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

week-picker/jquery-weekpicker.css

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,3 @@
101101
opacity: .4;
102102
filter: Alpha(Opacity=40);
103103
}
104-
105-
106-
.ui-datepicker1 td.ui-datepicker-current-day .ui-state-default {
107-
border: 1px solid #aaaaaa;
108-
background: #ffffff url("images/ui-bg_glass_65_ffffff_1x400.png") 50% 50% repeat-x;
109-
font-weight: normal;
110-
color: #212121;
111-
}

week-picker/jquery-weekpicker.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(function($, undefined) {
22

3-
$.widget('ui.weekpicker', {
3+
$.widget('lugolabs.weekpicker', {
44
_weekOptions: {
55
showOtherMonths: true,
66
selectOtherMonths: true
@@ -11,17 +11,13 @@
1111
this._dateFormat = this.options.dateFormat || $.datepicker._defaults.dateFormat;
1212
var date = this._initialDate();
1313
this._setWeek(date);
14-
var onSuccess = this.options.onSuccess;
14+
var onSelect = this.options.onSelect;
1515
this._picker = $(this.element).datepicker($.extend(this.options, this._weekOptions, {
1616
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);
2118
},
2219
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);
2521
},
2622
onChangeMonthYear: function(year, month, inst) {
2723
self._selectCurrentWeek();
@@ -41,9 +37,24 @@
4137
}
4238
},
4339

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+
4452
_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);
4758
},
4859

4960
_selectCurrentWeek: function() {

0 commit comments

Comments
 (0)