Browse Source

Add drag container in Dragger

pull/2062/head
Artur Arseniev 7 years ago
parent
commit
789bce13ce
  1. 12
      src/utils/Dragger.js

12
src/utils/Dragger.js

@ -8,6 +8,10 @@ export default class Dragger {
*/ */
constructor(opts = {}) { constructor(opts = {}) {
this.opts = { this.opts = {
/**
* Element on which the drag will be executed. By default, the document will be used
*/
container: null,
/** /**
* Callback on start * Callback on start
* onStart(ev, dragger) { * onStart(ev, dragger) {
@ -76,9 +80,10 @@ export default class Dragger {
toggleDrag(enable) { toggleDrag(enable) {
const docs = this.getDocumentEl(); const docs = this.getDocumentEl();
const container = this.getContainerEl();
const method = enable ? 'on' : 'off'; const method = enable ? 'on' : 'off';
const methods = { 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, 'mouseup dragend touchend', this.stop);
methods[method](docs, 'keydown', this.cancel); 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 * Returns documents
*/ */

Loading…
Cancel
Save