@@ -117,6 +117,55 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
117
117
var hasRegisteredTriggers = false ;
118
118
var hasEnableExp = angular . isDefined ( attrs [ prefix + 'Enable' ] ) ;
119
119
120
+ var positionTooltip = function ( ) {
121
+ var position ,
122
+ ttWidth ,
123
+ ttHeight ,
124
+ ttPosition ;
125
+ // Get the position of the directive element.
126
+ position = appendToBody ? $position . offset ( element ) : $position . position ( element ) ;
127
+
128
+ // Get the height and width of the tooltip so we can center it.
129
+ ttWidth = tooltip . prop ( 'offsetWidth' ) ;
130
+ ttHeight = tooltip . prop ( 'offsetHeight' ) ;
131
+
132
+ // Calculate the tooltip's top and left coordinates to center it with
133
+ // this directive.
134
+ switch ( scope . tt_placement ) {
135
+ case 'right' :
136
+ ttPosition = {
137
+ top : position . top + position . height / 2 - ttHeight / 2 ,
138
+ left : position . left + position . width
139
+ } ;
140
+ break ;
141
+ case 'bottom' :
142
+ ttPosition = {
143
+ top : position . top + position . height ,
144
+ left : position . left + position . width / 2 - ttWidth / 2
145
+ } ;
146
+ break ;
147
+ case 'left' :
148
+ ttPosition = {
149
+ top : position . top + position . height / 2 - ttHeight / 2 ,
150
+ left : position . left - ttWidth
151
+ } ;
152
+ break ;
153
+ default :
154
+ ttPosition = {
155
+ top : position . top - ttHeight ,
156
+ left : position . left + position . width / 2 - ttWidth / 2
157
+ } ;
158
+ break ;
159
+ }
160
+
161
+ ttPosition . top += 'px' ;
162
+ ttPosition . left += 'px' ;
163
+
164
+ // Now set the calculated positioning.
165
+ tooltip . css ( ttPosition ) ;
166
+
167
+ } ;
168
+
120
169
// By default, the tooltip is not open.
121
170
// TODO add ability to start tooltip opened
122
171
scope . tt_isOpen = false ;
@@ -136,8 +185,9 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
136
185
}
137
186
if ( scope . tt_popupDelay ) {
138
187
popupTimeout = $timeout ( show , scope . tt_popupDelay ) ;
188
+ popupTimeout . then ( function ( reposition ) { reposition ( ) ; } ) ;
139
189
} else {
140
- scope . $apply ( show ) ;
190
+ scope . $apply ( show ) ( ) ;
141
191
}
142
192
}
143
193
@@ -149,14 +199,11 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
149
199
150
200
// Show the tooltip popup element.
151
201
function show ( ) {
152
- var position ,
153
- ttWidth ,
154
- ttHeight ,
155
- ttPosition ;
202
+
156
203
157
204
// Don't show empty tooltips.
158
205
if ( ! scope . tt_content ) {
159
- return ;
206
+ return angular . noop ;
160
207
}
161
208
162
209
// If there is a pending remove transition, we must cancel it, lest the
@@ -176,50 +223,14 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
176
223
element . after ( tooltip ) ;
177
224
}
178
225
179
- // Get the position of the directive element.
180
- position = appendToBody ? $position . offset ( element ) : $position . position ( element ) ;
181
-
182
- // Get the height and width of the tooltip so we can center it.
183
- ttWidth = tooltip . prop ( 'offsetWidth' ) ;
184
- ttHeight = tooltip . prop ( 'offsetHeight' ) ;
185
-
186
- // Calculate the tooltip's top and left coordinates to center it with
187
- // this directive.
188
- switch ( scope . tt_placement ) {
189
- case 'right' :
190
- ttPosition = {
191
- top : position . top + position . height / 2 - ttHeight / 2 ,
192
- left : position . left + position . width
193
- } ;
194
- break ;
195
- case 'bottom' :
196
- ttPosition = {
197
- top : position . top + position . height ,
198
- left : position . left + position . width / 2 - ttWidth / 2
199
- } ;
200
- break ;
201
- case 'left' :
202
- ttPosition = {
203
- top : position . top + position . height / 2 - ttHeight / 2 ,
204
- left : position . left - ttWidth
205
- } ;
206
- break ;
207
- default :
208
- ttPosition = {
209
- top : position . top - ttHeight ,
210
- left : position . left + position . width / 2 - ttWidth / 2
211
- } ;
212
- break ;
213
- }
214
-
215
- ttPosition . top += 'px' ;
216
- ttPosition . left += 'px' ;
226
+ positionTooltip ( ) ;
217
227
218
- // Now set the calculated positioning.
219
- tooltip . css ( ttPosition ) ;
220
-
221
228
// And show the tooltip.
222
229
scope . tt_isOpen = true ;
230
+
231
+ // Return positioning function as promise callback for correct
232
+ // positioning after draw.
233
+ return positionTooltip ;
223
234
}
224
235
225
236
// Hide the tooltip popup element.
0 commit comments