summaryrefslogtreecommitdiff
path: root/templates/assets/tether/src/js/shift.js
blob: ecc872d27b5cc08c2df33cea8a010ab34b192604 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* globals TetherBase */

TetherBase.modules.push({
  position({top, left}) {
    if (!this.options.shift) {
      return;
    }

    let shift = this.options.shift;
    if (typeof this.options.shift === 'function') {
      shift = this.options.shift.call(this, {top, left});
    }

    let shiftTop, shiftLeft;
    if (typeof shift === 'string') {
      shift = shift.split(' ');
      shift[1] = shift[1] || shift[0];

      ([shiftTop, shiftLeft] = shift);

      shiftTop = parseFloat(shiftTop, 10);
      shiftLeft = parseFloat(shiftLeft, 10);
    } else {
      ([shiftTop, shiftLeft] = [shift.top, shift.left]);
    }

    top += shiftTop;
    left += shiftLeft;

    return {top, left};
  }
});