Skip to content
This repository was archived by the owner on Jun 18, 2018. It is now read-only.

[In progress] Fix iframe #27

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
coverage
lib
dist
.idea
13 changes: 7 additions & 6 deletions src/HTML5Backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,26 @@ export default class HTML5Backend {
this.endDragNativeItem = this.endDragNativeItem.bind(this);
}

setup() {
if (typeof window === 'undefined') {
setup(target = window) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vadorequest I see this is closed, but I'm doing somewhere where this would be really useful. I'm just wondering how you would wire things up to pass in an alternative target?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some PRs open that include the ability to use a different window context. After we get done with basic maintenance things I will add this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@darthtrevino Oh, nice! Thanks for that. If I wanted to play around with that, how does one pass along a different context?

e.g. From:

export default DragDropContext(HTML5Backend)(IframeDragReceiver)

to ... ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When it finalizes, it will look something like:

render() {
  <DragDropContext backend={HTML5Backend} context={{window: iframeWindowInstance}}>
   // your app
  </DragDrapContext>
}

if (typeof target === 'undefined') {
return;
}

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') {
// 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 = window) {
if (typeof target === 'undefined') {
return;
}

this.constructor.isSetUp = false;
this.removeEventListeners(window);
this.removeEventListeners(target);
this.clearCurrentDragSourceNode();
}

Expand Down