Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rtsinani committed Dec 27, 2015
1 parent a9dd81b commit 2fe424a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
8 changes: 0 additions & 8 deletions week-picker/jquery-weekpicker.css
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,3 @@
opacity: .4;
filter: Alpha(Opacity=40);
}


.ui-datepicker1 td.ui-datepicker-current-day .ui-state-default {
border: 1px solid #aaaaaa;
background: #ffffff url("images/ui-bg_glass_65_ffffff_1x400.png") 50% 50% repeat-x;
font-weight: normal;
color: #212121;
}
31 changes: 21 additions & 10 deletions week-picker/jquery-weekpicker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function($, undefined) {

$.widget('ui.weekpicker', {
$.widget('lugolabs.weekpicker', {
_weekOptions: {
showOtherMonths: true,
selectOtherMonths: true
Expand All @@ -11,17 +11,13 @@
this._dateFormat = this.options.dateFormat || $.datepicker._defaults.dateFormat;
var date = this._initialDate();
this._setWeek(date);
var onSuccess = this.options.onSuccess;
var onSelect = this.options.onSelect;
this._picker = $(this.element).datepicker($.extend(this.options, this._weekOptions, {
onSelect: function(dateText, inst) {
self._setWeek(self._picker.datepicker('getDate'));
var startDateText = $.datepicker.formatDate(self._dateFormat, self._startDate, inst.settings);
self._picker.val(startDateText);
if (onSuccess) onSuccess(dateText, startDateText, self._startDate, self._endDate, inst);
self._select(dateText, inst, onSelect);
},
beforeShowDay: function(date) {
var cssClass = date >= self._startDate && date <= self._endDate ? 'ui-datepicker-current-day' : '';
return [true, cssClass];
return self._showDay(date);
},
onChangeMonthYear: function(year, month, inst) {
self._selectCurrentWeek();
Expand All @@ -41,9 +37,24 @@
}
},

_select: function(dateText, inst, onSelect) {
this._setWeek(this._picker.datepicker('getDate'));
var startDateText = $.datepicker.formatDate(this._dateFormat, this._startDate, inst.settings);
this._picker.val(startDateText);
if (onSelect) onSelect(dateText, startDateText, this._startDate, this._endDate, inst);
},

_showDay: function(date) {
var cssClass = date >= this._startDate && date <= this._endDate ? 'ui-datepicker-current-day' : '';
return [true, cssClass];
},

_setWeek: function(date) {
this._startDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay());
this._endDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 6);
var year = date.getFullYear(),
month = date.getMonth(),
day = date.getDate() - date.getDay();
this._startDate = new Date(year, month, day);
this._endDate = new Date(year, month, day + 6);
},

_selectCurrentWeek: function() {
Expand Down

0 comments on commit 2fe424a

Please sign in to comment.