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

Commit

Permalink
fix(collapse): remove element height watching
Browse files Browse the repository at this point in the history
For unclear reasons the directive was watching DOM element's height
which incurs performance penalty. Normally this watching shouldn't be
necessery as collapsible elements should get height: auto;

Closes #1222
  • Loading branch information
pkozlowski-opensource committed Nov 11, 2013
1 parent fd21214 commit a72c635
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 33 deletions.
18 changes: 1 addition & 17 deletions src/collapse/collapse.js
Expand Up @@ -22,23 +22,7 @@ angular.module('ui.bootstrap.collapse',['ui.bootstrap.transition'])

var isCollapsed;
var initialAnimSkip = true;
scope.$watch(function (){ return element[0].scrollHeight; }, function (value) {
//The listener is called when scollHeight changes
//It actually does on 2 scenarios:
// 1. Parent is set to display none
// 2. angular bindings inside are resolved
//When we have a change of scrollHeight we are setting again the correct height if the group is opened
if (element[0].scrollHeight !== 0) {
if (!isCollapsed) {
if (initialAnimSkip) {
fixUpHeight(scope, element, element[0].scrollHeight + 'px');
} else {
fixUpHeight(scope, element, 'auto');
}
}
}
});


scope.$watch(attrs.collapse, function(value) {
if (value) {
collapse();
Expand Down
16 changes: 0 additions & 16 deletions src/collapse/test/collapse.spec.js
Expand Up @@ -86,21 +86,5 @@ describe('collapse directive', function () {
expect(element.height()).toBeLessThan(collapseHeight);
});

it('should shrink accordingly when content size inside collapse decreases on subsequent use', function() {
scope.isCollapsed = false;
scope.exp = false;
scope.$digest();
scope.isCollapsed = true;
scope.$digest();
scope.isCollapsed = false;
scope.$digest();
$timeout.flush();
scope.exp = true;
scope.$digest();
var collapseHeight = element.height();
scope.exp = false;
scope.$digest();
expect(element.height()).toBeLessThan(collapseHeight);
});
});
});

0 comments on commit a72c635

Please sign in to comment.