\ No newline at end of file
diff --git a/src/modal/modal.js b/src/modal/modal.js
index 12ddfa8ee4..adcc95fe65 100644
--- a/src/modal/modal.js
+++ b/src/modal/modal.js
@@ -57,7 +57,7 @@ angular.module('ui.bootstrap.modal', [])
/**
* A helper directive for the $modal service. It creates a backdrop element.
*/
- .directive('modalBackdrop', ['$modalStack', '$timeout', function ($modalStack, $timeout) {
+ .directive('modalBackdrop', ['$timeout', function ($timeout) {
return {
restrict: 'EA',
replace: true,
@@ -70,20 +70,11 @@ angular.module('ui.bootstrap.modal', [])
$timeout(function () {
scope.animate = true;
});
-
- scope.close = function (evt) {
- var modal = $modalStack.getTop();
- if (modal && modal.value.backdrop && modal.value.backdrop != 'static') {
- evt.preventDefault();
- evt.stopPropagation();
- $modalStack.dismiss(modal.key, 'backdrop click');
- }
- };
}
};
}])
- .directive('modalWindow', ['$timeout', function ($timeout) {
+ .directive('modalWindow', ['$modalStack', '$timeout', function ($modalStack, $timeout) {
return {
restrict: 'EA',
scope: {
@@ -95,13 +86,21 @@ angular.module('ui.bootstrap.modal', [])
link: function (scope, element, attrs) {
scope.windowClass = attrs.windowClass || '';
- // focus a freshly-opened modal
- element[0].focus();
-
$timeout(function () {
// trigger CSS transitions
scope.animate = true;
+ // focus a freshly-opened modal
+ element[0].focus();
});
+
+ scope.close = function (evt) {
+ var modal = $modalStack.getTop();
+ if (modal && modal.value.backdrop && modal.value.backdrop != 'static' && (evt.target === evt.currentTarget)) {
+ evt.preventDefault();
+ evt.stopPropagation();
+ $modalStack.dismiss(modal.key, 'backdrop click');
+ }
+ };
}
};
}])
@@ -195,9 +194,9 @@ angular.module('ui.bootstrap.modal', [])
};
$modalStack.close = function (modalInstance, result) {
- var modal = openedWindows.get(modalInstance);
- if (modal) {
- modal.value.deferred.resolve(result);
+ var modalWindow = openedWindows.get(modalInstance).value;
+ if (modalWindow) {
+ modalWindow.deferred.resolve(result);
removeModalWindow(modalInstance);
}
};
diff --git a/src/modal/test/modal.spec.js b/src/modal/test/modal.spec.js
index 697eec6861..96abff51a1 100644
--- a/src/modal/test/modal.spec.js
+++ b/src/modal/test/modal.spec.js
@@ -56,7 +56,7 @@ describe('$modal', function () {
toHaveModalOpenWithContent: function(content, selector) {
- var contentToCompare, modalDomEls = this.actual.find('body > div.modal');
+ var contentToCompare, modalDomEls = this.actual.find('body > div.modal > div.modal-dialog > div.modal-content');
this.message = function() {
return "Expected '" + angular.mock.dump(modalDomEls) + "' to be open with '" + content + "'.";
@@ -154,7 +154,7 @@ describe('$modal', function () {
var modal = open({template: '
Content
'});
expect($document).toHaveModalsOpen(1);
- $document.find('body > div.modal-backdrop').click();
+ $document.find('body > div.modal').click();
$rootScope.$digest();
expect($document).toHaveModalsOpen(0);
diff --git a/template/modal/backdrop.html b/template/modal/backdrop.html
index ebf8aa59a7..048497f558 100644
--- a/template/modal/backdrop.html
+++ b/template/modal/backdrop.html
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/template/modal/window.html b/template/modal/window.html
index 3e83b0bddc..5c3b1aa27b 100644
--- a/template/modal/window.html
+++ b/template/modal/window.html
@@ -1 +1,3 @@
-
\ No newline at end of file
+