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

Commit

Permalink
feat(optionalAnimations): adds an attribute "animate" to enable/disab…
Browse files Browse the repository at this point in the history
…le animations
  • Loading branch information
widmoser committed Feb 19, 2016
1 parent 5e23ee9 commit 845428c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
14 changes: 10 additions & 4 deletions src/ui-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ angular.module('ui.layout', [])

Layout.addLayout(ctrl);

ctrl.animate = $attrs.animate;

ctrl.containers = [];
ctrl.movingSplitbar = null;
ctrl.bounds = $element[0].getBoundingClientRect();
Expand Down Expand Up @@ -680,8 +682,10 @@ angular.module('ui.layout', [])
if(!element.hasClass('stretch')) element.addClass('stretch');
if(!element.hasClass('ui-splitbar')) element.addClass('ui-splitbar');

var animationClass = ctrl.isUsingColumnFlow ? 'animate-column' : 'animate-row';
element.addClass(animationClass);
if (ctrl.animate !== 'false') {
var animationClass = ctrl.isUsingColumnFlow ? 'animate-column' : 'animate-row';
element.addClass(animationClass);
}

scope.splitbar = LayoutContainer.Splitbar();
scope.splitbar.element = element;
Expand Down Expand Up @@ -920,8 +924,10 @@ angular.module('ui.layout', [])
if(!element.hasClass('stretch')) element.addClass('stretch');
if(!element.hasClass('ui-layout-container')) element.addClass('ui-layout-container');

var animationClass = ctrl.isUsingColumnFlow ? 'animate-column' : 'animate-row';
element.addClass(animationClass);
if (ctrl.animate !== 'false') {
var animationClass = ctrl.isUsingColumnFlow ? 'animate-column' : 'animate-row';
element.addClass(animationClass);
}

scope.$watch('collapsed', function (val, old) {
if (angular.isDefined(old) && val !== old) {
Expand Down
44 changes: 37 additions & 7 deletions test/uiLayoutContainer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@

describe('Directive: uiLayoutContainer', function () {
var scope, element, $compile,
template = '' +
'<div ui-layout="{flow: \'column\'}" ui-layout-loaded>' +
' <div ui-layout-container collapsed="layout.beforeContainer" size="100px" min-size="50px" max-size="200px" resizable="false">One</div>' +
' <div ui-layout-container data-collapsed="layout.afterContainer">Two</div>' +
'</div>';
template = function(params) {
return '' +
'<div ui-layout="{flow: \'column\'}" ui-layout-loaded ' + (params.animate || '') + '>' +
' <div ui-layout-container collapsed="layout.beforeContainer" size="100px" min-size="50px" max-size="200px" resizable="false">One</div>' +
' <div ui-layout-container data-collapsed="layout.afterContainer">Two</div>' +
'</div>';
};

function createDirective(layout) {
var elm;

scope.layout = layout;
elm = angular.element(template);
elm = angular.element(template(layout));
angular.element(document.body).prepend(elm);
$compile(elm)(scope);
scope.$digest();
Expand All @@ -38,7 +40,7 @@ describe('Directive: uiLayoutContainer', function () {

it('should get initial attribute values', function () {
// this tests values _after_ the layout has been calculated
element = createDirective({ beforeContainer: true, afterContainer: false});
element = createDirective({ beforeContainer: true, afterContainer: false });
var divs = element.find('div'),
beforeContainer = divs[0],
afterContainer = divs[2],
Expand All @@ -61,4 +63,32 @@ describe('Directive: uiLayoutContainer', function () {

});

it('should be animated when the attribute is explicitly set', function() {
element = createDirective({ beforeContainer: true, afterContainer: false, animate: 'animate="true"'});
var divs = element.find('div'),
beforeContainer = divs[0],
afterContainer = divs[2];

expect(angular.element(beforeContainer).hasClass('animate-column')).toEqual(true);
expect(angular.element(afterContainer).hasClass('animate-column')).toEqual(true);
});

it('should be animated when the attribute is not set', function() {
element = createDirective({ beforeContainer: true, afterContainer: false});
var divs = element.find('div'),
beforeContainer = divs[0],
afterContainer = divs[2];
expect(angular.element(beforeContainer).hasClass('animate-column')).toEqual(true);
expect(angular.element(afterContainer).hasClass('animate-column')).toEqual(true);
});

it('should not be animated when the attribute is set to false', function() {
element = createDirective({ beforeContainer: true, afterContainer: false, animate: 'animate="false"'});
var divs = element.find('div'),
beforeContainer = divs[0],
afterContainer = divs[2];
expect(angular.element(beforeContainer).hasClass('animate-column')).toEqual(false);
expect(angular.element(afterContainer).hasClass('animate-column')).toEqual(false);
});

});

0 comments on commit 845428c

Please sign in to comment.