From: Felix Nagel Date: Thu, 12 Jun 2014 12:36:45 +0000 (+0200) Subject: Datepicker: Simplify usage of calendar options and avoid duplications X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=258a3ff4e5989caddd56d15e19463c4b5943e3c8;p=jquery-ui.git Datepicker: Simplify usage of calendar options and avoid duplications --- diff --git a/ui/datepicker.js b/ui/datepicker.js index d03d1b8b2..15e979c34 100644 --- a/ui/datepicker.js +++ b/ui/datepicker.js @@ -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; + }));