(fix) Datepicker: Use Globalize 1.0.0

- user cannot provide locale: {fn1: ..., fn2:...} with all the
  formatters and parsers
This commit is contained in:
Rafael Xavier de Souza 2014-09-04 15:47:48 -03:00 committed by Felix Nagel
parent b6d7436756
commit 5d044dd88c
3 changed files with 33 additions and 46 deletions

View 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 ) {
return globalize.parseDate( stringDate, { date: "short" } );
}
};
}
};
if ( !locale.firstDay ) {
globalize = globalize || new Globalize( locale._locale );
$.extend( locale, {
this._parse = function( stringDate ) {
return globalize.parseDate( stringDate, { date: "short" } );
};
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();
}
}

View 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 );

View 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 ) {