@@ -11,6 +11,7 @@ export default class HTML5Backend {
11
11
this . actions = manager . getActions ( ) ;
12
12
this . monitor = manager . getMonitor ( ) ;
13
13
this . registry = manager . getRegistry ( ) ;
14
+ this . context = manager . getContext ( ) ;
14
15
15
16
this . sourcePreviewNodes = { } ;
16
17
this . sourcePreviewNodeOptions = { } ;
@@ -34,25 +35,29 @@ export default class HTML5Backend {
34
35
this . endDragNativeItem = this . endDragNativeItem . bind ( this ) ;
35
36
}
36
37
38
+ get window ( ) {
39
+ return ( this . context && this . context . window ) || window ;
40
+ }
41
+
37
42
setup ( ) {
38
- if ( typeof window === 'undefined' ) {
43
+ if ( typeof this . window === 'undefined' ) {
39
44
return ;
40
45
}
41
46
42
- if ( this . constructor . isSetUp ) {
47
+ if ( this . window . __isReactDndBackendSetUp ) { // eslint-disable-line no-underscore-dangle
43
48
throw new Error ( 'Cannot have two HTML5 backends at the same time.' ) ;
44
49
}
45
- this . constructor . isSetUp = true ;
46
- this . addEventListeners ( window ) ;
50
+ this . window . __isReactDndBackendSetUp = true ; // eslint-disable-line no-underscore-dangle
51
+ this . addEventListeners ( this . window ) ;
47
52
}
48
53
49
54
teardown ( ) {
50
- if ( typeof window === 'undefined' ) {
55
+ if ( typeof this . window === 'undefined' ) {
51
56
return ;
52
57
}
53
58
54
- this . constructor . isSetUp = false ;
55
- this . removeEventListeners ( window ) ;
59
+ this . window . __isReactDndBackendSetUp = false ; // eslint-disable-line no-underscore-dangle
60
+ this . removeEventListeners ( this . window ) ;
56
61
this . clearCurrentDragSourceNode ( ) ;
57
62
}
58
63
@@ -180,7 +185,7 @@ export default class HTML5Backend {
180
185
// On Firefox, if mousemove fires, the drag is over but browser failed to tell us.
181
186
// This is not true for other browsers.
182
187
if ( isFirefox ( ) ) {
183
- window . addEventListener ( 'mousemove' , this . endDragNativeItem , true ) ;
188
+ this . window . addEventListener ( 'mousemove' , this . endDragNativeItem , true ) ;
184
189
}
185
190
}
186
191
@@ -190,7 +195,7 @@ export default class HTML5Backend {
190
195
}
191
196
192
197
if ( isFirefox ( ) ) {
193
- window . removeEventListener ( 'mousemove' , this . endDragNativeItem , true ) ;
198
+ this . window . removeEventListener ( 'mousemove' , this . endDragNativeItem , true ) ;
194
199
}
195
200
196
201
this . actions . endDrag ( ) ;
@@ -219,15 +224,15 @@ export default class HTML5Backend {
219
224
// Receiving a mouse event in the middle of a dragging operation
220
225
// means it has ended and the drag source node disappeared from DOM,
221
226
// so the browser didn't dispatch the dragend event.
222
- window . addEventListener ( 'mousemove' , this . endDragIfSourceWasRemovedFromDOM , true ) ;
227
+ this . window . addEventListener ( 'mousemove' , this . endDragIfSourceWasRemovedFromDOM , true ) ;
223
228
}
224
229
225
230
clearCurrentDragSourceNode ( ) {
226
231
if ( this . currentDragSourceNode ) {
227
232
this . currentDragSourceNode = null ;
228
233
this . currentDragSourceNodeOffset = null ;
229
234
this . currentDragSourceNodeOffsetChanged = false ;
230
- window . removeEventListener ( 'mousemove' , this . endDragIfSourceWasRemovedFromDOM , true ) ;
235
+ this . window . removeEventListener ( 'mousemove' , this . endDragIfSourceWasRemovedFromDOM , true ) ;
231
236
return true ;
232
237
}
233
238
0 commit comments