From 8b3d6a44b2cdbfe8d5bac025fc263715968d8b6c Mon Sep 17 00:00:00 2001 From: Vadorequest Date: Tue, 12 Apr 2016 13:20:20 +0200 Subject: [PATCH] Ugly fix for our specific use. --- .gitignore | 1 + src/HTML5Backend.js | 17 +++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 63a662b..7df7bc4 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules coverage lib dist +.idea diff --git a/src/HTML5Backend.js b/src/HTML5Backend.js index 7206bfe..b082cf5 100644 --- a/src/HTML5Backend.js +++ b/src/HTML5Backend.js @@ -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') { + 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(); }