|
5 | 5 | * Provider that allows the user to specify messages, formatters, and parsers for date
|
6 | 6 | * internationalization.
|
7 | 7 | */
|
| 8 | + |
| 9 | + |
| 10 | + /** |
| 11 | + * @ngdoc service |
| 12 | + * @name $mdDateLocaleProvider |
| 13 | + * @module material.components.datepicker |
| 14 | + * |
| 15 | + * @description |
| 16 | + * The `$mdDateLocaleProvider` is the provider that creates the `$mdDateLocale` service. |
| 17 | + * This provider that allows the user to specify messages, formatters, and parsers for date |
| 18 | + * internationalization. The `$mdDateLocale` service itself is consumed by Angular Material |
| 19 | + * components that that deal with dates. |
| 20 | + * |
| 21 | + * @usage |
| 22 | + * <hljs lang="js"> |
| 23 | + * myAppModule.config(function($mdDateLocaleProvider) { |
| 24 | + * |
| 25 | + * // Example of a French localization. |
| 26 | + * $mdDateLocaleProvider.months = ['Janvier', 'Février', 'Mars', ...]; |
| 27 | + * $mdDateLocaleProvider.shortMonths = ['Janv', 'Févr', 'Mars', ...]; |
| 28 | + * $mdDateLocaleProvider.days = ['Lundi', 'Mardi', 'Mercredi', ...]; |
| 29 | + * $mdDateLocaleProvider.shortDays = ['L', 'M', 'M', ...]; |
| 30 | + * $mdDateLocaleProvider.dates = [1, 2, 3, 4, 5, 6, ...]; |
| 31 | + * |
| 32 | + * // Example uses moment.js to parse and format dates. |
| 33 | + * $mdDateLocaleProvider.formatDate = function(date) { |
| 34 | + * return moment(date).format |
| 35 | + * }; |
| 36 | + * $mdDateLocaleProvider.parseDate = function(dateString) { |
| 37 | + * return moment(dateString).toDate('L'); |
| 38 | + * }; |
| 39 | + * |
| 40 | + * $mdDateLocaleProvider.monthHeaderFormatter = function(date) { |
| 41 | + * $mdDateLocale.shortMonths[date.getMonth()] + ' ' + date.getFullYear(); |
| 42 | + * }; |
| 43 | + * |
| 44 | + * $mdDateLocaleProvider.weekNumberFormatter = function(weekNumber) { |
| 45 | + * return 'Semaine ' + weekNumber; |
| 46 | + * }; |
| 47 | + * |
| 48 | + * $mdDateLocaleProvider.msgCalendar = 'Calendrier'; |
| 49 | + * $mdDateLocaleProvider.msgOpenCalendar = 'Ouvrir le calendrier'; |
| 50 | + * |
| 51 | + * }); |
| 52 | + * </hljs> |
| 53 | + * |
| 54 | + */ |
8 | 55 | angular.module('material.components.datepicker').config(function($provide) {
|
9 | 56 | // TODO(jelbourn): Assert provided values are correctly formatted. Need assertions.
|
10 | 57 |
|
|
50 | 97 | this.weekNumberFormatter = null;
|
51 | 98 |
|
52 | 99 | /**
|
53 |
| - * Function that formats a date into a short aria-live announcement that is read when |
54 |
| - * the focused date changes within the same month. |
55 |
| - * @type {function(Date): string} |
56 |
| - */ |
57 |
| - this.shortAnnounceFormatter = null; |
58 |
| - |
59 |
| - /** |
60 |
| - * Function that formats a date into a long aria-live announcement that is read when |
61 |
| - * the focused date changes to a date in a different month. |
| 100 | + * Function that formats a date into a long aria-label that is read |
| 101 | + * when the focused date changes. |
62 | 102 | * @type {function(Date): string}
|
63 | 103 | */
|
64 |
| - this.longAnnounceFormatter = null; |
| 104 | + this.longDateFormatter = null; |
65 | 105 |
|
66 | 106 | /**
|
67 | 107 | * ARIA label for the calendar "dialog" used in the datepicker.
|
|
120 | 160 | }
|
121 | 161 |
|
122 | 162 | /**
|
123 |
| - * Default formatter for short aria-live announcements. |
124 |
| - * @param {!Date} date |
125 |
| - * @returns {string} |
126 |
| - */ |
127 |
| - function defaultShortAnnounceFormatter(date) { |
128 |
| - // Example: 'Tuesday 12' |
129 |
| - return service.days[date.getDay()] + ' ' + service.dates[date.getDate()]; |
130 |
| - } |
131 |
| - |
132 |
| - /** |
133 |
| - * Default formatter for long aria-live announcements. |
| 163 | + * Default formatter for date cell aria-labels. |
134 | 164 | * @param {!Date} date
|
135 | 165 | * @returns {string}
|
136 | 166 | */
|
137 |
| - function defaultLongAnnounceFormatter(date) { |
| 167 | + function defaultLongDateFormatter(date) { |
138 | 168 | // Example: 'Thursday June 18 2015'
|
139 | 169 | return [
|
140 | 170 | service.days[date.getDay()],
|
|
170 | 200 | parseDate: this.parseDate || defaultParseDate,
|
171 | 201 | monthHeaderFormatter: this.monthHeaderFormatter || defaultMonthHeaderFormatter,
|
172 | 202 | weekNumberFormatter: this.weekNumberFormatter || defaultWeekNumberFormatter,
|
173 |
| - shortAnnounceFormatter: this.shortAnnounceFormatter || defaultShortAnnounceFormatter, |
174 |
| - longAnnounceFormatter: this.longAnnounceFormatter || defaultLongAnnounceFormatter, |
| 203 | + longDateFormatter: this.longDateFormatter || defaultLongDateFormatter, |
175 | 204 | msgCalendar: this.msgCalendar || defaultMsgCalendar,
|
176 | 205 | msgOpenCalendar: this.msgOpenCalendar || defaultMsgOpenCalendar
|
177 | 206 | });
|
178 | 207 |
|
179 | 208 | return service;
|
180 | 209 | };
|
181 | 210 |
|
182 |
| - $provide.provider('$$mdDateLocale', new DateLocaleProvider()); |
| 211 | + $provide.provider('$mdDateLocale', new DateLocaleProvider()); |
183 | 212 | });
|
184 | 213 | })();
|
0 commit comments