Browse Source

Clean dragger

pull/2090/head
Artur Arseniev 7 years ago
parent
commit
b8f87f6ca7
  1. 14
      src/utils/Dragger.js

14
src/utils/Dragger.js

@ -1,6 +1,8 @@
import { bindAll, isFunction, result, isUndefined } from 'underscore'; import { bindAll, isFunction, result, isUndefined } from 'underscore';
import { on, off, isEscKey, getPointerEvent } from 'utils/mixins'; import { on, off, isEscKey, getPointerEvent } from 'utils/mixins';
const resetPos = () => ({ x: 0, y: 0 });
export default class Dragger { export default class Dragger {
/** /**
* Init the dragger * Init the dragger
@ -63,7 +65,7 @@ export default class Dragger {
}; };
bindAll(this, 'drag', 'stop', 'keyHandle', 'handleScroll'); bindAll(this, 'drag', 'stop', 'keyHandle', 'handleScroll');
this.setOptions(opts); this.setOptions(opts);
this.delta = { x: 0, y: 0 }; this.delta = resetPos();
return this; return this;
} }
@ -114,10 +116,8 @@ export default class Dragger {
this.guidesTarget = result(opts, 'guidesTarget') || []; this.guidesTarget = result(opts, 'guidesTarget') || [];
isFunction(onStart) && onStart(ev, this); isFunction(onStart) && onStart(ev, this);
this.startPosition = this.getStartPosition(); this.startPosition = this.getStartPosition();
this.lastDiff = 0; this.lastScrollDiff = resetPos();
this.globDiff = 0; this.globScrollDiff = resetPos();
this.lastScrollDiff = { x: 0, y: 0 };
this.globScrollDiff = { x: 0, y: 0 };
this.drag(ev); this.drag(ev);
} }
@ -139,7 +139,7 @@ export default class Dragger {
x: currentPos.x - startPointer.x + glDiff.x, x: currentPos.x - startPointer.x + glDiff.x,
y: currentPos.y - startPointer.y + glDiff.y y: currentPos.y - startPointer.y + glDiff.y
}; };
this.lastScrollDiff = { x: 0, y: 0 }; this.lastScrollDiff = resetPos();
let { lockedAxis } = this; let { lockedAxis } = this;
// Lock one axis // Lock one axis
@ -351,7 +351,7 @@ export default class Dragger {
getStartPosition() { getStartPosition() {
const { el, opts } = this; const { el, opts } = this;
const getPos = opts.getPosition; const getPos = opts.getPosition;
let result = { x: 0, y: 0 }; let result = resetPos();
if (isFunction(getPos)) { if (isFunction(getPos)) {
result = getPos(); result = getPos();

Loading…
Cancel
Save