diff --git a/toolkit/content/widgets/datekeeper.js b/toolkit/content/widgets/datekeeper.js
index 62fcfadbc3..de01fdadee 100644
--- a/toolkit/content/widgets/datekeeper.js
+++ b/toolkit/content/widgets/datekeeper.js
@@ -11,7 +11,7 @@
* {
* {Number} year
* {Number} month
- * {Number} date
+ * {Number} day
* }
* {Object} options
* {
@@ -20,7 +20,7 @@
* {Number} calViewSize [optional]
* }
*/
-function DateKeeper({ year, month, date }, { firstDayOfWeek = 0, weekends = [0], calViewSize = 42 }) {
+function DateKeeper({ year, month, day }, { firstDayOfWeek = 0, weekends = [0], calViewSize = 42 }) {
this.state = {
firstDayOfWeek, weekends, calViewSize,
dateObj: new Date(0),
@@ -29,7 +29,7 @@ function DateKeeper({ year, month, date }, { firstDayOfWeek = 0, weekends = [0],
days: []
};
this.state.weekHeaders = this._getWeekHeaders(firstDayOfWeek);
- this._update(year, month, date);
+ this._update(year, month, day);
}
{
@@ -48,8 +48,8 @@ function DateKeeper({ year, month, date }, { firstDayOfWeek = 0, weekends = [0],
* {Number} date [optional]
* }
*/
- set({ year = this.state.year, month = this.state.month, date = this.state.date }) {
- this._update(year, month, date);
+ set({ year = this.state.year, month = this.state.month, day = this.state.day }) {
+ this._update(year, month, day);
},
/**
@@ -62,44 +62,44 @@ function DateKeeper({ year, month, date }, { firstDayOfWeek = 0, weekends = [0],
},
/**
- * Set month. Makes sure the date is <= the last day of the month
+ * Set month. Makes sure the day is <= the last day of the month
* @param {Number} month
*/
setMonth(month) {
const lastDayOfMonth = this._newUTCDate(this.state.year, month + 1, 0).getUTCDate();
- this._update(this.state.year, month, Math.min(this.state.date, lastDayOfMonth));
+ this._update(this.state.year, month, Math.min(this.state.day, lastDayOfMonth));
},
/**
- * Set year. Makes sure the date is <= the last day of the month
+ * Set year. Makes sure the day is <= the last day of the month
* @param {Number} year
*/
setYear(year) {
const lastDayOfMonth = this._newUTCDate(year, this.state.month + 1, 0).getUTCDate();
- this._update(year, this.state.month, Math.min(this.state.date, lastDayOfMonth));
+ this._update(year, this.state.month, Math.min(this.state.day, lastDayOfMonth));
},
/**
- * Set month by offset. Makes sure the date is <= the last day of the month
+ * Set month by offset. Makes sure the day is <= the last day of the month
* @param {Number} offset
*/
setMonthByOffset(offset) {
const lastDayOfMonth = this._newUTCDate(this.state.year, this.state.month + offset + 1, 0).getUTCDate();
- this._update(this.state.year, this.state.month + offset, Math.min(this.state.date, lastDayOfMonth));
+ this._update(this.state.year, this.state.month + offset, Math.min(this.state.day, lastDayOfMonth));
},
/**
* Update the states.
* @param {Number} year [description]
* @param {Number} month [description]
- * @param {Number} date [description]
+ * @param {Number} day [description]
*/
- _update(year, month, date) {
+ _update(year, month, day) {
// Use setUTCFullYear so that year 99 doesn't get parsed as 1999
- this.state.dateObj.setUTCFullYear(year, month, date);
+ this.state.dateObj.setUTCFullYear(year, month, day);
this.state.year = this.state.dateObj.getUTCFullYear();
this.state.month = this.state.dateObj.getUTCMonth();
- this.state.date = this.state.dateObj.getUTCDate();
+ this.state.day = this.state.dateObj.getUTCDate();
},
/**
@@ -201,14 +201,14 @@ function DateKeeper({ year, month, date }, { firstDayOfWeek = 0, weekends = [0],
*/
_getWeekHeaders(firstDayOfWeek) {
let headers = [];
- let day = firstDayOfWeek;
+ let dayOfWeek = firstDayOfWeek;
for (let i = 0; i < DAYS_IN_A_WEEK; i++) {
headers.push({
- textContent: day % DAYS_IN_A_WEEK,
- classNames: this.state.weekends.includes(day % DAYS_IN_A_WEEK) ? ["weekend"] : []
+ textContent: dayOfWeek % DAYS_IN_A_WEEK,
+ classNames: this.state.weekends.includes(dayOfWeek % DAYS_IN_A_WEEK) ? ["weekend"] : []
});
- day++;
+ dayOfWeek++;
}
return headers;
},
diff --git a/toolkit/content/widgets/datepicker.js b/toolkit/content/widgets/datepicker.js
index 7453b67eb3..210ca856cf 100644
--- a/toolkit/content/widgets/datepicker.js
+++ b/toolkit/content/widgets/datepicker.js
@@ -37,13 +37,13 @@ function DatePicker(context) {
const now = new Date();
const { year = now.getFullYear(),
month = now.getMonth(),
- date = now.getDate(),
+ day = now.getDate(),
locale } = this.props;
// TODO: Use calendar info API to get first day of week & weekends
// (Bug 1287503)
const dateKeeper = new DateKeeper({
- year, month, date
+ year, month, day
}, {
calViewSize: CAL_VIEW_SIZE,
firstDayOfWeek: 0,
@@ -68,6 +68,7 @@ function DatePicker(context) {
this.state.isDateSet = true;
this._update();
this._dispatchState();
+ this._closePopup();
},
setYear: year => {
dateKeeper.setYear(year);
@@ -148,23 +149,32 @@ function DatePicker(context) {
this.context.monthYearView.classList.add("hidden");
},
+ /**
+ * Use postMessage to close the picker.
+ */
+ _closePopup() {
+ window.postMessage({
+ name: "ClosePopup"
+ }, "*");
+ },
+
/**
* Use postMessage to pass the state of picker to the panel.
*/
_dispatchState() {
- const { year, month, date } = this.state.dateKeeper.state;
- const { isYearSet, isMonthSet, isDateSet } = this.state;
+ const { year, month, day } = this.state.dateKeeper.state;
+ const { isYearSet, isMonthSet, isDaySet } = this.state;
// The panel is listening to window for postMessage event, so we
// do postMessage to itself to send data to input boxes.
window.postMessage({
- name: "DatePickerPopupChanged",
+ name: "PickerPopupChanged",
detail: {
year,
month,
- date,
+ day,
isYearSet,
isMonthSet,
- isDateSet
+ isDaySet
}
}, "*");
},
@@ -221,11 +231,11 @@ function DatePicker(context) {
*/
handleMessage(event) {
switch (event.data.name) {
- case "DatePickerSetValue": {
+ case "PickerSetValue": {
this.set(event.data.detail);
break;
}
- case "DatePickerInit": {
+ case "PickerInit": {
this.init(event.data.detail);
break;
}
@@ -242,18 +252,22 @@ function DatePicker(context) {
* {Number} date [optional]
* }
*/
- set(dateState) {
- if (dateState.year != undefined) {
+ set({ year, month, day }) {
+ const { dateKeeper } = this.state;
+
+ if (year != undefined) {
this.state.isYearSet = true;
}
- if (dateState.month != undefined) {
+ if (month != undefined) {
this.state.isMonthSet = true;
}
- if (dateState.date != undefined) {
- this.state.isDateSet = true;
+ if (day != undefined) {
+ this.state.isDaySet = true;
}
- this.state.dateKeeper.set(dateState);
+ dateKeeper.set({
+ year, month, day
+ });
this._update();
}
};
diff --git a/toolkit/content/widgets/datetimepopup.xml b/toolkit/content/widgets/datetimepopup.xml
index 69edffe259..86e8780c15 100644
--- a/toolkit/content/widgets/datetimepopup.xml
+++ b/toolkit/content/widgets/datetimepopup.xml
@@ -20,6 +20,8 @@
"12em"
"21em"
+ "23.1em"
+ "20.7em"
@@ -38,6 +40,14 @@
this.dateTimePopupFrame.style.height = this.TIME_PICKER_HEIGHT;
break;
}
+ case "date": {
+ this.detail = detail;
+ this.dateTimePopupFrame.addEventListener("load", this, true);
+ this.dateTimePopupFrame.setAttribute("src", "chrome://global/content/datepicker.xhtml");
+ this.dateTimePopupFrame.style.width = this.DATE_PICKER_WIDTH;
+ this.dateTimePopupFrame.style.height = this.DATE_PICKER_HEIGHT;
+ break;
+ }
}
]]>