From 5d044dd88c2f83855aaed5bb0164e7fabd2e98f0 Mon Sep 17 00:00:00 2001 From: Rafael Xavier de Souza Date: Thu, 4 Sep 2014 15:47:48 -0300 Subject: [PATCH] (fix) Datepicker: Use Globalize 1.0.0 - user cannot provide locale: {fn1: ..., fn2:...} with all the formatters and parsers --- ui/calendar.js | 34 ++++++++++++---------------------- ui/calendar/date.js | 2 +- ui/datepicker.js | 39 ++++++++++++++++++--------------------- 3 files changed, 31 insertions(+), 44 deletions(-) diff --git a/ui/calendar.js b/ui/calendar.js index 40f90fe7b..da8604458 100644 --- a/ui/calendar.js +++ b/ui/calendar.js @@ -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(); } } diff --git a/ui/calendar/date.js b/ui/calendar/date.js index 80ebdaf7a..dcace34a9 100644 --- a/ui/calendar/date.js +++ b/ui/calendar/date.js @@ -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 ); diff --git a/ui/datepicker.js b/ui/datepicker.js index 8faf67bab..b95d5a4f1 100644 --- a/ui/datepicker.js +++ b/ui/datepicker.js @@ -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 ) { -- 2.39.5