From a19e3b62f80f69cec9d478a095b4a59d0dca8742 Mon Sep 17 00:00:00 2001 From: Andy Joslin Date: Mon, 7 Apr 2014 08:04:07 -0600 Subject: [PATCH] feat($ionicModal): pass modal instance to modal.shown/modal.hidden events Fixes #1065 --- js/ext/angular/src/service/ionicModal.js | 7 +++++-- js/ext/angular/test/service/ionicModal.unit.js | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/js/ext/angular/src/service/ionicModal.js b/js/ext/angular/src/service/ionicModal.js index 6ebfaffab48..4bb5d5ebed7 100644 --- a/js/ext/angular/src/service/ionicModal.js +++ b/js/ext/angular/src/service/ionicModal.js @@ -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({ /** @@ -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); @@ -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); diff --git a/js/ext/angular/test/service/ionicModal.unit.js b/js/ext/angular/test/service/ionicModal.unit.js index d5b40fe8a02..356e99dc297 100644 --- a/js/ext/angular/test/service/ionicModal.unit.js +++ b/js/ext/angular/test/service/ionicModal.unit.js @@ -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 = ''; 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 = ''; 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) {