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

Function position

src/js/constraint.js:299–466  ·  view source on GitHub ↗
({ top, left, targetAttachment })

Source from the content-addressed store, hash-verified

297
298export default {
299 position({ top, left, targetAttachment }) {
300 if (!this.options.constraints) {
301 return true;
302 }
303
304 let { height, width } = this.cache('element-bounds', () => {
305 return getBounds(this.bodyElement, this.element);
306 });
307
308 if (width === 0 && height === 0 && !isUndefined(this.lastSize)) {
309 // Handle the item getting hidden as a result of our positioning without glitching
310 // the classes in and out
311 ({ width, height } = this.lastSize);
312 }
313
314 const targetSize = this.cache('target-bounds', () => {
315 return this.getTargetBounds();
316 });
317
318 const { height: targetHeight, width: targetWidth } = targetSize;
319 const { classes, classPrefix } = this.options;
320
321 const allClasses = _getAllClasses(classes, classPrefix, this.options.constraints);
322 const addClasses = [];
323
324 const tAttachment = extend({}, targetAttachment);
325 const eAttachment = extend({}, this.attachment);
326
327 this.options.constraints.forEach((constraint) => {
328 let { to, attachment, pin } = constraint;
329
330 if (isUndefined(attachment)) {
331 attachment = '';
332 }
333
334 let changeAttachX, changeAttachY;
335 if (attachment.indexOf(' ') >= 0) {
336 [changeAttachY, changeAttachX] = attachment.split(' ');
337 } else {
338 changeAttachX = changeAttachY = attachment;
339 }
340
341 const bounds = getBoundingRect(this.bodyElement, this, to);
342
343 if (changeAttachY === 'target' || changeAttachY === 'both') {
344 if (top < bounds[1] && tAttachment.top === 'top') {
345 top += targetHeight;
346 tAttachment.top = 'bottom';
347 }
348
349 if (top + height > bounds[3] && tAttachment.top === 'bottom') {
350 top -= targetHeight;
351 tAttachment.top = 'top';
352 }
353 }
354
355 if (changeAttachY === 'together') {
356 top = _flipYTogether(tAttachment, eAttachment, bounds, height, targetHeight, top);

Callers

nothing calls this directly

Calls 15

getBoundsFunction · 0.90
isUndefinedFunction · 0.90
extendFunction · 0.90
isStringFunction · 0.90
getClassFunction · 0.90
deferFunction · 0.90
updateClassesFunction · 0.90
_getAllClassesFunction · 0.85
getBoundingRectFunction · 0.85
_flipYTogetherFunction · 0.85
_flipXTogetherFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…