Skip to content

Commit 258a3ff

Browse files
fnagelscottgonzalez
authored andcommitted
Datepicker: Simplify usage of calendar options and avoid duplications
1 parent 63bdc3e commit 258a3ff

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
@@ -31,26 +31,19 @@
3131
}
3232
}(function( $ ) {
3333

34-
// TODO Use uniqueId, if possible
35-
var idIncrement = 0,
36-
// TODO Move this to the instance
34+
var widget,
35+
calendarOptions = [ "dateFormat", "eachDay", "max", "min", "numberOfMonths", "showWeek" ],
36+
// TODO Move this to the instance?
3737
suppressExpandOnFocus = false;
3838

39-
$.widget( "ui.datepicker", {
39+
widget = $.widget( "ui.datepicker", {
4040
version: "@VERSION",
4141
options: {
4242
appendTo: null,
43-
dateFormat: { date: "short" },
44-
// TODO Review
45-
eachDay: $.noop,
46-
max: null,
47-
min: null,
48-
numberOfMonths: 1,
4943
position: {
5044
my: "left top",
5145
at: "left bottom"
5246
},
53-
showWeek: false,
5447
show: true,
5548
hide: true,
5649

@@ -94,21 +87,15 @@ $.widget( "ui.datepicker", {
9487

9588
// Initialize calendar widget
9689
this.calendarInstance = this.calendar
97-
.calendar({
98-
dateFormat: this.options.dateFormat,
99-
eachDay: this.options.eachDay,
100-
max: this.options.max,
101-
min: this.options.min,
102-
numberOfMonths: this.options.numberOfMonths,
103-
showWeek: this.options.showWeek,
90+
.calendar( $.extend( {}, this.options, {
10491
value: this._getParsedValue(),
10592
select: function( event ) {
10693
that.element.val( that.calendarInstance.value() );
10794
that.close();
10895
that._focusTrigger();
10996
that._trigger( "select", event );
11097
}
111-
})
98+
}) )
11299
.calendar( "instance" );
113100

114101
this._setHiddenPicker();
@@ -322,7 +309,7 @@ $.widget( "ui.datepicker", {
322309
_setOption: function( key, value ) {
323310
this._super( key, value );
324311

325-
if ( $.inArray( key, [ "showWeek", "numberOfMonths", "dateFormat", "eachDay", "min", "max" ] ) !== -1 ) {
312+
if ( $.inArray( key, calendarOptions ) !== -1 ) {
326313
this.calendarInstance.option( key, value );
327314
}
328315

@@ -339,4 +326,11 @@ $.widget( "ui.datepicker", {
339326
}
340327
}
341328
});
329+
330+
$.each( calendarOptions, function( index, option ) {
331+
$.ui.datepicker.prototype.options[ option ] = $.ui.calendar.prototype.options[ option ];
332+
});
333+
334+
return widget;
335+
342336
}));

0 commit comments

Comments
 (0)