This repository was archived by the owner on May 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
feat(collapse): add possibility to collapse horizontally #6010
Closed
Closed
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
180e58d
feat(directive): add possibility to collapse horizontally
squelix 9eb6487
fix(example): correct the horizontal collapse example
squelix 7d55c1e
fix(collapse): forget to horizontal attribute
squelix 1759dae
Update dropdown.js
squelix 4973dc7
Update dropdown.js
squelix a134e98
fix(collapse): refactor
squelix 8881967
fix(collapse): refactor
squelix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,14 +7,26 @@ angular.module('ui.bootstrap.collapse', []) | |
var expandingExpr = $parse(attrs.expanding), | ||
expandedExpr = $parse(attrs.expanded), | ||
collapsingExpr = $parse(attrs.collapsing), | ||
collapsedExpr = $parse(attrs.collapsed); | ||
collapsedExpr = $parse(attrs.collapsed), | ||
horizontal = false; | ||
|
||
horizontal = !!('horizontal' in attrs); | ||
|
||
if (!scope.$eval(attrs.uibCollapse)) { | ||
element.addClass('in') | ||
.addClass('collapse') | ||
.attr('aria-expanded', true) | ||
.attr('aria-hidden', false) | ||
.css({height: 'auto'}); | ||
if (horizontal) { | ||
element.addClass('in') | ||
.addClass('collapse') | ||
.attr('aria-expanded', true) | ||
.attr('aria-hidden', false) | ||
.css({width: 'auto'}) | ||
.css({height: 'inherit'}); | ||
} else { | ||
element.addClass('in') | ||
.addClass('collapse') | ||
.attr('aria-expanded', true) | ||
.attr('aria-hidden', false) | ||
.css({height: 'auto'}); | ||
} | ||
} | ||
|
||
function expand() { | ||
|
@@ -29,24 +41,44 @@ angular.module('ui.bootstrap.collapse', []) | |
.attr('aria-expanded', true) | ||
.attr('aria-hidden', false); | ||
|
||
if ($animateCss) { | ||
$animateCss(element, { | ||
addClass: 'in', | ||
easing: 'ease', | ||
to: { height: element[0].scrollHeight + 'px' } | ||
}).start()['finally'](expandDone); | ||
if (horizontal) { | ||
if ($animateCss) { | ||
$animateCss(element, { | ||
addClass: 'in', | ||
easing: 'ease', | ||
to: {width: element[0].scrollWidth + 'px'} | ||
}).start()['finally'](expandDone); | ||
} else { | ||
$animate.addClass(element, 'in', { | ||
to: {width: element[0].scrollWidth + 'px'} | ||
}).then(expandDone); | ||
} | ||
} else { | ||
$animate.addClass(element, 'in', { | ||
to: { height: element[0].scrollHeight + 'px' } | ||
}).then(expandDone); | ||
if ($animateCss) { | ||
$animateCss(element, { | ||
addClass: 'in', | ||
easing: 'ease', | ||
to: {height: element[0].scrollHeight + 'px'} | ||
}).start()['finally'](expandDone); | ||
} else { | ||
$animate.addClass(element, 'in', { | ||
to: {height: element[0].scrollHeight + 'px'} | ||
}).then(expandDone); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
function expandDone() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Modify function so we can DRY this up, i.e. function expandDone(prop) {
return function() {
var css = {};
css[prop] = 'auto';
...
};
} Or just pass the desired object wholesale |
||
element.removeClass('collapsing') | ||
.addClass('collapse') | ||
.css({height: 'auto'}); | ||
if (horizontal) { | ||
element.removeClass('collapsing') | ||
.addClass('collapse') | ||
.css({width: 'auto'}); | ||
} else { | ||
element.removeClass('collapsing') | ||
.addClass('collapse') | ||
.css({height: 'auto'}); | ||
} | ||
expandedExpr(scope); | ||
} | ||
|
||
|
@@ -57,33 +89,62 @@ angular.module('ui.bootstrap.collapse', []) | |
|
||
$q.resolve(collapsingExpr(scope)) | ||
.then(function() { | ||
element | ||
if (horizontal) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrap all the logic in a helper function to help DRY up |
||
element | ||
// IMPORTANT: The width must be set before adding "collapsing" class. | ||
// Otherwise, the browser attempts to animate from width 0 (in | ||
// collapsing class) to the given width here. | ||
.css({width: element[0].scrollWidth + 'px'}) | ||
// initially all panel collapse have the collapse class, this removal | ||
// prevents the animation from jumping to collapsed state | ||
.removeClass('collapse') | ||
.addClass('collapsing') | ||
.attr('aria-expanded', false) | ||
.attr('aria-hidden', true); | ||
|
||
if ($animateCss) { | ||
$animateCss(element, { | ||
removeClass: 'in', | ||
to: {width: '0'} | ||
}).start()['finally'](collapseDone); | ||
} else { | ||
$animate.removeClass(element, 'in', { | ||
to: {width: '0'} | ||
}).then(collapseDone); | ||
} | ||
} else { | ||
element | ||
// IMPORTANT: The height must be set before adding "collapsing" class. | ||
// Otherwise, the browser attempts to animate from height 0 (in | ||
// collapsing class) to the given height here. | ||
.css({height: element[0].scrollHeight + 'px'}) | ||
// initially all panel collapse have the collapse class, this removal | ||
// prevents the animation from jumping to collapsed state | ||
.removeClass('collapse') | ||
.addClass('collapsing') | ||
.attr('aria-expanded', false) | ||
.attr('aria-hidden', true); | ||
.css({height: element[0].scrollHeight + 'px'}) | ||
// initially all panel collapse have the collapse class, this removal | ||
// prevents the animation from jumping to collapsed state | ||
.removeClass('collapse') | ||
.addClass('collapsing') | ||
.attr('aria-expanded', false) | ||
.attr('aria-hidden', true); | ||
|
||
if ($animateCss) { | ||
$animateCss(element, { | ||
removeClass: 'in', | ||
to: {height: '0'} | ||
}).start()['finally'](collapseDone); | ||
} else { | ||
$animate.removeClass(element, 'in', { | ||
to: {height: '0'} | ||
}).then(collapseDone); | ||
if ($animateCss) { | ||
$animateCss(element, { | ||
removeClass: 'in', | ||
to: {height: '0'} | ||
}).start()['finally'](collapseDone); | ||
} else { | ||
$animate.removeClass(element, 'in', { | ||
to: {height: '0'} | ||
}).then(collapseDone); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
function collapseDone() { | ||
element.css({height: '0'}); // Required so that collapse works when animation is disabled | ||
if (horizontal) { | ||
element.css({width: '0'}); // Required so that collapse works when animation is disabled | ||
} else { | ||
element.css({height: '0'}); // Required so that collapse works when animation is disabled | ||
} | ||
element.removeClass('collapsing') | ||
.addClass('collapse'); | ||
collapsedExpr(scope); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
<div ng-controller="CollapseDemoCtrl"> | ||
<button type="button" class="btn btn-default" ng-click="isCollapsed = !isCollapsed">Toggle collapse</button> | ||
<button type="button" class="btn btn-default" ng-click="isCollapsed = !isCollapsed">Toggle collapse Vertically</button> | ||
<hr> | ||
<div uib-collapse="isCollapsed"> | ||
<div class="well well-lg">Some content</div> | ||
</div> | ||
|
||
<button type="button" class="btn btn-default" ng-click="isCollapsedHorizontal = !isCollapsedHorizontal">Toggle collapse Horizontally</button> | ||
<hr> | ||
<div uib-collapse="isCollapsedHorizontal" horizontal> | ||
<div class="well well-lg">Some content</div> | ||
</div> | ||
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
angular.module('ui.bootstrap.demo').controller('CollapseDemoCtrl', function ($scope) { | ||
$scope.isCollapsed = false; | ||
$scope.isCollapsedHorizontal = false; | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It probably would be worthwhile converting everything in here into a helper function to avoid duplication between horizontal and vertical collapsing.