]> source.dussan.org Git - jquery-ui.git/commitdiff
Datepicker: Simplify usage of calendar options and avoid duplications
authorFelix Nagel <info@felixnagel.com>
Thu, 12 Jun 2014 12:36:45 +0000 (14:36 +0200)
committerScott González <scott.gonzalez@gmail.com>
Thu, 29 Jan 2015 23:01:28 +0000 (18:01 -0500)
ui/datepicker.js

index d03d1b8b2f34d693084d4e7d51eb76e27b612cd0..15e979c34f96dd305708e8f6b45864f971ca1da1 100644 (file)
        }
 }(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;
+
 }));