OLD | NEW |
---|---|
1 "use strict"; | 1 "use strict"; |
2 /* | 2 /* |
3 * Copyright (C) 2012 Google Inc. All rights reserved. | 3 * Copyright (C) 2012 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 * @return {!boolean} | 68 * @return {!boolean} |
69 */ | 69 */ |
70 function hasInaccuratePointingDevice() { | 70 function hasInaccuratePointingDevice() { |
71 return matchMedia("(pointer: coarse)").matches; | 71 return matchMedia("(pointer: coarse)").matches; |
72 } | 72 } |
73 | 73 |
74 /** | 74 /** |
75 * @return {!string} lowercase locale name. e.g. "en-us" | 75 * @return {!string} lowercase locale name. e.g. "en-us" |
76 */ | 76 */ |
77 function getLocale() { | 77 function getLocale() { |
78 return (global.params.locale || "en-us").toLowerCase(); | 78 return (global.params.locale || "en-us").toLowerCase().replace(/_/, '-'); |
keishi
2014/09/03 12:09:35
nit: I'm not sure but could the locale have two un
tkent
2014/09/05 04:54:47
That's right. The regex should be /_/g
| |
79 } | 79 } |
80 | 80 |
81 /** | 81 /** |
82 * @return {!string} lowercase language code. e.g. "en" | 82 * @return {!string} lowercase language code. e.g. "en" |
83 */ | 83 */ |
84 function getLanguage() { | 84 function getLanguage() { |
85 var locale = getLocale(); | 85 var locale = getLocale(); |
86 var result = locale.match(/^([a-z]+)/); | 86 var result = locale.match(/^([a-z]+)/); |
87 if (!result) | 87 if (!result) |
88 return "en"; | 88 return "en"; |
(...skipping 1464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1553 ScrollView.prototype.contentPositionForContentOffset = function(offset) { | 1553 ScrollView.prototype.contentPositionForContentOffset = function(offset) { |
1554 return offset - this._partitionNumber * ScrollView.PartitionHeight; | 1554 return offset - this._partitionNumber * ScrollView.PartitionHeight; |
1555 }; | 1555 }; |
1556 | 1556 |
1557 /** | 1557 /** |
1558 * @constructor | 1558 * @constructor |
1559 * @extends View | 1559 * @extends View |
1560 */ | 1560 */ |
1561 function ListCell() { | 1561 function ListCell() { |
1562 View.call(this, createElement("div", ListCell.ClassNameListCell)); | 1562 View.call(this, createElement("div", ListCell.ClassNameListCell)); |
1563 this.element.setAttribute("role", "gridcell"); | |
1563 | 1564 |
1564 /** | 1565 /** |
1565 * @type {!number} | 1566 * @type {!number} |
1566 */ | 1567 */ |
1567 this.row = NaN; | 1568 this.row = NaN; |
1568 /** | 1569 /** |
1569 * @type {!number} | 1570 * @type {!number} |
1570 */ | 1571 */ |
1571 this._width = 0; | 1572 this._width = 0; |
1572 /** | 1573 /** |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1652 this.element.classList.remove("selected"); | 1653 this.element.classList.remove("selected"); |
1653 }; | 1654 }; |
1654 | 1655 |
1655 /** | 1656 /** |
1656 * @constructor | 1657 * @constructor |
1657 * @extends View | 1658 * @extends View |
1658 */ | 1659 */ |
1659 function ListView() { | 1660 function ListView() { |
1660 View.call(this, createElement("div", ListView.ClassNameListView)); | 1661 View.call(this, createElement("div", ListView.ClassNameListView)); |
1661 this.element.tabIndex = 0; | 1662 this.element.tabIndex = 0; |
1663 this.element.setAttribute("role", "grid"); | |
1662 | 1664 |
1663 /** | 1665 /** |
1664 * @type {!number} | 1666 * @type {!number} |
1665 * @private | 1667 * @private |
1666 */ | 1668 */ |
1667 this._width = 0; | 1669 this._width = 0; |
1668 /** | 1670 /** |
1669 * @type {!Object} | 1671 * @type {!Object} |
1670 * @private | 1672 * @private |
1671 */ | 1673 */ |
(...skipping 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3062 */ | 3064 */ |
3063 DayCell.prototype.throwAway = function() { | 3065 DayCell.prototype.throwAway = function() { |
3064 ListCell.prototype.throwAway.call(this); | 3066 ListCell.prototype.throwAway.call(this); |
3065 this.day = null; | 3067 this.day = null; |
3066 }; | 3068 }; |
3067 | 3069 |
3068 /** | 3070 /** |
3069 * @param {!boolean} highlighted | 3071 * @param {!boolean} highlighted |
3070 */ | 3072 */ |
3071 DayCell.prototype.setHighlighted = function(highlighted) { | 3073 DayCell.prototype.setHighlighted = function(highlighted) { |
3072 if (highlighted) | 3074 if (highlighted) { |
3073 this.element.classList.add(DayCell.ClassNameHighlighted); | 3075 this.element.classList.add(DayCell.ClassNameHighlighted); |
3074 else | 3076 this.element.setAttribute("aria-selected", "true"); |
3077 } else { | |
3075 this.element.classList.remove(DayCell.ClassNameHighlighted); | 3078 this.element.classList.remove(DayCell.ClassNameHighlighted); |
3079 this.element.setAttribute("aria-selected", "false"); | |
3080 } | |
3076 }; | 3081 }; |
3077 | 3082 |
3078 /** | 3083 /** |
3079 * @param {!boolean} disabled | 3084 * @param {!boolean} disabled |
3080 */ | 3085 */ |
3081 DayCell.prototype.setDisabled = function(disabled) { | 3086 DayCell.prototype.setDisabled = function(disabled) { |
3082 if (disabled) | 3087 if (disabled) |
3083 this.element.classList.add(DayCell.ClassNameDisabled); | 3088 this.element.classList.add(DayCell.ClassNameDisabled); |
3084 else | 3089 else |
3085 this.element.classList.remove(DayCell.ClassNameDisabled); | 3090 this.element.classList.remove(DayCell.ClassNameDisabled); |
(...skipping 18 matching lines...) Expand all Loading... | |
3104 else | 3109 else |
3105 this.element.classList.remove(DayCell.ClassNameToday); | 3110 this.element.classList.remove(DayCell.ClassNameToday); |
3106 }; | 3111 }; |
3107 | 3112 |
3108 /** | 3113 /** |
3109 * @param {!Day} day | 3114 * @param {!Day} day |
3110 */ | 3115 */ |
3111 DayCell.prototype.reset = function(day) { | 3116 DayCell.prototype.reset = function(day) { |
3112 this.day = day; | 3117 this.day = day; |
3113 this.element.textContent = localizeNumber(this.day.date.toString()); | 3118 this.element.textContent = localizeNumber(this.day.date.toString()); |
3119 if (!DayCell.formatter) { | |
3120 DayCell.formatter = new Intl.DateTimeFormat(getLocale(), { | |
3121 weekday: "long", year: "numeric", month: "long", day: "numeric" | |
3122 }); | |
3123 } | |
3124 this.element.setAttribute("aria-label", DayCell.formatter.format(this.day.st artDate())); | |
3125 this.element.id = this.day.toString(); | |
3114 this.show(); | 3126 this.show(); |
3115 }; | 3127 }; |
3116 | 3128 |
3117 /** | 3129 /** |
3118 * @constructor | 3130 * @constructor |
3119 * @extends ListCell | 3131 * @extends ListCell |
3120 */ | 3132 */ |
3121 function WeekNumberCell() { | 3133 function WeekNumberCell() { |
3122 ListCell.call(this); | 3134 ListCell.call(this); |
3123 this.element.classList.add(WeekNumberCell.ClassNameWeekNumberCell); | 3135 this.element.classList.add(WeekNumberCell.ClassNameWeekNumberCell); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3219 CalendarTableHeaderView.Height = 25; | 3231 CalendarTableHeaderView.Height = 25; |
3220 | 3232 |
3221 /** | 3233 /** |
3222 * @constructor | 3234 * @constructor |
3223 * @extends ListCell | 3235 * @extends ListCell |
3224 */ | 3236 */ |
3225 function CalendarRowCell() { | 3237 function CalendarRowCell() { |
3226 ListCell.call(this); | 3238 ListCell.call(this); |
3227 this.element.classList.add(CalendarRowCell.ClassNameCalendarRowCell); | 3239 this.element.classList.add(CalendarRowCell.ClassNameCalendarRowCell); |
3228 this.element.style.height = CalendarRowCell.Height + "px"; | 3240 this.element.style.height = CalendarRowCell.Height + "px"; |
3241 this.element.setAttribute("role", "row"); | |
3229 | 3242 |
3230 /** | 3243 /** |
3231 * @type {!Array} | 3244 * @type {!Array} |
3232 * @protected | 3245 * @protected |
3233 */ | 3246 */ |
3234 this._dayCells = []; | 3247 this._dayCells = []; |
3235 /** | 3248 /** |
3236 * @type {!number} | 3249 * @type {!number} |
3237 */ | 3250 */ |
3238 this.row = 0; | 3251 this.row = 0; |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3504 lastDayInHighlight = Infinity; | 3517 lastDayInHighlight = Infinity; |
3505 } | 3518 } |
3506 var currentMonth = this.calendarPicker.currentMonth(); | 3519 var currentMonth = this.calendarPicker.currentMonth(); |
3507 var firstDayInCurrentMonth = currentMonth.firstDay().valueOf(); | 3520 var firstDayInCurrentMonth = currentMonth.firstDay().valueOf(); |
3508 var lastDayInCurrentMonth = currentMonth.lastDay().valueOf(); | 3521 var lastDayInCurrentMonth = currentMonth.lastDay().valueOf(); |
3509 for (var dayString in this._dayCells) { | 3522 for (var dayString in this._dayCells) { |
3510 var dayCell = this._dayCells[dayString]; | 3523 var dayCell = this._dayCells[dayString]; |
3511 var day = dayCell.day; | 3524 var day = dayCell.day; |
3512 dayCell.setIsToday(Day.createFromToday().equals(day)); | 3525 dayCell.setIsToday(Day.createFromToday().equals(day)); |
3513 dayCell.setSelected(day >= firstDayInSelection && day <= lastDayInSelect ion); | 3526 dayCell.setSelected(day >= firstDayInSelection && day <= lastDayInSelect ion); |
3514 dayCell.setHighlighted(day >= firstDayInHighlight && day <= lastDayInHig hlight); | 3527 var isHighlighted = day >= firstDayInHighlight && day <= lastDayInHighli ght; |
3528 dayCell.setHighlighted(isHighlighted); | |
3529 if (isHighlighted && firstDayInHighlight == lastDayInHighlight) | |
3530 this.element.setAttribute("aria-activedescendant", dayCell.element.i d); | |
3515 dayCell.setIsInCurrentMonth(day >= firstDayInCurrentMonth && day <= last DayInCurrentMonth); | 3531 dayCell.setIsInCurrentMonth(day >= firstDayInCurrentMonth && day <= last DayInCurrentMonth); |
3516 dayCell.setDisabled(!this.calendarPicker.isValidDay(day)); | 3532 dayCell.setDisabled(!this.calendarPicker.isValidDay(day)); |
3517 } | 3533 } |
3518 if (this.hasWeekNumberColumn) { | 3534 if (this.hasWeekNumberColumn) { |
3519 for (var weekString in this._weekNumberCells) { | 3535 for (var weekString in this._weekNumberCells) { |
3520 var weekNumberCell = this._weekNumberCells[weekString]; | 3536 var weekNumberCell = this._weekNumberCells[weekString]; |
3521 var week = weekNumberCell.week; | 3537 var week = weekNumberCell.week; |
3522 weekNumberCell.setSelected(selection && selection.equals(week)); | 3538 weekNumberCell.setSelected(selection && selection.equals(week)); |
3523 weekNumberCell.setHighlighted(highlight && highlight.equals(week)); | 3539 weekNumberCell.setHighlighted(highlight && highlight.equals(week)); |
3524 weekNumberCell.setDisabled(!this.calendarPicker.isValid(week)); | 3540 weekNumberCell.setDisabled(!this.calendarPicker.isValid(week)); |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4038 event.stopPropagation(); | 4054 event.stopPropagation(); |
4039 event.preventDefault(); | 4055 event.preventDefault(); |
4040 } | 4056 } |
4041 }; | 4057 }; |
4042 | 4058 |
4043 if (window.dialogArguments) { | 4059 if (window.dialogArguments) { |
4044 initialize(dialogArguments); | 4060 initialize(dialogArguments); |
4045 } else { | 4061 } else { |
4046 window.addEventListener("message", handleMessage, false); | 4062 window.addEventListener("message", handleMessage, false); |
4047 } | 4063 } |
OLD | NEW |