]> source.dussan.org Git - jquery-ui.git/commitdiff
Datepicker: Use Globalize 1.0.0
authorFelix Nagel <info@felixnagel.com>
Thu, 30 Apr 2015 11:06:56 +0000 (13:06 +0200)
committerFelix Nagel <info@felixnagel.com>
Tue, 28 Jul 2015 22:04:22 +0000 (00:04 +0200)
- Fix merge conflict in value method
- Fix common unit tests
- Fix calendar localization tests
- Fix rebase regression: labels update on refresh
- Add new pass through options
- lint fixes

tests/unit/calendar/common.js
tests/unit/calendar/core.js
tests/unit/datepicker/common.js
ui/calendar.js
ui/datepicker.js

index bb0f64d0d3f272b78bcbcd6a59a609c2798e8f7b..8402cc8c70c61a50d9e565d1203260874dac798f 100644 (file)
@@ -1,16 +1,15 @@
-define( [
-       "lib/common",
-       "ui/calendar",
-       "globalize-locales"
-], function( common ) {
-
-common.testWidget( "calendar", {
+TestHelpers.commonWidgetTests( "calendar", {
        defaults: {
                buttons: [],
-               classes: {},
-               dateFormat: { date: "short" },
                disabled: false,
                eachDay: $.noop,
+               labels: {
+                       "datePickerRole": "date picker",
+                       "nextText": "Next",
+                       "prevText": "Prev",
+                       "weekHeader": "Wk"
+               },
+               locale: "en",
                max: null,
                min: null,
                numberOfMonths: 1,
@@ -22,5 +21,3 @@ common.testWidget( "calendar", {
                select: null
        }
 });
-
-} );
index c35eff4ebb4220b899ccbd603430e43028d90ab8..1f30419ac8ec6a80c697bac4dc2af716ec1199cb 100644 (file)
@@ -85,12 +85,18 @@ test( "base structure", function() {
 test( "Localization", function() {
        expect( 10 );
 
-       var defaultLocale = Globalize.locale(),
-               element = $( "#calendar" ),
+       var element = $( "#calendar" ),
                date = new Date( 2014, 0, 1 ),
-               initCalendar = function() {
+               optionsDe = {
+                       locale: "de",
+                       labels: {
+                               "nextText": "Vor",
+                               "prevText": "Zurück"
+                       }
+               },
+               initCalendar = function( options ) {
                        element
-                               .calendar()
+                               .calendar( options )
                                .calendar( "valueAsDate", date );
                },
                testLocalization = function( message ) {
@@ -108,26 +114,23 @@ test( "Localization", function() {
                        );
                        equal(
                                element.find( ".ui-calendar-prev" ).text(),
-                               "<Zurück", message + "header prev"
+                               "Zurück", message + "header prev"
                        );
                        equal(
                                element.find( ".ui-calendar-next" ).text(),
-                               "Vor>", message + "header next"
+                               "Vor", message + "header next"
                        );
                };
 
-       Globalize.locale( "de" );
-       initCalendar();
+       initCalendar( optionsDe );
        testLocalization( "Init: " );
        element.calendar( "destroy" );
 
-       Globalize.locale( defaultLocale.locale );
-       initCalendar();
-       Globalize.locale( "de" );
-       element.calendar( "refresh" );
+       initCalendar( {} );
+       element
+               .calendar( "option", optionsDe )
+               .calendar( "refresh" );
        testLocalization( "After init: " );
-
-       Globalize.locale( defaultLocale.locale );
 });
 
 asyncTest( "keyboard handling", function() {
index bd7aca89eaa75a41e813cf9c90ad896f22d3da8f..31ab5abef707e58553a7d91e4255a0744be7ac66 100644 (file)
@@ -1,17 +1,16 @@
-define( [
-       "lib/common",
-       "ui/datepicker",
-       "globalize-locales"
-], function( common ) {
-
-common.testWidget( "datepicker", {
+TestHelpers.commonWidgetTests( "datepicker", {
        defaults: {
                appendTo: null,
                buttons: [],
-               classes: {},
-               dateFormat: { date: "short" },
                disabled: false,
                eachDay: $.noop,
+               labels: {
+                       "datePickerRole": "date picker",
+                       "nextText": "Next",
+                       "prevText": "Prev",
+                       "weekHeader": "Wk"
+               },
+               locale: "en",
                max: null,
                min: null,
                numberOfMonths: 1,
@@ -31,5 +30,3 @@ common.testWidget( "datepicker", {
                select: null
        }
 });
-
-} );
index b773281ab3a8d47eabbf3273214877f13aed610b..78eccb51b7692d24fb2f14ea86ba031b91424c5a 100644 (file)
@@ -180,16 +180,18 @@ return $.widget( "ui.calendar", {
                var globalize = new Globalize( locale ),
                        weekdayShortFormatter = globalize.dateFormatter({ pattern: "EEEEEE" }),
                        weekdayNarrowFormatter = globalize.dateFormatter({ pattern: "EEEEE" });
+
                this._format = globalize.dateFormatter({ date: "short" });
                this._parse = globalize.dateParser({ date: "short" });
                this._calendarDateOptions = {
-                               firstDay: globalize.cldr.supplemental.weekData.firstDay(),
-                               formatWeekdayShort: function( date ) {
+                       firstDay: globalize.cldr.supplemental.weekData.firstDay(),
+                       formatWeekdayShort: function( date ) {
 
-                                       // Return the short weekday if its length is < 3. Otherwise, its narrow form.
+                               // Return the short weekday if its length is < 3. Otherwise, its narrow form.
                                var shortWeekday = weekdayShortFormatter( date );
+
                                return shortWeekday.length > 3 ? weekdayNarrowFormatter( date ) : shortWeekday;
-                               },
+                       },
                        formatWeekdayFull: globalize.dateFormatter({ pattern: "EEEE" }),
                        formatMonth: globalize.dateFormatter({ pattern: "MMMM" }),
                        formatWeekOfYear: globalize.dateFormatter({ pattern: "w" }),
@@ -325,7 +327,7 @@ return $.widget( "ui.calendar", {
                if ( this.options.showWeek ) {
                        cells += "<th class='ui-calendar-week-col'>" + this._getTranslation( "weekHeader" ) + "</th>";
                }
-               for ( i; i < weekDayLength; i++ ) {
+               for ( ; i < weekDayLength; i++ ) {
                        cells += this._buildGridHeaderCell( weekdays[ i ] );
                }
 
@@ -492,6 +494,7 @@ return $.widget( "ui.calendar", {
        // with the prev and next links would cause loss of focus issues because the links being
        // interacted with will disappear while focused.
        refresh: function() {
+               this.labels = this.options.labels;
 
                // Determine which day gridcell to focus after refresh
                // TODO: Prevent disabled cells from being focused
@@ -541,7 +544,7 @@ return $.widget( "ui.calendar", {
 
        value: function( value ) {
                if ( arguments.length ) {
-                       this.valueAsDate( locale.parse( value ) );
+                       this.valueAsDate( this._parse( value ) );
                } else {
                        return this._format( this.option( "value" ) );
                }
index 8139782154a891f1bc1fab31db1695616820d271..df61becb5e9a341358fd767e8677a6d314147026 100644 (file)
@@ -37,7 +37,6 @@ var widget = $.widget( "ui.datepicker", {
        version: "@VERSION",
        options: {
                appendTo: null,
-               locale: "en",
                position: {
                        my: "left top",
                        at: "left bottom"
@@ -52,8 +51,8 @@ var widget = $.widget( "ui.datepicker", {
                select: null
        },
 
-       calendarOptions: [ "buttons", "dateFormat", "disabled", "eachDay", "max",
-               "min", "numberOfMonths", "showWeek" ],
+       calendarOptions: [ "buttons", "disabled", "eachDay", "labels", "locale",
+               "max", "min", "numberOfMonths", "showWeek" ],
 
        _create: function() {
                this.suppressExpandOnFocus = false;
@@ -283,6 +282,7 @@ var widget = $.widget( "ui.datepicker", {
 
        _setLocale: function( locale ) {
                var globalize = new Globalize( locale );
+
                this._format = globalize.dateFormatter({ date: "short" });
                this._parse = globalize.dateParser({ date: "short" });
                this._parseYMD = globalize.dateParser({ pattern: "yyyy-MM-dd" });