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

Commit a2bbf4d

Browse files
fix(tooltip): fix placement issues
Closes #115
1 parent ff5d119 commit a2bbf4d

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/popover/popover.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ angular.module( 'ui.bootstrap.popover', [] )
1212
templateUrl: 'template/popover/popover.html'
1313
};
1414
})
15-
.directive( 'popover', [ '$compile', '$timeout', '$parse', function ( $compile, $timeout, $parse ) {
15+
.directive( 'popover', [ '$compile', '$timeout', '$parse', '$window', function ( $compile, $timeout, $parse, $window ) {
1616

1717
var template =
1818
'<popover-popup '+
@@ -52,15 +52,15 @@ angular.module( 'ui.bootstrap.popover', [] )
5252

5353
// Calculate the current position and size of the directive element.
5454
function getPosition() {
55+
var boundingClientRect = element[0].getBoundingClientRect();
5556
return {
5657
width: element.prop( 'offsetWidth' ),
5758
height: element.prop( 'offsetHeight' ),
58-
top: element.prop( 'offsetTop' ),
59-
left: element.prop( 'offsetLeft' )
59+
top: boundingClientRect.top + $window.pageYOffset,
60+
left: boundingClientRect.left + $window.pageXOffset
6061
};
6162
}
62-
63-
// Show the popover popup element.
63+
6464
function show() {
6565
var position,
6666
ttWidth,

src/tooltip/tooltip.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ angular.module( 'ui.bootstrap.tooltip', [] )
1212
templateUrl: 'template/tooltip/tooltip-popup.html'
1313
};
1414
})
15-
.directive( 'tooltip', [ '$compile', '$timeout', '$parse', function ( $compile, $timeout, $parse ) {
15+
.directive( 'tooltip', [ '$compile', '$timeout', '$parse', '$window', function ( $compile, $timeout, $parse, $window) {
1616

1717
var template =
1818
'<tooltip-popup '+
@@ -47,11 +47,12 @@ angular.module( 'ui.bootstrap.tooltip', [] )
4747

4848
// Calculate the current position and size of the directive element.
4949
function getPosition() {
50+
var boundingClientRect = element[0].getBoundingClientRect();
5051
return {
5152
width: element.prop( 'offsetWidth' ),
5253
height: element.prop( 'offsetHeight' ),
53-
top: element.prop( 'offsetTop' ),
54-
left: element.prop( 'offsetLeft' )
54+
top: boundingClientRect.top + $window.pageYOffset,
55+
left: boundingClientRect.left + $window.pageXOffset
5556
};
5657
}
5758

@@ -82,7 +83,7 @@ angular.module( 'ui.bootstrap.tooltip', [] )
8283

8384
// Get the position of the directive element.
8485
position = getPosition();
85-
86+
8687
// Get the height and width of the tooltip so we can center it.
8788
ttWidth = tooltip.prop( 'offsetWidth' );
8889
ttHeight = tooltip.prop( 'offsetHeight' );

0 commit comments

Comments
 (0)