Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
allow a dropdown to be positioned inside the trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
Yvonne Yip committed Sep 4, 2014
1 parent 035f49d commit 8d9504f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions core-dropdown-overlay.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,33 @@
return;
}

if (this.target.offsetParent !== this.relatedTarget.offsetParent && this.target.offsetParent !== this.relatedTarget) {
console.warn('core-dropdown-overlay: dropdown\'s offsetParent must be the relatedTarget or the relatedTarget\'s offsetParent!');
}

// Don't use CSS to handle halign/valign here so _shouldPosition still works.

var inside = this.target.offsetParent === this.relatedTarget;
var ref = this.relatedTarget.getBoundingClientRect();

if (this._shouldPosition.left) {
var left;
var ml = -1 * ref.left + this.margin;
if (this.halign === 'right') {
left = Math.max(-1 * ref.left + this.relatedTarget.offsetLeft + this.margin, this.relatedTarget.offsetLeft + ref.width - this._naturalSize.width);
left = Math.max((inside ? 0 : this.relatedTarget.offsetLeft) + this.relatedTarget.offsetWidth - this._naturalSize.width, ml);
} else {
left = this.relatedTarget.offsetLeft;
left = inside ? 0 : this.relatedTarget.offsetLeft;
}
this.target.style.left = left + 'px';
}

if (this._shouldPosition.top) {
var top;
var mt = -1 * ref.top + this.margin;
if (this.valign === 'bottom') {
top = Math.max(-1 * ref.top + this.relatedTarget.offsetTop + this.margin, this.relatedTarget.offsetTop + ref.height - this._naturalSize.height);
top = Math.max((inside ? 0 : this.relatedTarget.offsetTop) + this.relatedTarget.offsetHeight - this._naturalSize.height, mt);
} else {
top = this.relatedTarget.offsetTop;
top = inside ? 0 : this.relatedTarget.offsetTop;
}
this.target.style.top = top + 'px';
}
Expand Down

0 comments on commit 8d9504f

Please sign in to comment.