(flushChanges = true)
| 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 |
no test coverage detected