@@ -11,6 +11,7 @@ export default class HTML5Backend {
1111 this . actions = manager . getActions ( ) ;
1212 this . monitor = manager . getMonitor ( ) ;
1313 this . registry = manager . getRegistry ( ) ;
14+ this . context = manager . getContext ( ) ;
1415
1516 this . sourcePreviewNodes = { } ;
1617 this . sourcePreviewNodeOptions = { } ;
@@ -34,25 +35,29 @@ export default class HTML5Backend {
3435 this . endDragNativeItem = this . endDragNativeItem . bind ( this ) ;
3536 }
3637
38+ get window ( ) {
39+ return ( this . context && this . context . window ) || window ;
40+ }
41+
3742 setup ( ) {
38- if ( typeof window === 'undefined' ) {
43+ if ( typeof this . window === 'undefined' ) {
3944 return ;
4045 }
4146
42- if ( this . constructor . isSetUp ) {
47+ if ( this . window . __isReactDndBackendSetUp ) { // eslint-disable-line no-underscore-dangle
4348 throw new Error ( 'Cannot have two HTML5 backends at the same time.' ) ;
4449 }
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 ) ;
4752 }
4853
4954 teardown ( ) {
50- if ( typeof window === 'undefined' ) {
55+ if ( typeof this . window === 'undefined' ) {
5156 return ;
5257 }
5358
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 ) ;
5661 this . clearCurrentDragSourceNode ( ) ;
5762 }
5863
@@ -180,7 +185,7 @@ export default class HTML5Backend {
180185 // On Firefox, if mousemove fires, the drag is over but browser failed to tell us.
181186 // This is not true for other browsers.
182187 if ( isFirefox ( ) ) {
183- window . addEventListener ( 'mousemove' , this . endDragNativeItem , true ) ;
188+ this . window . addEventListener ( 'mousemove' , this . endDragNativeItem , true ) ;
184189 }
185190 }
186191
@@ -190,7 +195,7 @@ export default class HTML5Backend {
190195 }
191196
192197 if ( isFirefox ( ) ) {
193- window . removeEventListener ( 'mousemove' , this . endDragNativeItem , true ) ;
198+ this . window . removeEventListener ( 'mousemove' , this . endDragNativeItem , true ) ;
194199 }
195200
196201 this . actions . endDrag ( ) ;
@@ -219,15 +224,15 @@ export default class HTML5Backend {
219224 // Receiving a mouse event in the middle of a dragging operation
220225 // means it has ended and the drag source node disappeared from DOM,
221226 // so the browser didn't dispatch the dragend event.
222- window . addEventListener ( 'mousemove' , this . endDragIfSourceWasRemovedFromDOM , true ) ;
227+ this . window . addEventListener ( 'mousemove' , this . endDragIfSourceWasRemovedFromDOM , true ) ;
223228 }
224229
225230 clearCurrentDragSourceNode ( ) {
226231 if ( this . currentDragSourceNode ) {
227232 this . currentDragSourceNode = null ;
228233 this . currentDragSourceNodeOffset = null ;
229234 this . currentDragSourceNodeOffsetChanged = false ;
230- window . removeEventListener ( 'mousemove' , this . endDragIfSourceWasRemovedFromDOM , true ) ;
235+ this . window . removeEventListener ( 'mousemove' , this . endDragIfSourceWasRemovedFromDOM , true ) ;
231236 return true ;
232237 }
233238
0 commit comments