Skip to content

Commit

Permalink
Ugly fix for our specific use.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadorequest committed Apr 12, 2016
1 parent 69e872a commit 8b3d6a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@ node_modules
coverage
lib
dist
.idea
17 changes: 9 additions & 8 deletions src/HTML5Backend.js
Expand Up @@ -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.

Copy link
@phloe

phloe Apr 12, 2016

Careful: target would actually never be type 'undefined' as it will get set default to document.querySelector("iframe").contentWindow.

This comment has been minimized.

Copy link
@Vadorequest

Vadorequest Apr 12, 2016

Author

It was to check if there was an iframe or not actually. But it would fail anyway if document.querySelector("iframe") returns null. #uglyFix =D

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();
}

Expand Down

0 comments on commit 8b3d6a4

Please sign in to comment.