({ top, left, targetAttachment })
| 297 | |
| 298 | export 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); |
nothing calls this directly
no test coverage detected
searching dependent graphs…