Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 6458f48

Browse files
Josh David Millerpkozlowski-opensource
Josh David Miller
authored andcommitted
fix($tooltip): fix positioning issues in tooltips and popovers
To calculate the relative position of the tooltip or popover, the $tooltip service now uses the $position service, which resolves many positioning bugs. Closes #265, #115
1 parent 7bd1a91 commit 6458f48

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

src/popover/docs/readme.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ will display:
1414
- `popover-popup-delay`: For how long should the user have to have the mouse
1515
over the element before the popover shows (in milliseconds)? Defaults to 0.
1616

17+
The popover directives require the `$position` service.
18+

src/tooltip/docs/readme.md

+2
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ will display:
1616
- `tooltip-popup-delay`: For how long should the user have to have the mouse
1717
over the element before the tooltip shows (in milliseconds)? Defaults to 0.
1818

19+
The tooltip directives require the `$position` service.
20+

src/tooltip/tooltip.js

+3-14
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* function, placement as a function, inside, support for more triggers than
44
* just mouse enter/leave, html tooltips, and selector delegation.
55
*/
6-
angular.module( 'ui.bootstrap.tooltip', [] )
6+
angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] )
77

88
/**
99
* The $tooltip service creates tooltip- and popover-like directives as well as
@@ -48,7 +48,7 @@ angular.module( 'ui.bootstrap.tooltip', [] )
4848
* Returns the actual instance of the $tooltip service.
4949
* TODO support multiple triggers
5050
*/
51-
this.$get = [ '$window', '$compile', '$timeout', '$parse', '$document', function ( $window, $compile, $timeout, $parse, $document ) {
51+
this.$get = [ '$window', '$compile', '$timeout', '$parse', '$document', '$position', function ( $window, $compile, $timeout, $parse, $document, $position ) {
5252
return function $tooltip ( type, prefix, defaultTriggerShow, defaultTriggerHide ) {
5353
var options = angular.extend( {}, defaultOptions, globalOptions );
5454
var directiveName = snake_case( type );
@@ -63,17 +63,6 @@ angular.module( 'ui.bootstrap.tooltip', [] )
6363
'>'+
6464
'</'+ directiveName +'-popup>';
6565

66-
// Calculate the current position and size of the directive element.
67-
function getPosition( element ) {
68-
var boundingClientRect = element[0].getBoundingClientRect();
69-
return {
70-
width: element.prop( 'offsetWidth' ),
71-
height: element.prop( 'offsetHeight' ),
72-
top: boundingClientRect.top + $window.pageYOffset,
73-
left: boundingClientRect.left + $window.pageXOffset
74-
};
75-
}
76-
7766
return {
7867
restrict: 'EA',
7968
scope: true,
@@ -148,7 +137,7 @@ angular.module( 'ui.bootstrap.tooltip', [] )
148137
}
149138

150139
// Get the position of the directive element.
151-
position = getPosition( element );
140+
position = $position.position( element );
152141

153142
// Get the height and width of the tooltip so we can center it.
154143
ttWidth = tooltip.prop( 'offsetWidth' );

0 commit comments

Comments
 (0)