]> source.dussan.org Git - jquery-ui.git/commitdiff
(fix) Datepicker: Use Globalize 1.0.0
authorRafael Xavier de Souza <rxaviers@gmail.com>
Thu, 4 Sep 2014 18:47:48 +0000 (15:47 -0300)
committerFelix Nagel <info@felixnagel.com>
Tue, 28 Jul 2015 22:04:00 +0000 (00:04 +0200)
- user cannot provide locale: {fn1: ..., fn2:...} with all the
  formatters and parsers

ui/calendar.js
ui/calendar/date.js
ui/datepicker.js

index 40f90fe7bd2ecf60de9c698dc146b39ee8bf00c2..da8604458104e0752bfb69bb34c5a27b04cb71ec 100644 (file)
@@ -71,8 +71,7 @@ return $.widget( "ui.calendar", {
 
                this._setLocale( this.options.locale );
 
-               this.date = new $.ui.calendarDate( this.options.value, this.options.locale );
-               this.date = $.date( this.options.value, this.options.dateFormat );
+               this.date = new $.ui.calendarDate( this.options.value, this._calendarDateOptions );
                this.viewDate = this.date.clone();
                this.viewDate.eachDay = this.options.eachDay;
 
@@ -178,23 +177,17 @@ return $.widget( "ui.calendar", {
        },
 
        _setLocale: function( locale ) {
-               var globalize;
+               var globalize = new Globalize( locale );
 
-               if ( typeof locale === "string" ) {
-                       globalize = new Globalize( locale );
-                       locale = {
-                               format: function( date ) {
+               this._format = function( date ) {
                                        return globalize.formatDate( date, { date: "short" } );
-                               },
-                               parse: function( stringDate ) {
+               };
+
+               this._parse = function( stringDate ) {
                                        return globalize.parseDate( stringDate, { date: "short" } );
-                               }
                        };
-               }
 
-               if ( !locale.firstDay ) {
-                       globalize = globalize || new Globalize( locale._locale );
-                       $.extend( locale, {
+               this._calendarDateOptions = {
                                firstDay: globalize.cldr.supplemental.weekData.firstDay(),
                                formatWeekdayShort: function( date ) {
 
@@ -212,11 +205,9 @@ return $.widget( "ui.calendar", {
                                },
                                formatWeekOfYear: function( date ) {
                                        return globalize.formatDate( date, { pattern: "w" } );
-                               }
-                       });
-               }
-
-               this.options.locale = locale;
+       },
+                       parse: this._parse
+               };
        },
 
        _createCalendar: function() {
@@ -562,11 +553,10 @@ return $.widget( "ui.calendar", {
        },
 
        value: function( value ) {
-               var locale = this.options.locale;
                if ( arguments.length ) {
                        this.valueAsDate( locale.parse( value ) );
                } else {
-                       return locale.format( this.option( "value" ) );
+                       return this._format( this.option( "value" ) );
                }
        },
 
@@ -658,7 +648,7 @@ return $.widget( "ui.calendar", {
 
                if ( key === "locale" ) {
                        this._setLocale( value );
-                       this.date.setAttributes( this.options.locale );
+                       this.date.setAttributes( this._calendarDateOptions );
                        this.refresh();
                }
        }
index 80ebdaf7a1d07734bff475a08d82097736c55f30..dcace34a935eee0e210abd9d3bc18f1bb2deffba 100644 (file)
@@ -38,7 +38,7 @@ var _Date,
 
 _Date = function( date, attributes ) {
        if ( !( this instanceof _Date ) ) {
-               return new _Date( date, options );
+               return new _Date( date, attributes );
        }
 
        this.setAttributes( attributes );
index 8faf67babb24127f4311add6a1c2c4821d942ef7..b95d5a4f100ed437c9adfd4724c34a0e4b1daa68 100644 (file)
@@ -61,10 +61,10 @@ var widget = $.widget( "ui.datepicker", {
                this._setLocale( this.options.locale );
 
                if ( $.type( this.options.max ) === "string" ) {
-                       this.options.max = this.options.locale.parseYMD( this.options.max );
+                       this.options.max = this._parseYMD( this.options.max );
                }
                if ( $.type( this.options.min ) === "string" ) {
-                       this.options.min = this.options.locale.parseYMD( this.options.min );
+                       this.options.min = this._parseYMD( this.options.min );
                }
 
                this._createCalendar();
@@ -282,22 +282,19 @@ var widget = $.widget( "ui.datepicker", {
        },
 
        _setLocale: function( locale ) {
-               if ( typeof locale === "string" ) {
-                       globalize = new Globalize( locale );
-                       locale = {
-                               _locale: locale,
-                               format: function( date ) {
-                                       return globalize.formatDate( date, { date: "short" } );
-                               },
-                               parse: function( stringDate ) {
-                                       return globalize.parseDate( stringDate, { date: "short" } );
-                               },
-                               parseYMD: function( stringDate ) {
-                                       return globalize.parseDate( stringDate, { pattern: "yyyy-MM-dd" } );
-                               }
-                       };
-               }
-               this.options.locale = locale;
+               var globalize = new Globalize( locale );
+
+               this._format = function( date ) {
+                       return globalize.formatDate( date, { date: "short" } );
+               };
+
+               this._parse = function( stringDate ) {
+                       return globalize.parseDate( stringDate, { date: "short" } );
+               };
+
+               this._parseYMD = function( stringDate ) {
+                       return globalize.parseDate( stringDate, { pattern: "yyyy-MM-dd" } );
+               };
        },
 
        _buildPosition: function() {
@@ -306,7 +303,7 @@ var widget = $.widget( "ui.datepicker", {
 
        value: function( value ) {
                if ( arguments.length ) {
-                       this.valueAsDate( this.options.locale.parse( value ) );
+                       this.valueAsDate( this._parse( value ) );
                } else {
                        return this._getParsedValue() ? this.element.val() : null;
                }
@@ -316,7 +313,7 @@ var widget = $.widget( "ui.datepicker", {
                if ( arguments.length ) {
                        if ( this.calendarInstance._isValid( value ) ) {
                                this.calendarInstance.valueAsDate( value );
-                               this.element.val( this.options.locale.format( value ) );
+                               this.element.val( this._format( value ) );
                        }
                } else {
                        return this._getParsedValue();
@@ -338,7 +335,7 @@ var widget = $.widget( "ui.datepicker", {
        },
 
        _getParsedValue: function() {
-               return this.options.locale.parse( this.element.val() );
+               return this._parse( this.element.val() );
        },
 
        _setOption: function( key, value ) {