Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
fix(tooltip): always append to body and disappear on scroll
Browse files Browse the repository at this point in the history
- Default animation origin has been set to bottom that mean the origin is `top center`

Closes #6140
  • Loading branch information
EladBezalel authored and jelbourn committed Dec 8, 2015
1 parent db72b39 commit 9d72659
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/components/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,19 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdThe

var parent = $mdUtil.getParentWithPointerEvents(element),
content = angular.element(element[0].getElementsByClassName('md-content')[0]),
current = $mdUtil.getNearestContentElement(element),
tooltipParent = angular.element(current || document.body),
tooltipParent = angular.element(document.body),
debouncedOnResize = $$rAF.throttle(function () { updatePosition(); });

if ($animate.pin) $animate.pin(element, parent);

// Initialize element

setDefaults();
manipulateElement();
bindEvents();

// Default origin transform point is 'left top'
// positionTooltip() is always relative to top left
// Default origin transform point is 'center top'
// positionTooltip() is always relative to center top
updateContentOrigin();

configureWatchers();
Expand All @@ -81,7 +82,7 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdThe
}

function updateContentOrigin() {
var origin = 'left top';
var origin = 'center top';
switch (scope.direction) {
case 'left' : origin = 'right center'; break;
case 'right' : origin = 'left center'; break;
Expand Down Expand Up @@ -137,19 +138,25 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdThe
});

attributeObserver.observe(parent[0], { attributes: true});
};
}

// Store whether the element was focused when the window loses focus.
var windowBlurHandler = function() {
elementFocusedOnWindowBlur = document.activeElement === parent[0];
};
var elementFocusedOnWindowBlur = false;

function windowScrollHandler() {
setVisible(false);
}

ngWindow.on('blur', windowBlurHandler);
ngWindow.on('resize', debouncedOnResize);
document.addEventListener('scroll', windowScrollHandler, true);
scope.$on('$destroy', function() {
ngWindow.off('blur', windowBlurHandler);
ngWindow.off('resize', debouncedOnResize);
document.removeEventListener('scroll', windowScrollHandler, true);
attributeObserver && attributeObserver.disconnect();
});

Expand Down
1 change: 1 addition & 0 deletions src/components/tooltip/tooltip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ md-tooltip {
&.md-show, &.md-show-add-active {
transform: scale(1);
opacity: 1;
transform-origin: center top;
}
&.md-show-remove {
transition: $swift-ease-out;
Expand Down

0 comments on commit 9d72659

Please sign in to comment.