@@ -7,17 +7,16 @@ import 'package:angular/angular.dart';
77@NgDirective (
88 selector: '[tooltip]' )
99class Tooltip {
10- dom.Element element;
10+ final dom.Element element;
1111
1212 @NgOneWay ('tooltip' )
1313 TooltipModel displayModel;
1414
1515 dom.Element tooltipElem;
1616
1717 Tooltip (this .element) {
18- element
19- ..onMouseEnter.listen ((_) => _createTemplate ())
20- ..onMouseLeave.listen ((_) => _destroyTemplate ());
18+ element..onMouseEnter.listen ((_) => _createTemplate ())
19+ ..onMouseLeave.listen ((_) => _destroyTemplate ());
2120 }
2221
2322 void _createTemplate () {
@@ -47,19 +46,13 @@ class Tooltip {
4746 ..borderRadius = "5px"
4847 ..width = "${displayModel .imgWidth .toString ()}px" ;
4948
50- // find the coordinates of the parent DOM element
51- Rectangle bounds = element.getBoundingClientRect ();
52- int left = (bounds.left + dom.window.pageXOffset).toInt ();
53- int top = (bounds.top + dom.window.pageYOffset).toInt ();
54- int width = bounds.width.toInt ();
55- int height = bounds.height.toInt ();
56-
5749 // position the tooltip.
58- // Figure out where the containing element sits in the window.
50+ var elTopRight = element.offset.topRight;
51+
5952 tooltipElem.style
6053 ..position = "absolute"
61- ..top = "${top - height }px"
62- ..left = "${left + width + 10 }px" ;
54+ ..top = "${elTopRight . y }px"
55+ ..left = "${elTopRight . x + 10 }px" ;
6356
6457 // Add the tooltip to the document body. We add it here because
6558 // we need to position it absolutely, without reference to its
0 commit comments