10
10
'use strict' ;
11
11
12
12
var mouseOffset = require ( 'mouse-event-offset' ) ;
13
+ var hasHover = require ( 'has-hover' ) ;
13
14
14
15
var Plotly = require ( '../../plotly' ) ;
15
16
var Lib = require ( '../../lib' ) ;
@@ -63,11 +64,16 @@ dragElement.init = function init(options) {
63
64
startX ,
64
65
startY ,
65
66
newMouseDownTime ,
66
- dragCover ,
67
+ cursor ,
68
+ root = document . documentElement ,
67
69
initialTarget ;
68
70
69
71
if ( ! gd . _mouseDownTime ) gd . _mouseDownTime = 0 ;
70
72
73
+ options . element . style . pointerEvents = 'all' ;
74
+ options . element . onmousedown = onStart ;
75
+ options . element . ontouchstart = onStart ;
76
+
71
77
function onStart ( e ) {
72
78
// make dragging and dragged into properties of gd
73
79
// so that others can look at and modify them
@@ -91,19 +97,16 @@ dragElement.init = function init(options) {
91
97
92
98
if ( options . prepFn ) options . prepFn ( e , startX , startY ) ;
93
99
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 )
102
103
103
- // var moveEvent = new TouchEvent('touchstart ', e )
104
- // dragCover.dispatchEvent(moveEvent )
104
+ document . addEventListener ( 'touchmove ', onMove )
105
+ document . addEventListener ( 'touchend' , onDone )
105
106
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 ;
107
110
108
111
return Lib . pauseEvent ( e ) ;
109
112
}
@@ -127,12 +130,17 @@ dragElement.init = function init(options) {
127
130
}
128
131
129
132
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
+ }
136
144
137
145
if ( ! gd . _dragging ) {
138
146
gd . _dragged = false ;
@@ -175,10 +183,6 @@ dragElement.init = function init(options) {
175
183
176
184
return Lib . pauseEvent ( e ) ;
177
185
}
178
-
179
- options . element . onmousedown = onStart ;
180
- options . element . ontouchstart = onStart ;
181
- options . element . style . pointerEvents = 'all' ;
182
186
} ;
183
187
184
188
function coverSlip ( ) {
0 commit comments