diff --git a/src/HTML5Backend.js b/src/HTML5Backend.js
index 95fcd3d..d02cde5 100644
--- a/src/HTML5Backend.js
+++ b/src/HTML5Backend.js
@@ -11,6 +11,7 @@ export default class HTML5Backend {
this.actions = manager.getActions();
this.monitor = manager.getMonitor();
this.registry = manager.getRegistry();
+ this.context = manager.getContext();
this.sourcePreviewNodes = {};
this.sourcePreviewNodeOptions = {};
@@ -34,25 +35,29 @@ export default class HTML5Backend {
this.endDragNativeItem = this.endDragNativeItem.bind(this);
}
+ get window() {
+ return (this.context && this.context.window) || window;
+ }
+
setup() {
- if (typeof window === 'undefined') {
+ if (typeof this.window === 'undefined') {
return;
}
- if (this.constructor.isSetUp) {
+ if (this.window.__isReactDndBackendSetUp) { // eslint-disable-line no-underscore-dangle
throw new Error('Cannot have two HTML5 backends at the same time.');
}
- this.constructor.isSetUp = true;
- this.addEventListeners(window);
+ this.window.__isReactDndBackendSetUp = true; // eslint-disable-line no-underscore-dangle
+ this.addEventListeners(this.window);
}
teardown() {
- if (typeof window === 'undefined') {
+ if (typeof this.window === 'undefined') {
return;
}
- this.constructor.isSetUp = false;
- this.removeEventListeners(window);
+ this.window.__isReactDndBackendSetUp = false; // eslint-disable-line no-underscore-dangle
+ this.removeEventListeners(this.window);
this.clearCurrentDragSourceNode();
}
@@ -180,7 +185,7 @@ export default class HTML5Backend {
// On Firefox, if mousemove fires, the drag is over but browser failed to tell us.
// This is not true for other browsers.
if (isFirefox()) {
- window.addEventListener('mousemove', this.endDragNativeItem, true);
+ this.window.addEventListener('mousemove', this.endDragNativeItem, true);
}
}
@@ -190,7 +195,7 @@ export default class HTML5Backend {
}
if (isFirefox()) {
- window.removeEventListener('mousemove', this.endDragNativeItem, true);
+ this.window.removeEventListener('mousemove', this.endDragNativeItem, true);
}
this.actions.endDrag();
@@ -219,7 +224,7 @@ export default class HTML5Backend {
// Receiving a mouse event in the middle of a dragging operation
// means it has ended and the drag source node disappeared from DOM,
// so the browser didn't dispatch the dragend event.
- window.addEventListener('mousemove', this.endDragIfSourceWasRemovedFromDOM, true);
+ this.window.addEventListener('mousemove', this.endDragIfSourceWasRemovedFromDOM, true);
}
clearCurrentDragSourceNode() {
@@ -227,7 +232,7 @@ export default class HTML5Backend {
this.currentDragSourceNode = null;
this.currentDragSourceNodeOffset = null;
this.currentDragSourceNodeOffsetChanged = false;
- window.removeEventListener('mousemove', this.endDragIfSourceWasRemovedFromDOM, true);
+ this.window.removeEventListener('mousemove', this.endDragIfSourceWasRemovedFromDOM, true);
return true;
}