revert body cell event to click, change input event to keydown

This commit is contained in:
t1m0n 2016-04-19 11:41:05 +03:00
parent 0f87ce2d58
commit 82ca3b75d2
5 changed files with 34 additions and 22 deletions

26
dist/js/datepicker.js vendored
View File

@ -191,7 +191,7 @@
this.$el.on(this.opts.showEvent + '.adp', this._onShowEvent.bind(this)); this.$el.on(this.opts.showEvent + '.adp', this._onShowEvent.bind(this));
this.$el.on('mouseup.adp', this._onMouseUpEl.bind(this)); this.$el.on('mouseup.adp', this._onMouseUpEl.bind(this));
this.$el.on('blur.adp', this._onBlur.bind(this)); this.$el.on('blur.adp', this._onBlur.bind(this));
this.$el.on('input.adp', this._onInput.bind(this)); this.$el.on('keyup.adp', this._onKeyUpGeneral.bind(this));
$(window).on('resize.adp', this._onResize.bind(this)); $(window).on('resize.adp', this._onResize.bind(this));
$('body').on('mouseup.adp', this._onMouseUpBody.bind(this)); $('body').on('mouseup.adp', this._onMouseUpBody.bind(this));
}, },
@ -501,7 +501,7 @@
_this._triggerOnChange(); _this._triggerOnChange();
} }
if (opts.autoClose) { if (opts.autoClose && !this.timepickerIsActive) {
if (!opts.multipleDates && !opts.range) { if (!opts.multipleDates && !opts.range) {
_this.hide(); _this.hide();
} else if (opts.range && _this.selectedDates.length == 2) { } else if (opts.range && _this.selectedDates.length == 2) {
@ -1028,7 +1028,8 @@
} }
}, },
_onShowEvent: function () { _onShowEvent: function (e) {
console.log(e.type);
if (!this.visible) { if (!this.visible) {
this.show(); this.show();
} }
@ -1050,7 +1051,7 @@
if (!e.originalEvent.timepickerFocus) this.$el.focus(); if (!e.originalEvent.timepickerFocus) this.$el.focus();
}, },
_onInput: function () { _onKeyUpGeneral: function (e) {
var val = this.$el.val(); var val = this.$el.val();
if (!val) { if (!val) {
@ -1074,6 +1075,7 @@
_onMouseUpEl: function (e) { _onMouseUpEl: function (e) {
e.originalEvent.inFocus = true; e.originalEvent.inFocus = true;
setTimeout(this._onKeyUpGeneral.bind(this),4);
}, },
_onKeyDown: function (e) { _onKeyDown: function (e) {
@ -1426,10 +1428,7 @@
}, },
_bindEvents: function () { _bindEvents: function () {
// Use 'mouseup' and 'click' events instead of 'click' because of IE 10-11 bug, which triggers 'input' event this.$el.on('click', '.datepicker--cell', $.proxy(this._onClickCell, this));
// when placeholder value is changed (e.g. when user just focus input). It causes calling clear() method,
// which clears input value and prevents from selecting cell. (issue #36)
this.$el.on('click mouseup', '.datepicker--cell', $.proxy(this._onClickCell, this));
}, },
_buildBaseHtml: function () { _buildBaseHtml: function () {
@ -1884,7 +1883,8 @@
this.d.$el.on('selectDate', this._onSelectDate.bind(this)); this.d.$el.on('selectDate', this._onSelectDate.bind(this));
this.$ranges.on(input, this._onChangeRange.bind(this)); this.$ranges.on(input, this._onChangeRange.bind(this));
this.$ranges.on('mouseenter', this._onMouseEnterRange.bind(this)); this.$ranges.on('mouseup', this._onMouseUpRange.bind(this));
this.$ranges.on('mouseenter focus ', this._onMouseEnterRange.bind(this));
this.$ranges.on('mouseout blur', this._onMouseOutRange.bind(this)); this.$ranges.on('mouseout blur', this._onMouseOutRange.bind(this));
}, },
@ -2078,6 +2078,8 @@
var $target = $(e.target), var $target = $(e.target),
name = $target.attr('name'); name = $target.attr('name');
this.d.timepickerIsActive = true;
this[name] = $target.val(); this[name] = $target.val();
this._updateCurrentTime(); this._updateCurrentTime();
this.d._trigger('timeChange', [this.hours, this.minutes]) this.d._trigger('timeChange', [this.hours, this.minutes])
@ -2097,7 +2099,11 @@
var name = $(e.target).attr('name'); var name = $(e.target).attr('name');
if (this.d.inFocus) return; // Prevent removing focus when mouse out of range slider if (this.d.inFocus) return; // Prevent removing focus when mouse out of range slider
$('.datepicker--time-current-' + name, this.$timepicker).removeClass('-focus-'); $('.datepicker--time-current-' + name, this.$timepicker).removeClass('-focus-');
},
_onMouseUpRange: function (e) {
this.d.timepickerIsActive = false;
} }
}; };
})() })();
})(window, jQuery); })(window, jQuery);

File diff suppressed because one or more lines are too long

View File

@ -34,10 +34,7 @@
}, },
_bindEvents: function () { _bindEvents: function () {
// Use 'mouseup' and 'click' events instead of 'click' because of IE 10-11 bug, which triggers 'input' event this.$el.on('click', '.datepicker--cell', $.proxy(this._onClickCell, this));
// when placeholder value is changed (e.g. when user just focus input). It causes calling clear() method,
// which clears input value and prevents from selecting cell. (issue #36)
this.$el.on('click mouseup', '.datepicker--cell', $.proxy(this._onClickCell, this));
}, },
_buildBaseHtml: function () { _buildBaseHtml: function () {

View File

@ -191,7 +191,7 @@
this.$el.on(this.opts.showEvent + '.adp', this._onShowEvent.bind(this)); this.$el.on(this.opts.showEvent + '.adp', this._onShowEvent.bind(this));
this.$el.on('mouseup.adp', this._onMouseUpEl.bind(this)); this.$el.on('mouseup.adp', this._onMouseUpEl.bind(this));
this.$el.on('blur.adp', this._onBlur.bind(this)); this.$el.on('blur.adp', this._onBlur.bind(this));
this.$el.on('input.adp', this._onInput.bind(this)); this.$el.on('keyup.adp', this._onKeyUpGeneral.bind(this));
$(window).on('resize.adp', this._onResize.bind(this)); $(window).on('resize.adp', this._onResize.bind(this));
$('body').on('mouseup.adp', this._onMouseUpBody.bind(this)); $('body').on('mouseup.adp', this._onMouseUpBody.bind(this));
}, },
@ -501,7 +501,7 @@
_this._triggerOnChange(); _this._triggerOnChange();
} }
if (opts.autoClose) { if (opts.autoClose && !this.timepickerIsActive) {
if (!opts.multipleDates && !opts.range) { if (!opts.multipleDates && !opts.range) {
_this.hide(); _this.hide();
} else if (opts.range && _this.selectedDates.length == 2) { } else if (opts.range && _this.selectedDates.length == 2) {
@ -1028,7 +1028,8 @@
} }
}, },
_onShowEvent: function () { _onShowEvent: function (e) {
console.log(e.type);
if (!this.visible) { if (!this.visible) {
this.show(); this.show();
} }
@ -1050,7 +1051,7 @@
if (!e.originalEvent.timepickerFocus) this.$el.focus(); if (!e.originalEvent.timepickerFocus) this.$el.focus();
}, },
_onInput: function () { _onKeyUpGeneral: function (e) {
var val = this.$el.val(); var val = this.$el.val();
if (!val) { if (!val) {
@ -1074,6 +1075,7 @@
_onMouseUpEl: function (e) { _onMouseUpEl: function (e) {
e.originalEvent.inFocus = true; e.originalEvent.inFocus = true;
setTimeout(this._onKeyUpGeneral.bind(this),4);
}, },
_onKeyDown: function (e) { _onKeyDown: function (e) {

View File

@ -36,7 +36,8 @@
this.d.$el.on('selectDate', this._onSelectDate.bind(this)); this.d.$el.on('selectDate', this._onSelectDate.bind(this));
this.$ranges.on(input, this._onChangeRange.bind(this)); this.$ranges.on(input, this._onChangeRange.bind(this));
this.$ranges.on('mouseenter', this._onMouseEnterRange.bind(this)); this.$ranges.on('mouseup', this._onMouseUpRange.bind(this));
this.$ranges.on('mouseenter focus ', this._onMouseEnterRange.bind(this));
this.$ranges.on('mouseout blur', this._onMouseOutRange.bind(this)); this.$ranges.on('mouseout blur', this._onMouseOutRange.bind(this));
}, },
@ -230,6 +231,8 @@
var $target = $(e.target), var $target = $(e.target),
name = $target.attr('name'); name = $target.attr('name');
this.d.timepickerIsActive = true;
this[name] = $target.val(); this[name] = $target.val();
this._updateCurrentTime(); this._updateCurrentTime();
this.d._trigger('timeChange', [this.hours, this.minutes]) this.d._trigger('timeChange', [this.hours, this.minutes])
@ -249,6 +252,10 @@
var name = $(e.target).attr('name'); var name = $(e.target).attr('name');
if (this.d.inFocus) return; // Prevent removing focus when mouse out of range slider if (this.d.inFocus) return; // Prevent removing focus when mouse out of range slider
$('.datepicker--time-current-' + name, this.$timepicker).removeClass('-focus-'); $('.datepicker--time-current-' + name, this.$timepicker).removeClass('-focus-');
},
_onMouseUpRange: function (e) {
this.d.timepickerIsActive = false;
} }
}; };
})() })();