mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Datepicker: Simplify usage of calendar options and avoid duplications
This commit is contained in:
parent
63bdc3ef81
commit
258a3ff4e5
@ -31,26 +31,19 @@
|
||||
}
|
||||
}(function( $ ) {
|
||||
|
||||
// TODO Use uniqueId, if possible
|
||||
var idIncrement = 0,
|
||||
// TODO Move this to the instance
|
||||
var widget,
|
||||
calendarOptions = [ "dateFormat", "eachDay", "max", "min", "numberOfMonths", "showWeek" ],
|
||||
// TODO Move this to the instance?
|
||||
suppressExpandOnFocus = false;
|
||||
|
||||
$.widget( "ui.datepicker", {
|
||||
widget = $.widget( "ui.datepicker", {
|
||||
version: "@VERSION",
|
||||
options: {
|
||||
appendTo: null,
|
||||
dateFormat: { date: "short" },
|
||||
// TODO Review
|
||||
eachDay: $.noop,
|
||||
max: null,
|
||||
min: null,
|
||||
numberOfMonths: 1,
|
||||
position: {
|
||||
my: "left top",
|
||||
at: "left bottom"
|
||||
},
|
||||
showWeek: false,
|
||||
show: true,
|
||||
hide: true,
|
||||
|
||||
@ -94,13 +87,7 @@ $.widget( "ui.datepicker", {
|
||||
|
||||
// Initialize calendar widget
|
||||
this.calendarInstance = this.calendar
|
||||
.calendar({
|
||||
dateFormat: this.options.dateFormat,
|
||||
eachDay: this.options.eachDay,
|
||||
max: this.options.max,
|
||||
min: this.options.min,
|
||||
numberOfMonths: this.options.numberOfMonths,
|
||||
showWeek: this.options.showWeek,
|
||||
.calendar( $.extend( {}, this.options, {
|
||||
value: this._getParsedValue(),
|
||||
select: function( event ) {
|
||||
that.element.val( that.calendarInstance.value() );
|
||||
@ -108,7 +95,7 @@ $.widget( "ui.datepicker", {
|
||||
that._focusTrigger();
|
||||
that._trigger( "select", event );
|
||||
}
|
||||
})
|
||||
}) )
|
||||
.calendar( "instance" );
|
||||
|
||||
this._setHiddenPicker();
|
||||
@ -322,7 +309,7 @@ $.widget( "ui.datepicker", {
|
||||
_setOption: function( key, value ) {
|
||||
this._super( key, value );
|
||||
|
||||
if ( $.inArray( key, [ "showWeek", "numberOfMonths", "dateFormat", "eachDay", "min", "max" ] ) !== -1 ) {
|
||||
if ( $.inArray( key, calendarOptions ) !== -1 ) {
|
||||
this.calendarInstance.option( key, value );
|
||||
}
|
||||
|
||||
@ -339,4 +326,11 @@ $.widget( "ui.datepicker", {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$.each( calendarOptions, function( index, option ) {
|
||||
$.ui.datepicker.prototype.options[ option ] = $.ui.calendar.prototype.options[ option ];
|
||||
});
|
||||
|
||||
return widget;
|
||||
|
||||
}));
|
||||
|
Loading…
Reference in New Issue
Block a user