assets/javascripts/materialize/datepicker.js in materialize-sass-1.0.0.alpha4 vs assets/javascripts/materialize/datepicker.js in materialize-sass-1.0.0.beta
- old
+ new
@@ -58,14 +58,17 @@
showDaysInNextAndPreviousMonths: false,
// Specify a DOM element to render the calendar in
container: null,
+ // Show clear button
+ showClearBtn: false,
+
// internationalization
i18n: {
+ cancel: 'Cancel',
clear: 'Clear',
- today: 'Today',
done: 'Ok',
previousMonth: '‹',
nextMonth: '›',
months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
monthsShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
@@ -159,22 +162,38 @@
*/
value: function destroy() {
this._removeEventHandlers();
this.modal.destroy();
$(this.modalEl).remove();
+ this.destroySelects();
this.el.M_Datepicker = undefined;
}
}, {
+ key: 'destroySelects',
+ value: function destroySelects() {
+ var oldYearSelect = this.calendarEl.querySelector('.pika-select-year');
+ if (oldYearSelect) {
+ M.FormSelect.getInstance(oldYearSelect).destroy();
+ }
+ var oldMonthSelect = this.calendarEl.querySelector('.pika-select-month');
+ if (oldMonthSelect) {
+ M.FormSelect.getInstance(oldMonthSelect).destroy();
+ }
+ }
+ }, {
key: '_insertHTMLIntoDOM',
value: function _insertHTMLIntoDOM() {
- this.clearBtn.innerHTML = this.options.i18n.clear;
- this.todayBtn.innerHTML = this.options.i18n.today;
+ if (this.options.showClearBtn) {
+ $(this.clearBtn).css({ visibility: '' });
+ this.clearBtn.innerHTML = this.options.i18n.clear;
+ }
+
this.doneBtn.innerHTML = this.options.i18n.done;
+ this.cancelBtn.innerHTML = this.options.i18n.cancel;
- var containerEl = document.querySelector(this.options.container);
- if (this.options.container && !!containerEl) {
- this.$modalEl.appendTo(containerEl);
+ if (this.options.container) {
+ this.$modalEl.appendTo(this.options.container);
} else {
this.$modalEl.insertBefore(this.el);
}
}
}, {
@@ -577,19 +596,11 @@
for (var c = 0; c < 1; c++) {
this._renderDateDisplay();
html += this.renderTitle(this, c, this.calendars[c].year, this.calendars[c].month, this.calendars[0].year, randId) + this.render(this.calendars[c].year, this.calendars[c].month, randId);
}
- // Destroy Materialize Select
- var oldYearSelect = this.calendarEl.querySelector('.pika-select-year');
- if (oldYearSelect) {
- M.FormSelect.getInstance(oldYearSelect).destroy();
- }
- var oldMonthSelect = this.calendarEl.querySelector('.pika-select-month');
- if (oldMonthSelect) {
- M.FormSelect.getInstance(oldMonthSelect).destroy();
- }
+ this.destroySelects();
this.calendarEl.innerHTML = html;
// Init Materialize Select
var yearSelect = this.calendarEl.querySelector('.pika-select-year');
@@ -616,21 +627,24 @@
this._handleInputKeydownBound = this._handleInputKeydown.bind(this);
this._handleInputClickBound = this._handleInputClick.bind(this);
this._handleInputChangeBound = this._handleInputChange.bind(this);
this._handleCalendarClickBound = this._handleCalendarClick.bind(this);
this._finishSelectionBound = this._finishSelection.bind(this);
- this._handleTodayClickBound = this._handleTodayClick.bind(this);
- this._handleClearClickBound = this._handleClearClick.bind(this);
this._handleMonthChange = this._handleMonthChange.bind(this);
+ this._closeBound = this.close.bind(this);
this.el.addEventListener('click', this._handleInputClickBound);
this.el.addEventListener('keydown', this._handleInputKeydownBound);
this.el.addEventListener('change', this._handleInputChangeBound);
this.calendarEl.addEventListener('click', this._handleCalendarClickBound);
this.doneBtn.addEventListener('click', this._finishSelectionBound);
- this.todayBtn.addEventListener('click', this._handleTodayClickBound);
- this.clearBtn.addEventListener('click', this._handleClearClickBound);
+ this.cancelBtn.addEventListener('click', this._closeBound);
+
+ if (this.options.showClearBtn) {
+ this._handleClearClickBound = this._handleClearClick.bind(this);
+ this.clearBtn.addEventListener('click', this._handleClearClickBound);
+ }
}
}, {
key: '_setupVariables',
value: function _setupVariables() {
var _this4 = this;
@@ -640,13 +654,15 @@
this.calendarEl = this.modalEl.querySelector('.pika-single');
this.yearTextEl = this.modalEl.querySelector('.year-text');
this.dateTextEl = this.modalEl.querySelector('.date-text');
- this.clearBtn = this.modalEl.querySelector('.datepicker-clear');
- this.todayBtn = this.modalEl.querySelector('.datepicker-today');
+ if (this.options.showClearBtn) {
+ this.clearBtn = this.modalEl.querySelector('.datepicker-clear');
+ }
this.doneBtn = this.modalEl.querySelector('.datepicker-done');
+ this.cancelBtn = this.modalEl.querySelector('.datepicker-cancel');
this.formats = {
d: function () {
return _this4.date.getDate();
@@ -736,17 +752,10 @@
// } else {
// this._c = true;
// }
}
}, {
- key: '_handleTodayClick',
- value: function _handleTodayClick() {
- this.date = new Date();
- this.setInputValue();
- this.close();
- }
- }, {
key: '_handleClearClick',
value: function _handleClearClick() {
this.date = null;
this.setInputValue();
this.close();
@@ -931,10 +940,10 @@
}]);
return Datepicker;
}(Component);
- Datepicker._template = ['<div class= "modal datepicker-modal">', '<div class="modal-content datepicker-container">', '<div class="datepicker-date-display">', '<span class="year-text"></span>', '<span class="date-text"></span>', '</div>', '<div class="datepicker-calendar-container">', '<div class="pika-single"></div>', '<div class="datepicker-footer">', '<button class="btn-flat datepicker-clear waves-effect" type="button"></button>', '<div class="confirmation-btns">', '<button class="btn-flat datepicker-today waves-effect" type="button"></button>', '<button class="btn-flat datepicker-done waves-effect" type="button"></button>', '</div>', '</div>', '</div>', '</div>', '</div>'].join('');
+ Datepicker._template = ['<div class= "modal datepicker-modal">', '<div class="modal-content datepicker-container">', '<div class="datepicker-date-display">', '<span class="year-text"></span>', '<span class="date-text"></span>', '</div>', '<div class="datepicker-calendar-container">', '<div class="pika-single"></div>', '<div class="datepicker-footer">', '<button class="btn-flat datepicker-clear waves-effect" style="visibility: hidden;" type="button"></button>', '<div class="confirmation-btns">', '<button class="btn-flat datepicker-cancel waves-effect" type="button"></button>', '<button class="btn-flat datepicker-done waves-effect" type="button"></button>', '</div>', '</div>', '</div>', '</div>', '</div>'].join('');
M.Datepicker = Datepicker;
if (M.jQueryLoaded) {
M.initializeJqueryWrapper(Datepicker, 'datepicker', 'M_Datepicker');