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

Function getBoundingRect

src/js/constraint.js:15–58  ·  view source on GitHub ↗

* Returns an array of bounds of the format [left, top, right, bottom] * @param tether * @param to * @return {*[]|HTMLElement|ActiveX.IXMLDOMElement}

(body, tether, to)

Source from the content-addressed store, hash-verified

13 * @return {*[]|HTMLElement|ActiveX.IXMLDOMElement}
14 */
15function getBoundingRect(body, tether, to) {
16 // arg to is required
17 if (!to) {
18 return null;
19 }
20 if (to === 'scrollParent') {
21 to = tether.scrollParents[0];
22 } else if (to === 'window') {
23 to = [pageXOffset, pageYOffset, innerWidth + pageXOffset, innerHeight + pageYOffset];
24 }
25
26 if (to === document) {
27 to = to.documentElement;
28 }
29
30 if (!isUndefined(to.nodeType)) {
31 const node = to;
32 const size = getBounds(body, to);
33 const pos = size;
34 const style = getComputedStyle(to);
35
36 to = [pos.left, pos.top, size.width + pos.left, size.height + pos.top];
37
38 // Account any parent Frames scroll offset
39 if (node.ownerDocument !== document) {
40 let win = node.ownerDocument.defaultView;
41 to[0] += win.pageXOffset;
42 to[1] += win.pageYOffset;
43 to[2] += win.pageXOffset;
44 to[3] += win.pageYOffset;
45 }
46
47 BOUNDS_FORMAT.forEach((side, i) => {
48 side = side[0].toUpperCase() + side.substr(1);
49 if (side === 'Top' || side === 'Left') {
50 to[i] += parseFloat(style[`border${side}Width`]);
51 } else {
52 to[i] -= parseFloat(style[`border${side}Width`]);
53 }
54 });
55 }
56
57 return to;
58}
59
60/**
61 * Add out of bounds classes to the list of classes we add to tether

Callers 2

constraint.spec.jsFile · 0.85
positionFunction · 0.85

Calls 2

isUndefinedFunction · 0.90
getBoundsFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…