Skip to content

Commit

Permalink
feat($ionicModal): pass modal instance to modal.shown/modal.hidden ev…
Browse files Browse the repository at this point in the history
…ents

Fixes #1065
  • Loading branch information
ajoslin committed Apr 7, 2014
1 parent c6f5ed3 commit a19e3b6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions js/ext/angular/src/service/ionicModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ function($rootScope, $document, $compile, $timeout, $ionicPlatform, $ionicTempla
*
* Hint: Be sure to call [remove()](#remove) when you are done with each modal
* to clean it up and avoid memory leaks.
*
* Note: a modal will broadcast 'modal.shown' and 'modal.hidden' events from its originating
* scope, passing in itself as an event argument.
*/
var ModalView = ionic.views.Modal.inherit({
/**
Expand Down Expand Up @@ -113,7 +116,7 @@ function($rootScope, $document, $compile, $timeout, $ionicPlatform, $ionicTempla

$timeout(function(){
modalEl.addClass('ng-enter-active');
self.scope.$parent && self.scope.$parent.$broadcast('modal.shown');
self.scope.$parent && self.scope.$parent.$broadcast('modal.shown', self);
self.el.classList.add('active');
}, 20);

Expand All @@ -139,7 +142,7 @@ function($rootScope, $document, $compile, $timeout, $ionicPlatform, $ionicTempla
}, 20);

self._isShown = false;
self.scope.$parent && self.scope.$parent.$broadcast('modal.hidden');
self.scope.$parent && self.scope.$parent.$broadcast('modal.hidden', self);
self._deregisterBackButton && self._deregisterBackButton();

ionic.views.Modal.prototype.hide.call(self);
Expand Down
8 changes: 4 additions & 4 deletions js/ext/angular/test/service/ionicModal.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,21 @@ describe('Ionic Modal', function() {
expect(modalInstance.isShown()).toBe(false);
});

it('should broadcast "modal.shown" on show', function() {
it('should broadcast "modal.shown" on show with self', function() {
var template = '<div class="modal"></div>';
var m = modal.fromTemplate(template, {});
spyOn(m.scope.$parent, '$broadcast');
m.show();
timeout.flush();
expect(m.scope.$parent.$broadcast).toHaveBeenCalledWith('modal.shown');
expect(m.scope.$parent.$broadcast).toHaveBeenCalledWith('modal.shown', m);
});

it('should broadcast "modal.hidden" on hide', function() {
it('should broadcast "modal.hidden" on hide with self', function() {
var template = '<div class="modal"></div>';
var m = modal.fromTemplate(template, {});
spyOn(m.scope.$parent, '$broadcast');
m.hide();
expect(m.scope.$parent.$broadcast).toHaveBeenCalledWith('modal.hidden');
expect(m.scope.$parent.$broadcast).toHaveBeenCalledWith('modal.hidden', m);
});

it('should broadcast "modal.removed" on remove', inject(function($animate) {
Expand Down

0 comments on commit a19e3b6

Please sign in to comment.