|
3 | 3 | * function, placement as a function, inside, support for more triggers than
|
4 | 4 | * just mouse enter/leave, html popovers, and selector delegatation.
|
5 | 5 | */
|
6 |
| -angular.module( 'ui.bootstrap.popover', [] ) |
| 6 | +angular.module( 'ui.bootstrap.popover', [ 'ui.bootstrap.tooltip' ] ) |
7 | 7 | .directive( 'popoverPopup', function () {
|
8 | 8 | return {
|
9 | 9 | restrict: 'EA',
|
10 | 10 | replace: true,
|
11 |
| - scope: { popoverTitle: '@', popoverContent: '@', placement: '@', animation: '&', isOpen: '&' }, |
| 11 | + scope: { title: '@', content: '@', placement: '@', animation: '&', isOpen: '&' }, |
12 | 12 | templateUrl: 'template/popover/popover.html'
|
13 | 13 | };
|
14 | 14 | })
|
15 |
| -.directive( 'popover', [ '$compile', '$timeout', '$parse', '$window', function ( $compile, $timeout, $parse, $window ) { |
16 |
| - |
17 |
| - var template = |
18 |
| - '<popover-popup '+ |
19 |
| - 'popover-title="{{tt_title}}" '+ |
20 |
| - 'popover-content="{{tt_popover}}" '+ |
21 |
| - 'placement="{{tt_placement}}" '+ |
22 |
| - 'animation="tt_animation()" '+ |
23 |
| - 'is-open="tt_isOpen"'+ |
24 |
| - '>'+ |
25 |
| - '</popover-popup>'; |
26 |
| - |
27 |
| - return { |
28 |
| - scope: true, |
29 |
| - link: function ( scope, element, attr ) { |
30 |
| - var popover = $compile( template )( scope ), |
31 |
| - transitionTimeout; |
32 |
| - |
33 |
| - attr.$observe( 'popover', function ( val ) { |
34 |
| - scope.tt_popover = val; |
35 |
| - }); |
36 |
| - |
37 |
| - attr.$observe( 'popoverTitle', function ( val ) { |
38 |
| - scope.tt_title = val; |
39 |
| - }); |
40 |
| - |
41 |
| - attr.$observe( 'popoverPlacement', function ( val ) { |
42 |
| - // If no placement was provided, default to 'top'. |
43 |
| - scope.tt_placement = val || 'top'; |
44 |
| - }); |
45 |
| - |
46 |
| - attr.$observe( 'popoverAnimation', function ( val ) { |
47 |
| - scope.tt_animation = $parse( val ); |
48 |
| - }); |
49 |
| - |
50 |
| - // By default, the popover is not open. |
51 |
| - scope.tt_isOpen = false; |
52 |
| - |
53 |
| - // Calculate the current position and size of the directive element. |
54 |
| - function getPosition() { |
55 |
| - var boundingClientRect = element[0].getBoundingClientRect(); |
56 |
| - return { |
57 |
| - width: element.prop( 'offsetWidth' ), |
58 |
| - height: element.prop( 'offsetHeight' ), |
59 |
| - top: boundingClientRect.top + $window.pageYOffset, |
60 |
| - left: boundingClientRect.left + $window.pageXOffset |
61 |
| - }; |
62 |
| - } |
63 |
| - |
64 |
| - function show() { |
65 |
| - var position, |
66 |
| - ttWidth, |
67 |
| - ttHeight, |
68 |
| - ttPosition; |
69 |
| - |
70 |
| - // If there is a pending remove transition, we must cancel it, lest the |
71 |
| - // toolip be mysteriously removed. |
72 |
| - if ( transitionTimeout ) { |
73 |
| - $timeout.cancel( transitionTimeout ); |
74 |
| - } |
75 |
| - |
76 |
| - // Set the initial positioning. |
77 |
| - popover.css({ top: 0, left: 0, display: 'block' }); |
78 |
| - |
79 |
| - // Now we add it to the DOM because need some info about it. But it's not |
80 |
| - // visible yet anyway. |
81 |
| - element.after( popover ); |
82 |
| - |
83 |
| - // Get the position of the directive element. |
84 |
| - position = getPosition(); |
85 |
| - |
86 |
| - // Get the height and width of the popover so we can center it. |
87 |
| - ttWidth = popover.prop( 'offsetWidth' ); |
88 |
| - ttHeight = popover.prop( 'offsetHeight' ); |
89 |
| - |
90 |
| - // Calculate the popover's top and left coordinates to center it with |
91 |
| - // this directive. |
92 |
| - switch ( scope.tt_placement ) { |
93 |
| - case 'right': |
94 |
| - ttPosition = { |
95 |
| - top: (position.top + position.height / 2 - ttHeight / 2) + 'px', |
96 |
| - left: (position.left + position.width) + 'px' |
97 |
| - }; |
98 |
| - break; |
99 |
| - case 'bottom': |
100 |
| - ttPosition = { |
101 |
| - top: (position.top + position.height) + 'px', |
102 |
| - left: (position.left + position.width / 2 - ttWidth / 2) + 'px' |
103 |
| - }; |
104 |
| - break; |
105 |
| - case 'left': |
106 |
| - ttPosition = { |
107 |
| - top: (position.top + position.height / 2 - ttHeight / 2) + 'px', |
108 |
| - left: (position.left - ttWidth) + 'px' |
109 |
| - }; |
110 |
| - break; |
111 |
| - default: |
112 |
| - ttPosition = { |
113 |
| - top: (position.top - ttHeight) + 'px', |
114 |
| - left: (position.left + position.width / 2 - ttWidth / 2) + 'px' |
115 |
| - }; |
116 |
| - break; |
117 |
| - } |
118 |
| - |
119 |
| - // Now set the calculated positioning. |
120 |
| - popover.css( ttPosition ); |
121 |
| - |
122 |
| - // And show the popover. |
123 |
| - scope.tt_isOpen = true; |
124 |
| - } |
125 |
| - |
126 |
| - // Hide the popover popup element. |
127 |
| - function hide() { |
128 |
| - // First things first: we don't show it anymore. |
129 |
| - //popover.removeClass( 'in' ); |
130 |
| - scope.tt_isOpen = false; |
131 |
| - |
132 |
| - // And now we remove it from the DOM. However, if we have animation, we |
133 |
| - // need to wait for it to expire beforehand. |
134 |
| - // FIXME: this is a placeholder for a port of the transitions library. |
135 |
| - if ( angular.isDefined( scope.tt_animation ) && scope.tt_animation() ) { |
136 |
| - transitionTimeout = $timeout( function () { popover.remove(); }, 500 ); |
137 |
| - } else { |
138 |
| - popover.remove(); |
139 |
| - } |
140 |
| - } |
141 |
| - |
142 |
| - // Register the event listeners. |
143 |
| - element.bind( 'click', function() { |
144 |
| - if(scope.tt_isOpen){ |
145 |
| - scope.$apply( hide ); |
146 |
| - } else { |
147 |
| - scope.$apply( show ); |
148 |
| - } |
149 |
| - |
150 |
| - }); |
151 |
| - } |
152 |
| - }; |
| 15 | +.directive( 'popover', [ '$compile', '$timeout', '$parse', '$window', '$tooltip', function ( $compile, $timeout, $parse, $window, $tooltip ) { |
| 16 | + return $tooltip( 'popover', 'click' ); |
153 | 17 | }]);
|
154 | 18 |
|
0 commit comments