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

Commit

Permalink
fix(tooltip): using tooltip inside subheader causes Firefox hang.
Browse files Browse the repository at this point in the history
When a `<md-tooltip>` was placed inside the `<md-subheader>`,
an infinite loop was being hit (only in Firefox) which was
causing the browser to hang.

The infinite loop was caused by the tooltip's
`getParentWithPointerEvents()` method which travels up the DOM looking for a parent who has pointer events. In Firefox, the `element.parent()` can apparently return an empty jqLite object that is not null, but whose length is 0. In this case, calling `parent.parent()` again will return the same object.

Add a check to the tooltip's loop to ensure that `parent.length` is never 0.

Fixes #4777. Closes #4800.
  • Loading branch information
topherfangio authored and ThomasBurleson committed Sep 23, 2015
1 parent c2e17ad commit 5bb3505
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/components/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,12 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdThe
*/
function getParentWithPointerEvents () {
var parent = element.parent();
while (parent && hasComputedStyleValue('pointer-events','none', parent[0])) {

// jqLite might return a non-null, but still empty, parent; so check for parent and length
while (hasComputedStyleValue('pointer-events','none', parent)) {
parent = parent.parent();
}

return parent;
}

Expand All @@ -123,12 +126,17 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdThe


function hasComputedStyleValue(key, value, target) {
key = attr.$normalize(key);
target = target || element[0];
var hasValue = false;

var computedStyles = $window.getComputedStyle(target);
if ( target && target.length ) {
key = attr.$normalize(key);
target = target[0] || element[0];

var computedStyles = $window.getComputedStyle(target);
hasValue = angular.isDefined(computedStyles[key]) && (computedStyles[key] == value);
}

return angular.isDefined(computedStyles[key]) && (computedStyles[key] == value);
return hasValue;
}

function bindEvents () {
Expand Down

0 comments on commit 5bb3505

Please sign in to comment.