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