35 lines
972 B
TypeScript
Raw Normal View History

2015-08-20 14:28:25 -07:00
import {Promise, PromiseWrapper} from 'angular2/src/core/facade/async';
import {DomAdapter} from 'angular2/src/core/dom/dom_adapter';
import {ElementRef} from 'angular2/src/core/compiler/element_ref';
export class Rectangle {
left;
right;
top;
bottom;
height;
width;
constructor(left, top, width, height) {
this.left = left;
this.right = left + width;
this.top = top;
this.bottom = top + height;
this.height = height;
this.width = width;
}
}
export class Ruler {
domAdapter: DomAdapter;
2015-05-20 09:48:15 -07:00
constructor(domAdapter: DomAdapter) { this.domAdapter = domAdapter; }
2015-05-20 09:48:15 -07:00
measure(el: ElementRef): Promise<Rectangle> {
var clntRect = <any>this.domAdapter.getBoundingClientRect(el.nativeElement);
2015-05-20 09:48:15 -07:00
// even if getBoundingClientRect is synchronous we use async API in preparation for further
// changes
return PromiseWrapper.resolve(
new Rectangle(clntRect.left, clntRect.top, clntRect.width, clntRect.height));
}
}