From c20bd23e14860b6ce840f206b2a419f679484cd6 Mon Sep 17 00:00:00 2001 From: Cagatay Civici Date: Wed, 17 Feb 2021 16:57:54 +0300 Subject: [PATCH] Fixed #980 - Touch support for ColorPicker --- src/components/colorpicker/ColorPicker.vue | 73 +++++++++++++++------- 1 file changed, 49 insertions(+), 24 deletions(-) diff --git a/src/components/colorpicker/ColorPicker.vue b/src/components/colorpicker/ColorPicker.vue index ec47af929..fc8f74ab1 100755 --- a/src/components/colorpicker/ColorPicker.vue +++ b/src/components/colorpicker/ColorPicker.vue @@ -5,12 +5,14 @@
-
+
-
+
@@ -84,8 +86,7 @@ export default { hueHandle: null, beforeUnmount() { this.unbindOutsideClickListener(); - this.unbindDocumentMouseMoveListener(); - this.unbindDocumentMouseUpListener(); + this.unbindDragListeners(); this.unbindResizeListener(); if (this.scrollHandler) { @@ -381,26 +382,64 @@ export default { return; } + this.bindDragListeners(); + this.onColorDragStart(event); + }, + onColorDragStart(event) { + if (this.disabled) { + return; + } + this.colorDragging = true; - this.bindDocumentMouseMoveListener(); - this.bindDocumentMouseUpListener(); this.pickColor(event); DomHandler.addClass(this.$el, 'p-colorpicker-dragging'); + event.preventDefault(); + }, + onDrag(event) { + if (this.colorDragging) { + this.pickColor(event); + event.preventDefault(); + } + + if (this.hueDragging) { + this.pickHue(event); + event.preventDefault(); + } + }, + onDragEnd() { + this.colorDragging = false; + this.hueDragging = false; + DomHandler.removeClass(this.$el, 'p-colorpicker-dragging'); + this.unbindDragListeners(); }, onHueMousedown(event) { if (this.disabled) { return; } + this.bindDragListeners(); + this.onHueDragStart(event); + }, + onHueDragStart(event) { + if (this.disabled) { + return; + } + this.hueDragging = true; - this.bindDocumentMouseMoveListener(); - this.bindDocumentMouseUpListener(); this.pickHue(event); DomHandler.addClass(this.$el, 'p-colorpicker-dragging'); }, isInputClicked(event) { return this.$refs.input && this.$refs.input.isSameNode(event.target); }, + bindDragListeners() { + this.bindDocumentMouseMoveListener(); + this.bindDocumentMouseUpListener(); + }, + unbindDragListeners() { + this.unbindDocumentMouseMoveListener(); + this.unbindDocumentMouseUpListener(); + }, bindOutsideClickListener() { if (!this.outsideClickListener) { this.outsideClickListener = (event) => { @@ -451,15 +490,7 @@ export default { }, bindDocumentMouseMoveListener() { if (!this.documentMouseMoveListener) { - this.documentMouseMoveListener = (event) => { - if (this.colorDragging) { - this.pickColor(event); - } - - if (this.hueDragging) { - this.pickHue(event); - } - }; + this.documentMouseMoveListener = this.onDrag.bind(this); document.addEventListener('mousemove', this.documentMouseMoveListener); } }, @@ -471,13 +502,7 @@ export default { }, bindDocumentMouseUpListener() { if (!this.documentMouseUpListener) { - this.documentMouseUpListener = () => { - this.colorDragging = false; - this.hueDragging = false; - DomHandler.removeClass(this.$el, 'p-colorpicker-dragging'); - this.unbindDocumentMouseMoveListener(); - this.unbindDocumentMouseUpListener(); - }; + this.documentMouseUpListener = this.onDragEnd.bind(this); document.addEventListener('mouseup', this.documentMouseUpListener); } },