@@ -7,76 +7,70 @@ import 'package:angular/angular.dart';
77@NgDirective (
88 selector: '[tooltip]' ,
99 map: const {
10- 'tooltip' : '=>displayModel'
10+ 'tooltip' : '=>displayModel'
1111 }
1212)
1313class Tooltip {
14- // not sure which one I will need.
15- // ng-click uses node.
16- // ng-show-hide uses element.
14+ // not sure which one I will need.
15+ // ng-click uses node.
16+ // ng-show-hide uses element.
1717 dom.Element element;
1818 dom.Node node;
1919 Scope scope;
2020 TooltipModel displayModel;
2121
2222 dom.Element tooltipElem;
2323
24- Tooltip (dom.Element this .element, dom.Node this .node,
25- Scope this .scope) {
26-
27- element.onMouseEnter.listen ((event) {
28- _createTemplate ();
29- });
30-
31- element.onMouseLeave.listen ((event) {
32- _destroyTemplate ();
33- });
24+ Tooltip (this .element, this .node, this .scope) {
25+ element
26+ ..onMouseEnter.listen ((_) => _createTemplate ())
27+ ..onMouseLeave.listen ((_) => _destroyTemplate ());
3428 }
3529
3630 _createTemplate () {
3731 assert (displayModel != null );
3832
3933 tooltipElem = new dom.DivElement ();
4034
41- dom.ImageElement imgElem = new dom.ImageElement ();
42- imgElem. width = displayModel.imgWidth;
43- imgElem .src = displayModel.imgUrl;
35+ dom.ImageElement imgElem = new dom.ImageElement ()
36+ .. width = displayModel.imgWidth
37+ . .src = displayModel.imgUrl;
4438 tooltipElem.append (imgElem);
4539
4640 if (displayModel.text != null ) {
47- dom.DivElement textSpan = new dom.DivElement ();
48- textSpan. appendText (displayModel.text);
49- textSpan. style.color = "white" ;
50- textSpan. style.fontSize = "smaller" ;
51- textSpan .style.paddingBottom = "5px" ;
41+ dom.DivElement textSpan = new dom.DivElement ()
42+ .. appendText (displayModel.text)
43+ .. style.color = "white"
44+ .. style.fontSize = "smaller"
45+ . .style.paddingBottom = "5px" ;
5246
5347 tooltipElem.append (textSpan);
5448 }
5549
56- tooltipElem.style.padding = "5px" ;
57- tooltipElem.style.paddingBottom = "0px" ;
58- tooltipElem.style.backgroundColor = "black" ;
59- tooltipElem.style.borderRadius = "5px" ;
60- tooltipElem.style.width = "${displayModel .imgWidth .toString ()}px" ;
50+ tooltipElem.style
51+ ..padding = "5px"
52+ ..paddingBottom = "0px"
53+ ..backgroundColor = "black"
54+ ..borderRadius = "5px"
55+ ..width = "${displayModel .imgWidth .toString ()}px" ;
6156
62- // find the coordinates of the parent DOM element
57+ // find the coordinates of the parent DOM element
6358 Rectangle bounds = element.getBoundingClientRect ();
6459 int left = (bounds.left + dom.window.pageXOffset).toInt ();
6560 int top = (bounds.top + dom.window.pageYOffset).toInt ();
66- int width = (bounds.width).toInt ();
67- int height = (bounds.height).toInt ();
68-
69- // position the tooltip.
70- // Figure out where the containing element sits in the window.
71- int tooltipLeft = left + width + 10 ;
72- int tooltipTop = top - height;
73- tooltipElem.style.position = "absolute" ;
74- tooltipElem.style.top = "${tooltipTop }px" ;
75- tooltipElem.style.left = "${tooltipLeft }px" ;
76-
77- // Add the tooltip to the document body. We add it here because
78- // we need to position it absolutely, without reference to its
79- // parent element.
61+ int width = bounds.width.toInt ();
62+ int height = bounds.height.toInt ();
63+
64+ // position the tooltip.
65+ // Figure out where the containing element sits in the window.
66+ tooltipElem.style
67+ ..position = "absolute"
68+ ..top = "${top - height }px"
69+ ..left = "${left + width + 10 }px" ;
70+
71+ // Add the tooltip to the document body. We add it here because
72+ // we need to position it absolutely, without reference to its
73+ // parent element.
8074 dom.document.body.append (tooltipElem);
8175 }
8276
@@ -90,6 +84,5 @@ class TooltipModel {
9084 String text;
9185 int imgWidth;
9286
93- TooltipModel (String this .imgUrl, String this .text,
94- int this .imgWidth);
87+ TooltipModel (this .imgUrl, this .text, this .imgWidth);
9588}
0 commit comments