FIX: pikaday wasn't working when using the mouse with a touch-enabled monitor
This commit is contained in:
parent
07ead44187
commit
e37ecb9d2f
|
@ -1,30 +1,30 @@
|
|||
/* global Pikaday:true */
|
||||
import loadScript from "discourse/lib/load-script";
|
||||
import { on } from "ember-addons/ember-computed-decorators";
|
||||
|
||||
export default Em.Component.extend({
|
||||
tagName: "input",
|
||||
classNames: ["date-picker"],
|
||||
_picker: null,
|
||||
|
||||
_loadDatePicker: function() {
|
||||
const self = this,
|
||||
input = this.$()[0];
|
||||
@on("didInsertElement")
|
||||
_loadDatePicker() {
|
||||
const input = this.$()[0];
|
||||
|
||||
loadScript("/javascripts/pikaday.js").then(function() {
|
||||
self._picker = new Pikaday({
|
||||
loadScript("/javascripts/pikaday.js").then(() => {
|
||||
this._picker = new Pikaday({
|
||||
field: input,
|
||||
format: "YYYY-MM-DD",
|
||||
defaultDate: moment().add(1, "day").toDate(),
|
||||
minDate: new Date(),
|
||||
onSelect: function(date) {
|
||||
self.set("value", moment(date).format("YYYY-MM-DD"));
|
||||
},
|
||||
onSelect: date => this.set("value", moment(date).format("YYYY-MM-DD")),
|
||||
});
|
||||
});
|
||||
}.on("didInsertElement"),
|
||||
},
|
||||
|
||||
_destroy: function() {
|
||||
@on("willDestroyElement")
|
||||
_destroy() {
|
||||
this._picker = null;
|
||||
}.on("willDestroyElement"),
|
||||
},
|
||||
|
||||
});
|
||||
|
|
|
@ -428,7 +428,6 @@
|
|||
}
|
||||
}, 100);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (hasClass(target, 'pika-prev')) {
|
||||
self.prevMonth();
|
||||
|
@ -438,6 +437,7 @@
|
|||
}
|
||||
}
|
||||
if (!hasClass(target, 'pika-select')) {
|
||||
// if this is touch event prevent mouse events emulation
|
||||
if (e.preventDefault) {
|
||||
e.preventDefault();
|
||||
} else {
|
||||
|
@ -543,7 +543,8 @@
|
|||
self.el = document.createElement('div');
|
||||
self.el.className = 'pika-single' + (opts.isRTL ? ' is-rtl' : '') + (opts.theme ? ' ' + opts.theme : '');
|
||||
|
||||
addEvent(self.el, 'ontouchend' in document ? 'touchend' : 'mousedown', self._onMouseDown, true);
|
||||
addEvent(self.el, 'mousedown', self._onMouseDown, true);
|
||||
addEvent(self.el, 'touchend', self._onMouseDown, true);
|
||||
addEvent(self.el, 'change', self._onChange);
|
||||
|
||||
if (opts.field) {
|
||||
|
@ -1058,6 +1059,7 @@
|
|||
{
|
||||
this.hide();
|
||||
removeEvent(this.el, 'mousedown', this._onMouseDown, true);
|
||||
removeEvent(this.el, 'touchend', this._onMouseDown, true);
|
||||
removeEvent(this.el, 'change', this._onChange);
|
||||
if (this._o.field) {
|
||||
removeEvent(this._o.field, 'change', this._onInputChange);
|
||||
|
|
Loading…
Reference in New Issue