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

Commit 474ce52

Browse files
Monish Parajulipkozlowski-opensource
Monish Parajuli
authored andcommitted
fix(dialog): close dialog on location change
Closes #335
1 parent 74beecd commit 474ce52

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/dialog/dialog.js

+7
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ dialogModule.provider("$dialog", function(){
9393
e.preventDefault();
9494
self.$scope.$apply();
9595
};
96+
97+
this.handleLocationChange = function() {
98+
self.close();
99+
self.$scope.$apply();
100+
};
96101
}
97102

98103
// The `isOpen()` method returns wether the dialog is currently visible.
@@ -184,6 +189,8 @@ dialogModule.provider("$dialog", function(){
184189
Dialog.prototype._bindEvents = function() {
185190
if(this.options.keyboard){ body.bind('keydown', this.handledEscapeKey); }
186191
if(this.options.backdrop && this.options.backdropClick){ this.backdropEl.bind('click', this.handleBackDropClick); }
192+
193+
this.$scope.$on('$locationChangeSuccess', this.handleLocationChange);
187194
};
188195

189196
Dialog.prototype._unbindEvents = function() {

src/dialog/test/dialog.spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ describe('Given ui.bootstrap.dialog', function(){
5959
var clearGlobalOptions = function(){
6060
provider.options({});
6161
};
62+
63+
var changeLocation = function() {
64+
$rootScope.$broadcast('$locationChangeSuccess');
65+
$rootScope.$apply();
66+
};
6267

6368
var dialogShouldBeClosed = function(){
6469
it('should not include a backdrop in the DOM', function(){
@@ -287,6 +292,16 @@ describe('Given ui.bootstrap.dialog', function(){
287292
expect($document.find('body > div.modal > div.modal-header').length).toBe(1);
288293
});
289294
});
295+
296+
describe('When dialog is open and location changes', function(){
297+
beforeEach(function(){
298+
createDialog({template:template});
299+
openDialog();
300+
changeLocation();
301+
});
302+
303+
dialogShouldBeClosed();
304+
});
290305

291306
describe('when opening it with a template containing white-space', function(){
292307

src/modal/test/modal.spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -169,5 +169,11 @@ describe('Give ui.boostrap.modal', function() {
169169
$scope.$digest();
170170
expect($scope.modalShown).not.toBeTruthy();
171171
});
172+
173+
it('should update the model if the location change is successful', function() {
174+
$rootScope.$broadcast('$locationChangeSuccess');
175+
$scope.$digest();
176+
expect($scope.modalShown).not.toBeTruthy();
177+
});
172178
});
173179
});

0 commit comments

Comments
 (0)