Skip to content

Commit c21d364

Browse files
committed
Datepicker: Simplify usage of calendar options and avoid duplications
1 parent 883ea9d commit c21d364

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

ui/datepicker.js

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,19 @@
2626
}
2727
}(function( $ ) {
2828

29-
// TODO Use uniqueId, if possible
30-
var idIncrement = 0,
31-
// TODO Move this to the instance
29+
var widget,
30+
calendarOptions = [ "dateFormat", "eachDay", "max", "min", "numberOfMonths", "showWeek" ],
31+
// TODO Move this to the instance?
3232
suppressExpandOnFocus = false;
3333

34-
$.widget( "ui.datepicker", {
34+
widget = $.widget( "ui.datepicker", {
3535
version: "@VERSION",
3636
options: {
3737
appendTo: null,
38-
dateFormat: { date: "short" },
39-
// TODO Review
40-
eachDay: $.noop,
41-
max: null,
42-
min: null,
43-
numberOfMonths: 1,
4438
position: {
4539
my: "left top",
4640
at: "left bottom"
4741
},
48-
showWeek: false,
4942
show: true,
5043
hide: true,
5144

@@ -86,21 +79,15 @@ $.widget( "ui.datepicker", {
8679

8780
// Initialize calendar widget
8881
this.calendarInstance = this.calendar
89-
.calendar({
90-
dateFormat: this.options.dateFormat,
91-
eachDay: this.options.eachDay,
92-
max: this.options.max,
93-
min: this.options.min,
94-
numberOfMonths: this.options.numberOfMonths,
95-
showWeek: this.options.showWeek,
82+
.calendar( $.extend( {}, this.options, {
9683
value: this._getParsedValue(),
9784
select: function( event ) {
9885
that.element.val( that.calendarInstance.value() );
9986
that.close();
10087
that._focusTrigger();
10188
that._trigger( "select", event );
10289
}
103-
})
90+
}) )
10491
.calendar( "instance" );
10592

10693
this._setHiddenPicker();
@@ -329,7 +316,7 @@ $.widget( "ui.datepicker", {
329316
_setOption: function( key, value ) {
330317
this._super( key, value );
331318

332-
if ( $.inArray( key, [ "showWeek", "numberOfMonths", "dateFormat", "eachDay", "min", "max" ] ) !== -1 ) {
319+
if ( $.inArray( key, calendarOptions ) !== -1 ) {
333320
this.calendarInstance._setOption( key, value );
334321
}
335322

@@ -346,4 +333,11 @@ $.widget( "ui.datepicker", {
346333
}
347334
}
348335
});
336+
337+
$.each( calendarOptions, function( index, option ) {
338+
$.ui.datepicker.prototype.options[ option ] = $.ui.calendar.prototype.options[ option ];
339+
});
340+
341+
return widget;
342+
349343
}));

0 commit comments

Comments
 (0)