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

Commit 444c488

Browse files
Justin Hallpkozlowski-opensource
Justin Hall
authored andcommittedDec 28, 2013
feat(modal): added bootstrap3 support
1 parent 428f147 commit 444c488

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed
 

‎src/modal/docs/demo.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ <h3>I'm a modal!</h3>
1717
</div>
1818
</script>
1919

20-
<button class="btn" ng-click="open()">Open me!</button>
20+
<button class="btn btn-default" ng-click="open()">Open me!</button>
2121
<div ng-show="selected">Selection from a modal: {{ selected }}</div>
2222
</div>

‎src/modal/modal.js

+16-17
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ angular.module('ui.bootstrap.modal', [])
5757
/**
5858
* A helper directive for the $modal service. It creates a backdrop element.
5959
*/
60-
.directive('modalBackdrop', ['$modalStack', '$timeout', function ($modalStack, $timeout) {
60+
.directive('modalBackdrop', ['$timeout', function ($timeout) {
6161
return {
6262
restrict: 'EA',
6363
replace: true,
@@ -70,20 +70,11 @@ angular.module('ui.bootstrap.modal', [])
7070
$timeout(function () {
7171
scope.animate = true;
7272
});
73-
74-
scope.close = function (evt) {
75-
var modal = $modalStack.getTop();
76-
if (modal && modal.value.backdrop && modal.value.backdrop != 'static') {
77-
evt.preventDefault();
78-
evt.stopPropagation();
79-
$modalStack.dismiss(modal.key, 'backdrop click');
80-
}
81-
};
8273
}
8374
};
8475
}])
8576

86-
.directive('modalWindow', ['$timeout', function ($timeout) {
77+
.directive('modalWindow', ['$modalStack', '$timeout', function ($modalStack, $timeout) {
8778
return {
8879
restrict: 'EA',
8980
scope: {
@@ -95,13 +86,21 @@ angular.module('ui.bootstrap.modal', [])
9586
link: function (scope, element, attrs) {
9687
scope.windowClass = attrs.windowClass || '';
9788

98-
// focus a freshly-opened modal
99-
element[0].focus();
100-
10189
$timeout(function () {
10290
// trigger CSS transitions
10391
scope.animate = true;
92+
// focus a freshly-opened modal
93+
element[0].focus();
10494
});
95+
96+
scope.close = function (evt) {
97+
var modal = $modalStack.getTop();
98+
if (modal && modal.value.backdrop && modal.value.backdrop != 'static' && (evt.target === evt.currentTarget)) {
99+
evt.preventDefault();
100+
evt.stopPropagation();
101+
$modalStack.dismiss(modal.key, 'backdrop click');
102+
}
103+
};
105104
}
106105
};
107106
}])
@@ -195,9 +194,9 @@ angular.module('ui.bootstrap.modal', [])
195194
};
196195

197196
$modalStack.close = function (modalInstance, result) {
198-
var modal = openedWindows.get(modalInstance);
199-
if (modal) {
200-
modal.value.deferred.resolve(result);
197+
var modalWindow = openedWindows.get(modalInstance).value;
198+
if (modalWindow) {
199+
modalWindow.deferred.resolve(result);
201200
removeModalWindow(modalInstance);
202201
}
203202
};

‎src/modal/test/modal.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('$modal', function () {
5656

5757
toHaveModalOpenWithContent: function(content, selector) {
5858

59-
var contentToCompare, modalDomEls = this.actual.find('body > div.modal');
59+
var contentToCompare, modalDomEls = this.actual.find('body > div.modal > div.modal-dialog > div.modal-content');
6060

6161
this.message = function() {
6262
return "Expected '" + angular.mock.dump(modalDomEls) + "' to be open with '" + content + "'.";
@@ -154,7 +154,7 @@ describe('$modal', function () {
154154
var modal = open({template: '<div>Content</div>'});
155155
expect($document).toHaveModalsOpen(1);
156156

157-
$document.find('body > div.modal-backdrop').click();
157+
$document.find('body > div.modal').click();
158158
$rootScope.$digest();
159159

160160
expect($document).toHaveModalsOpen(0);

‎template/modal/backdrop.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<div class="modal-backdrop fade" ng-class="{in: animate}" ng-style="{'z-index': 1040 + index*10}" ng-click="close($event)"></div>
1+
<div class="modal-backdrop fade" ng-class="{in: animate}" ng-style="{'z-index': 1040 + index*10}"></div>

‎template/modal/window.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
<div tabindex="-1" class="modal fade {{ windowClass }}" ng-class="{in: animate}" ng-style="{'z-index': 1050 + index*10}" ng-transclude></div>
1+
<div tabindex="-1" class="modal fade {{ windowClass }}" ng-class="{in: animate}" ng-style="{'z-index': 1050 + index*10, display: 'block'}" ng-click="close($event)">
2+
<div class="modal-dialog"><div class="modal-content" ng-transclude></div></div>
3+
</div>

0 commit comments

Comments
 (0)