@@ -65,14 +65,19 @@ dragElement.init = function init(options) {
65
65
startY ,
66
66
newMouseDownTime ,
67
67
cursor ,
68
- root = document . documentElement ,
68
+ dragCover ,
69
69
initialTarget ;
70
70
71
71
if ( ! gd . _mouseDownTime ) gd . _mouseDownTime = 0 ;
72
72
73
73
options . element . style . pointerEvents = 'all' ;
74
- options . element . onmousedown = onStart ;
75
- options . element . ontouchstart = onStart ;
74
+
75
+ if ( hasHover ) {
76
+ options . element . onmousedown = onStart ;
77
+ }
78
+ else {
79
+ options . element . ontouchstart = onStart ;
80
+ }
76
81
77
82
function onStart ( e ) {
78
83
// make dragging and dragged into properties of gd
@@ -97,16 +102,25 @@ dragElement.init = function init(options) {
97
102
98
103
if ( options . prepFn ) options . prepFn ( e , startX , startY ) ;
99
104
100
- document . addEventListener ( 'mousemove' , onMove )
101
- document . addEventListener ( 'mouseup' , onDone )
102
- document . addEventListener ( 'mouseout' , onDone )
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
+
114
+ // 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 ) ;
103
119
104
- document . addEventListener ( 'touchmove' , onMove )
105
- document . addEventListener ( 'touchend' , onDone )
120
+ cursor = window . getComputedStyle ( document . documentElement ) . cursor ;
121
+ document . documentElement . style . cursor = window . getComputedStyle ( options . element ) . cursor ;
122
+ }
106
123
107
- // disable cursor
108
- cursor = window . getComputedStyle ( root ) . cursor
109
- root . style . cursor = window . getComputedStyle ( options . element ) . cursor ;
110
124
111
125
return Lib . pauseEvent ( e ) ;
112
126
}
@@ -130,18 +144,25 @@ dragElement.init = function init(options) {
130
144
}
131
145
132
146
function onDone ( e ) {
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
147
+ if ( hasHover ) {
148
+ document . removeEventListener ( 'mousemove' , onMove ) ;
149
+ document . removeEventListener ( 'mouseup' , onDone ) ;
150
+ document . removeEventListener ( 'mouseout' , onDone ) ;
151
+
152
+ Lib . removeElement ( dragCover ) ;
143
153
}
144
154
155
+ else {
156
+ document . removeEventListener ( 'touchmove' , onMove ) ;
157
+ document . removeEventListener ( 'touchend' , onDone ) ;
158
+
159
+ if ( cursor ) {
160
+ document . documentElement . style . cursor = cursor ;
161
+ cursor = null ;
162
+ }
163
+ }
164
+
165
+
145
166
if ( ! gd . _dragging ) {
146
167
gd . _dragged = false ;
147
168
return ;
0 commit comments