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

Function _getOrigin

src/js/utils/bounds.js:185–216  ·  view source on GitHub ↗
(body)

Source from the content-addressed store, hash-verified

183}
184
185function _getOrigin(body) {
186 // getBoundingClientRect is unfortunately too accurate. It introduces a pixel or two of
187 // jitter as the user scrolls that messes with our ability to detect if two positions
188 // are equivilant or not. We place an element at the top left of the page that will
189 // get the same jitter, so we can cancel the two out.
190 let node = zeroElement;
191 if (!node || !body.contains(node)) {
192 node = document.createElement('div');
193 node.setAttribute('data-tether-id', uniqueId());
194 extend(node.style, {
195 top: 0,
196 left: 0,
197 position: 'absolute'
198 });
199
200 body.appendChild(node);
201
202 zeroElement = node;
203 }
204
205 const id = node.getAttribute('data-tether-id');
206 if (isUndefined(zeroPosCache[id])) {
207 zeroPosCache[id] = _getActualBoundingClientRect(node);
208
209 // Clear the cache when this position call is done
210 defer(() => {
211 delete zeroPosCache[id];
212 });
213 }
214
215 return zeroPosCache[id];
216}

Callers 1

getBoundsFunction · 0.85

Calls 4

extendFunction · 0.90
isUndefinedFunction · 0.90
deferFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…