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

Method position

src/js/tether.js:367–567  ·  view source on GitHub ↗
(flushChanges = true)

Source from the content-addressed store, hash-verified

365 }
366
367 position(flushChanges = true) {
368 // flushChanges commits the changes immediately, leave true unless you are positioning multiple
369 // tethers (in which case call Tether.Utils.flush yourself when you're done)
370
371 if (!this.enabled) {
372 return;
373 }
374
375 this.clearCache();
376
377 // Turn 'auto' attachments into the appropriate corner or edge
378 const targetAttachment = autoToFixedAttachment(
379 this.targetAttachment,
380 this.attachment
381 );
382
383 this.updateAttachClasses(this.attachment, targetAttachment);
384
385 const elementPos = this.cache('element-bounds', () => {
386 return getBounds(this.bodyElement, this.element);
387 });
388
389 let { width, height } = elementPos;
390
391 if (width === 0 && height === 0 && !isUndefined(this.lastSize)) {
392 // We cache the height and width to make it possible to position elements that are
393 // getting hidden.
394 ({ width, height } = this.lastSize);
395 } else {
396 this.lastSize = { width, height };
397 }
398
399 const targetPos = this.cache('target-bounds', () => {
400 return this.getTargetBounds();
401 });
402 const targetSize = targetPos;
403
404 // Get an actual px offset from the attachment
405 let offset = offsetToPx(attachmentToOffset(this.attachment), {
406 width,
407 height
408 });
409 let targetOffset = offsetToPx(
410 attachmentToOffset(targetAttachment),
411 targetSize
412 );
413
414 const manualOffset = offsetToPx(this.offset, { width, height });
415 const manualTargetOffset = offsetToPx(this.targetOffset, targetSize);
416
417 // Add the manually provided offset
418 offset = addOffset(offset, manualOffset);
419 targetOffset = addOffset(targetOffset, manualTargetOffset);
420
421 // It's now our goal to make (element position + offset) == (target position + target offset)
422 let left = targetPos.left + targetOffset.left - offset.left;
423 let top = targetPos.top + targetOffset.top - offset.top;
424

Callers 7

constructorMethod · 0.95
enableMethod · 0.95
positionFunction · 0.80
jquery.jsFile · 0.80
welcome.jsFile · 0.80
dolls.jsFile · 0.80
tickFunction · 0.80

Calls 14

clearCacheMethod · 0.95
updateAttachClassesMethod · 0.95
cacheMethod · 0.95
getTargetBoundsMethod · 0.95
moveMethod · 0.95
autoToFixedAttachmentFunction · 0.90
getBoundsFunction · 0.90
isUndefinedFunction · 0.90
offsetToPxFunction · 0.90
attachmentToOffsetFunction · 0.90
addOffsetFunction · 0.90
isObjectFunction · 0.90

Tested by

no test coverage detected