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

Commit

Permalink
feat(modal): append using $animate
Browse files Browse the repository at this point in the history
- Use $animate.enter to append transcluded content

Closes #6023
Closes #6029
  • Loading branch information
Anthony Cleaver authored and wesleycho committed Jun 27, 2016
1 parent 433e536 commit 1cbd73d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,16 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap', 'ui.bootstrap.p
};
})

.directive('uibModalTransclude', function() {
.directive('uibModalTransclude', ['$animate', function($animate) {
return {
link: function(scope, element, attrs, controller, transclude) {
transclude(scope.$parent, function(clone) {
element.empty();
element.append(clone);
$animate.enter(clone, element);
});
}
};
})
}])

.factory('$uibModalStack', ['$animate', '$animateCss', '$document',
'$compile', '$rootScope', '$q', '$$multiMap', '$$stackedMap', '$uibPosition',
Expand Down
56 changes: 56 additions & 0 deletions src/modal/test/modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,62 @@ describe('$uibResolve', function() {
});
});

describe('uibModalTransclude', function() {
var uibModalTranscludeDDO,
$animate;

beforeEach(module('ui.bootstrap.modal'));
beforeEach(module(function($provide) {
$animate = jasmine.createSpyObj('$animate', ['enter']);
$provide.value('$animate', $animate);
}));

beforeEach(inject(function(uibModalTranscludeDirective) {
uibModalTranscludeDDO = uibModalTranscludeDirective[0];
}));

describe('when initialised', function() {
var scope,
element,
transcludeSpy,
transcludeFn;

beforeEach(function() {
scope = {
$parent: 'parentScope'
};

element = jasmine.createSpyObj('containerElement', ['empty']);
transcludeSpy = jasmine.createSpy('transcludeSpy').and.callFake(function(scope, fn) {
transcludeFn = fn;
});

uibModalTranscludeDDO.link(scope, element, {}, {}, transcludeSpy);
});

it('should call the transclusion function', function() {
expect(transcludeSpy).toHaveBeenCalledWith(scope.$parent, jasmine.any(Function));
});

describe('transclusion callback', function() {
var transcludedContent;

beforeEach(function() {
transcludedContent = 'my transcluded content';
transcludeFn(transcludedContent);
});

it('should empty the element', function() {
expect(element.empty).toHaveBeenCalledWith();
});

it('should append the transcluded content', function() {
expect($animate.enter).toHaveBeenCalledWith(transcludedContent, element);
});
});
});
});

describe('$uibModal', function() {
var $animate, $controllerProvider, $rootScope, $document, $compile, $templateCache, $timeout, $q;
var $uibModal, $uibModalStack, $uibModalProvider;
Expand Down

0 comments on commit 1cbd73d

Please sign in to comment.