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

Commit

Permalink
feat(interimElement): add onShowing event
Browse files Browse the repository at this point in the history
Currently hideElement has an onRemoving event, this is the showElement equivalent. Useful when dealing with loading spinners that should disappear before the dialog shows.

Closes #4820.
  • Loading branch information
Patrik-Lundqvist authored and ThomasBurleson committed Oct 6, 2015
1 parent f03aca6 commit 39efc85
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/components/dialog/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ function MdDialogDirective($$rAF, $mdTheming, $mdDialog) {
* - `controllerAs` - `{string=}`: An alias to assign the controller to on the scope.
* - `parent` - `{element=}`: The element to append the dialog to. Defaults to appending
* to the root element of the application.
* - `onShowing` `{function=} Callback function used to announce the show() action is
* starting.
* - `onComplete` `{function=}`: Callback function used to announce when the show() action is
* finished.
* - `onRemoving` `{function=} Callback function used to announce the close/hide() action is
Expand Down
25 changes: 25 additions & 0 deletions src/components/dialog/dialog.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,31 @@ describe('$mdDialog', function() {
});

describe('#build()', function() {
it('should support onShowing callbacks before `show()` starts', inject(function($mdDialog, $rootScope) {

var template = '<md-dialog>Hello</md-dialog>';
var parent = angular.element('<div>');
var showing = false;

$mdDialog.show({
template: template,
parent: parent,
onShowing: onShowing
});
$rootScope.$apply();

runAnimation();

function onShowing(scope, element, options) {
showing = true;
container = angular.element(parent[0].querySelector('.md-dialog-container'));
expect(arguments.length).toEqual(3);
expect(container.length).toBe(0);
}

expect(showing).toBe(true);
}));

it('should support onComplete callbacks within `show()`', inject(function($mdDialog, $rootScope, $timeout, $mdConstant) {

var template = '<md-dialog>Hello</md-dialog>';
Expand Down
3 changes: 3 additions & 0 deletions src/core/services/interimElement/interimElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,11 +596,14 @@ function InterimElementProvider() {
* optional auto-Hide
*/
function showElement(element, options, controller) {
// Trigger onShowing callback before the `show()` starts
var notifyShowing = options.onShowing || angular.noop;
// Trigger onComplete callback when the `show()` finishes
var notifyComplete = options.onComplete || angular.noop;

return $q(function (resolve, reject) {
try {
notifyShowing(options.scope, element, options);

// Start transitionIn
$q.when(options.onShow(options.scope, element, options, controller))
Expand Down
22 changes: 22 additions & 0 deletions src/core/services/interimElement/interimElement.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,28 @@ describe('$$interimElement service', function() {
expect(autoClosed).toBe(true);
}));

it('calls onShowing before onShow', inject(function() {
var onShowingCalled = false;

Service.show({
template: '<some-element />',
passingOptions: true,
onShowing: onShowing,
onShow: onShow
});

expect(onShowingCalled).toBe(true);

function onShowing(scope, el, options) {
expect(arguments.length).toEqual(3);
onShowingCalled = true;
}

function onShow(scope, el, options) {
expect(onShowingCalled).toBe(true);
}
}));

it('calls onRemove', inject(function() {
var onRemoveCalled = false;
Service.show({
Expand Down

0 comments on commit 39efc85

Please sign in to comment.