Skip to content

Commit a1d3261

Browse files
committed
Remove dragCover
1 parent 4b4ae27 commit a1d3261

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

src/components/dragelement/index.js

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'use strict';
1111

1212
var mouseOffset = require('mouse-event-offset');
13+
var hasHover = require('has-hover');
1314

1415
var Plotly = require('../../plotly');
1516
var Lib = require('../../lib');
@@ -63,11 +64,16 @@ dragElement.init = function init(options) {
6364
startX,
6465
startY,
6566
newMouseDownTime,
66-
dragCover,
67+
cursor,
68+
root = document.documentElement,
6769
initialTarget;
6870

6971
if(!gd._mouseDownTime) gd._mouseDownTime = 0;
7072

73+
options.element.style.pointerEvents = 'all';
74+
options.element.onmousedown = onStart;
75+
options.element.ontouchstart = onStart;
76+
7177
function onStart(e) {
7278
// make dragging and dragged into properties of gd
7379
// so that others can look at and modify them
@@ -91,19 +97,16 @@ dragElement.init = function init(options) {
9197

9298
if(options.prepFn) options.prepFn(e, startX, startY);
9399

94-
dragCover = coverSlip();
95-
96-
97-
dragCover.onmousemove = onMove;
98-
dragCover.ontouchmove = onMove;
99-
dragCover.onmouseup = onDone;
100-
dragCover.onmouseout = onDone;
101-
dragCover.ontouchend = onDone;
100+
document.addEventListener('mousemove', onMove)
101+
document.addEventListener('mouseup', onDone)
102+
document.addEventListener('mouseout', onDone)
102103

103-
// var moveEvent = new TouchEvent('touchstart', e)
104-
// dragCover.dispatchEvent(moveEvent)
104+
document.addEventListener('touchmove', onMove)
105+
document.addEventListener('touchend', onDone)
105106

106-
dragCover.style.cursor = window.getComputedStyle(options.element).cursor;
107+
// disable cursor
108+
cursor = window.getComputedStyle(root).cursor
109+
root.style.cursor = window.getComputedStyle(options.element).cursor;
107110

108111
return Lib.pauseEvent(e);
109112
}
@@ -127,12 +130,17 @@ dragElement.init = function init(options) {
127130
}
128131

129132
function onDone(e) {
130-
dragCover.onmousemove = null;
131-
dragCover.ontouchmove = null;
132-
dragCover.onmouseup = null;
133-
dragCover.onmouseout = null;
134-
dragCover.ontouchend = null;
135-
Lib.removeElement(dragCover);
133+
document.removeEventListener('mousemove', onMove);
134+
document.removeEventListener('mouseup', onDone);
135+
document.removeEventListener('mouseout', onDone);
136+
document.removeEventListener('touchmove', onMove);
137+
document.removeEventListener('touchend', onDone);
138+
139+
// enable cursor
140+
if (cursor) {
141+
root.style.cursor = cursor
142+
cursor = null
143+
}
136144

137145
if(!gd._dragging) {
138146
gd._dragged = false;
@@ -175,10 +183,6 @@ dragElement.init = function init(options) {
175183

176184
return Lib.pauseEvent(e);
177185
}
178-
179-
options.element.onmousedown = onStart;
180-
options.element.ontouchstart = onStart;
181-
options.element.style.pointerEvents = 'all';
182186
};
183187

184188
function coverSlip() {

0 commit comments

Comments
 (0)