10
10
'use strict' ;
11
11
12
12
var mouseOffset = require ( 'mouse-event-offset' ) ;
13
- var hasHover = require ( 'has-hover' ) ;
14
13
15
14
var Plotly = require ( '../../plotly' ) ;
16
15
var Lib = require ( '../../lib' ) ;
@@ -30,13 +29,6 @@ dragElement.unhoverRaw = unhover.raw;
30
29
/**
31
30
* Abstracts click & drag interactions
32
31
*
33
- * During the interaction, a "coverSlip" element - a transparent
34
- * div covering the whole page - is created, which has two key effects:
35
- * - Lets you drag beyond the boundaries of the plot itself without
36
- * dropping (but if you drag all the way out of the browser window the
37
- * interaction will end)
38
- * - Freezes the cursor: whatever mouse cursor the drag element had when the
39
- * interaction started gets copied to the coverSlip for use until mouseup
40
32
*
41
33
* @param {object } options with keys:
42
34
* element (required) the DOM element to drag
@@ -65,19 +57,14 @@ dragElement.init = function init(options) {
65
57
startY ,
66
58
newMouseDownTime ,
67
59
cursor ,
68
- dragCover ,
69
60
initialTarget ;
70
61
71
62
if ( ! gd . _mouseDownTime ) gd . _mouseDownTime = 0 ;
72
63
73
64
options . element . style . pointerEvents = 'all' ;
74
65
75
- if ( hasHover ) {
76
- options . element . onmousedown = onStart ;
77
- }
78
- else {
79
- options . element . ontouchstart = onStart ;
80
- }
66
+ options . element . onmousedown = onStart ;
67
+ options . element . ontouchstart = onStart ;
81
68
82
69
function onStart ( e ) {
83
70
// make dragging and dragged into properties of gd
@@ -102,24 +89,16 @@ dragElement.init = function init(options) {
102
89
103
90
if ( options . prepFn ) options . prepFn ( e , startX , startY ) ;
104
91
105
- if ( hasHover ) {
106
- dragCover = coverSlip ( ) ;
107
- dragCover . addEventListener ( 'mousemove' , onMove ) ;
108
- dragCover . addEventListener ( 'mouseup' , onDone ) ;
109
- dragCover . addEventListener ( 'mouseout' , onDone ) ;
110
-
111
- dragCover . style . cursor = window . getComputedStyle ( options . element ) . cursor ;
112
- }
113
92
114
93
// document acts as a dragcover for mobile, bc we can't create dragcover dynamically
115
- else {
116
- dragCover = document ;
117
- document . addEventListener ( 'touchmove' , onMove ) ;
118
- document . addEventListener ( 'touchend' , onDone ) ;
94
+ document . addEventListener ( 'mousemove' , onMove ) ;
95
+ document . addEventListener ( 'mouseup' , onDone ) ;
96
+ document . addEventListener ( 'mouseout' , onDone ) ;
97
+ document . addEventListener ( 'touchmove' , onMove ) ;
98
+ document . addEventListener ( 'touchend' , onDone ) ;
119
99
120
- cursor = window . getComputedStyle ( document . documentElement ) . cursor ;
121
- document . documentElement . style . cursor = window . getComputedStyle ( options . element ) . cursor ;
122
- }
100
+ cursor = window . getComputedStyle ( document . documentElement ) . cursor ;
101
+ document . documentElement . style . cursor = window . getComputedStyle ( options . element ) . cursor ;
123
102
124
103
125
104
return Lib . pauseEvent ( e ) ;
@@ -144,25 +123,17 @@ dragElement.init = function init(options) {
144
123
}
145
124
146
125
function onDone ( e ) {
147
- if ( hasHover ) {
148
- dragCover . removeEventListener ( 'mousemove' , onMove ) ;
149
- dragCover . removeEventListener ( 'mouseup' , onDone ) ;
150
- dragCover . removeEventListener ( 'mouseout' , onDone ) ;
151
-
152
- Lib . removeElement ( dragCover ) ;
126
+ document . removeEventListener ( 'mousemove' , onMove ) ;
127
+ document . removeEventListener ( 'mouseup' , onDone ) ;
128
+ document . removeEventListener ( 'mouseout' , onDone ) ;
129
+ document . removeEventListener ( 'touchmove' , onMove ) ;
130
+ document . removeEventListener ( 'touchend' , onDone ) ;
131
+
132
+ if ( cursor ) {
133
+ document . documentElement . style . cursor = cursor ;
134
+ cursor = null ;
153
135
}
154
136
155
- else {
156
- dragCover . removeEventListener ( 'touchmove' , onMove ) ;
157
- dragCover . removeEventListener ( 'touchend' , onDone ) ;
158
-
159
- if ( cursor ) {
160
- dragCover . documentElement . style . cursor = cursor ;
161
- cursor = null ;
162
- }
163
- }
164
-
165
-
166
137
if ( ! gd . _dragging ) {
167
138
gd . _dragged = false ;
168
139
return ;
0 commit comments