Skip to content

Commit

Permalink
Fixed #675
Browse files Browse the repository at this point in the history
  • Loading branch information
Çağatay Çivici committed Aug 2, 2016
1 parent 2de65af commit 97392ed
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions components/dom/domhandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,30 @@ export class DomHandler {
}

public absolutePosition(element: any, target: any): void {
let elementOuterHeight = element.offsetParent ? element.offsetHeight : this.getHiddenElementOuterHeight(element);
let elementDimensions = element.offsetParent ? {width:element.offsetWidth, height: element.offsetHeight} : this.getHiddenElementDimensions(element)
let elementOuterHeight = elementDimensions.height;
let elementOuterWidth = elementDimensions.width;
let targetOuterHeight = target.offsetHeight;
let targetOuterWidth = target.offsetWidth;
let targetOffset = target.getBoundingClientRect();
let windowScrollTop = this.getWindowScrollTop();
let top;
let windowScrollLeft = this.getWindowScrollLeft();
let top,left;

if(targetOffset.top + targetOuterHeight + elementOuterHeight > window.innerHeight)
top = targetOffset.top + windowScrollTop - elementOuterHeight;
else
top = targetOuterHeight + targetOffset.top + windowScrollTop;

if(targetOffset.left + targetOuterWidth + elementOuterWidth > window.innerWidth)
left = targetOffset.left + windowScrollLeft + targetOuterWidth - elementOuterWidth;
else
left = targetOffset.left + windowScrollLeft;

element.style.top = top + 'px';
element.style.left = targetOffset.left + 'px';
element.style.left = left + 'px';
}

public getHiddenElementOuterHeight(element: any): number {
element.style.visibility = 'hidden';
element.style.display = 'block';
Expand Down Expand Up @@ -191,6 +200,11 @@ export class DomHandler {
let doc = document.documentElement;
return (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
}

public getWindowScrollLeft(): number {
let doc = document.documentElement;
return (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0);
}

public matches(element, selector: string): boolean {
var p = Element.prototype;
Expand Down

0 comments on commit 97392ed

Please sign in to comment.