@@ -7,76 +7,70 @@ import 'package:angular/angular.dart';
7
7
@NgDirective (
8
8
selector: '[tooltip]' ,
9
9
map: const {
10
- 'tooltip' : '=>displayModel'
10
+ 'tooltip' : '=>displayModel'
11
11
}
12
12
)
13
13
class 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.
17
17
dom.Element element;
18
18
dom.Node node;
19
19
Scope scope;
20
20
TooltipModel displayModel;
21
21
22
22
dom.Element tooltipElem;
23
23
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 ());
34
28
}
35
29
36
30
_createTemplate () {
37
31
assert (displayModel != null );
38
32
39
33
tooltipElem = new dom.DivElement ();
40
34
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;
44
38
tooltipElem.append (imgElem);
45
39
46
40
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" ;
52
46
53
47
tooltipElem.append (textSpan);
54
48
}
55
49
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" ;
61
56
62
- // find the coordinates of the parent DOM element
57
+ // find the coordinates of the parent DOM element
63
58
Rectangle bounds = element.getBoundingClientRect ();
64
59
int left = (bounds.left + dom.window.pageXOffset).toInt ();
65
60
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.
80
74
dom.document.body.append (tooltipElem);
81
75
}
82
76
@@ -90,6 +84,5 @@ class TooltipModel {
90
84
String text;
91
85
int imgWidth;
92
86
93
- TooltipModel (String this .imgUrl, String this .text,
94
- int this .imgWidth);
87
+ TooltipModel (this .imgUrl, this .text, this .imgWidth);
95
88
}
0 commit comments