From 789bce13ce2c850dbe2e4b5844f78ea224963dd1 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Sun, 2 Jun 2019 19:11:08 +0200 Subject: [PATCH] Add drag container in Dragger --- src/utils/Dragger.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/utils/Dragger.js b/src/utils/Dragger.js index 95e441faa..00a6a873b 100644 --- a/src/utils/Dragger.js +++ b/src/utils/Dragger.js @@ -8,6 +8,10 @@ export default class Dragger { */ constructor(opts = {}) { this.opts = { + /** + * Element on which the drag will be executed. By default, the document will be used + */ + container: null, /** * Callback on start * onStart(ev, dragger) { @@ -76,9 +80,10 @@ export default class Dragger { toggleDrag(enable) { const docs = this.getDocumentEl(); + const container = this.getContainerEl(); const method = enable ? 'on' : 'off'; const methods = { on, off }; - methods[method](docs, 'mousemove dragover', this.drag); + methods[method](container, 'mousemove dragover', this.drag); methods[method](docs, 'mouseup dragend touchend', this.stop); methods[method](docs, 'keydown', this.cancel); } @@ -272,6 +277,11 @@ export default class Dragger { } } + getContainerEl() { + const { container } = this.opts; + return container ? [container] : this.getDocumentEl(); + } + /** * Returns documents */