forked from react-dnd/react-dnd-html5-backend
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
69e872a
commit 8b3d6a4
Showing
2 changed files
with
10 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ node_modules | |
coverage | ||
lib | ||
dist | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,25 +34,26 @@ export default class HTML5Backend { | |
this.endDragNativeItem = this.endDragNativeItem.bind(this); | ||
} | ||
|
||
setup() { | ||
if (typeof window === 'undefined') { | ||
return; | ||
setup(target = document.querySelector("iframe").contentWindow) { | ||
if (typeof target === 'undefined') { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Vadorequest
Author
|
||
target = window; | ||
} | ||
|
||
if (this.constructor.isSetUp) { | ||
throw new Error('Cannot have two HTML5 backends at the same time.'); | ||
} | ||
this.constructor.isSetUp = true; | ||
this.addEventListeners(window); | ||
this.addEventListeners(target); | ||
} | ||
|
||
teardown() { | ||
if (typeof window === 'undefined') { | ||
return; | ||
// TODO - Maybe save the target and use the same target for both setup and teardown to ensure the events are correctly removed in case the the target isn't provided. | ||
teardown(target = document.querySelector("iframe").contentWindow) { | ||
if (typeof target === 'undefined') { | ||
target = window; | ||
} | ||
|
||
this.constructor.isSetUp = false; | ||
this.removeEventListeners(window); | ||
this.removeEventListeners(target); | ||
this.clearCurrentDragSourceNode(); | ||
} | ||
|
||
|
Careful: target would actually never be type
'undefined'
as it will get set default todocument.querySelector("iframe").contentWindow
.