MCPcopy Index your code
hub / github.com/shipshapecode/tether / position

Function position

src/js/abutment.js:6–58  ·  view source on GitHub ↗
({ top, left })

Source from the content-addressed store, hash-verified

4
5export default {
6 position({ top, left }) {
7 const { height, width } = this.cache('element-bounds', () => {
8 return getBounds(this.element);
9 });
10
11 const targetPos = this.getTargetBounds();
12
13 const bottom = top + height;
14 const right = left + width;
15
16 const abutted = [];
17 if (top <= targetPos.bottom && bottom >= targetPos.top) {
18 ['left', 'right'].forEach((side) => {
19 const targetPosSide = targetPos[side];
20 if (targetPosSide === left || targetPosSide === right) {
21 abutted.push(side);
22 }
23 });
24 }
25
26 if (left <= targetPos.right && right >= targetPos.left) {
27 ['top', 'bottom'].forEach((side) => {
28 const targetPosSide = targetPos[side];
29 if (targetPosSide === top || targetPosSide === bottom) {
30 abutted.push(side);
31 }
32 });
33 }
34
35 const sides = ['left', 'top', 'right', 'bottom'];
36 const { classes, classPrefix } = this.options;
37 this.all.push(getClass('abutted', classes, classPrefix));
38 sides.forEach((side) => {
39 this.all.push(`${getClass('abutted', classes, classPrefix)}-${side}`);
40 });
41
42 if (abutted.length) {
43 this.add.push(getClass('abutted', classes, classPrefix));
44 }
45
46 abutted.forEach((side) => {
47 this.add.push(`${getClass('abutted', classes, classPrefix)}-${side}`);
48 });
49
50 defer(() => {
51 if (!(this.options.addTargetClasses === false)) {
52 updateClasses(this.target, this.add, this.all);
53 }
54 updateClasses(this.element, this.add, this.all);
55 });
56
57 return true;
58 }
59};

Callers

nothing calls this directly

Calls 6

getBoundsFunction · 0.90
getClassFunction · 0.90
deferFunction · 0.90
updateClassesFunction · 0.90
cacheMethod · 0.80
getTargetBoundsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…