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

Commit d72d24a

Browse files
Justin Hallpkozlowski-opensource
Justin Hall
authored andcommitted
feat(modal): added bootstrap3 support
1 parent 2c31c70 commit d72d24a

File tree

5 files changed

+25
-20
lines changed

5 files changed

+25
-20
lines changed

src/modal/docs/demo.html

Lines changed: 1 addition & 1 deletion
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

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,31 +57,21 @@ 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,
6464
templateUrl: 'template/modal/backdrop.html',
6565
link: function (scope, element, attrs) {
66-
6766
//trigger CSS transitions
6867
$timeout(function () {
6968
scope.animate = true;
7069
});
71-
72-
scope.close = function (evt) {
73-
var modal = $modalStack.getTop();
74-
if (modal && modal.value.backdrop && modal.value.backdrop != 'static') {
75-
evt.preventDefault();
76-
evt.stopPropagation();
77-
$modalStack.dismiss(modal.key, 'backdrop click');
78-
}
79-
};
8070
}
8171
};
8272
}])
8373

84-
.directive('modalWindow', ['$timeout', function ($timeout) {
74+
.directive('modalWindow', ['$modalStack', '$timeout', function ($modalStack, $timeout) {
8575
return {
8676
restrict: 'EA',
8777
scope: {
@@ -97,6 +87,15 @@ angular.module('ui.bootstrap.modal', [])
9787
$timeout(function () {
9888
scope.animate = true;
9989
});
90+
91+
scope.close = function (evt) {
92+
var modal = $modalStack.getTop();
93+
if (modal && modal.value.backdrop && modal.value.backdrop != 'static' && (evt.target === evt.currentTarget)) {
94+
evt.preventDefault();
95+
evt.stopPropagation();
96+
$modalStack.dismiss(modal.key, 'backdrop click');
97+
}
98+
};
10099
}
101100
};
102101
}])
@@ -121,6 +120,10 @@ angular.module('ui.bootstrap.modal', [])
121120
return topBackdropIndex;
122121
}
123122

123+
$rootScope.$watch(openedWindows.length, function(noOfModals){
124+
body.toggleClass('modal-open', openedWindows.length() > 0);
125+
});
126+
124127
$rootScope.$watch(backdropIndex, function(newBackdropIndex){
125128
backdropScope.index = newBackdropIndex;
126129
});
@@ -184,9 +187,9 @@ angular.module('ui.bootstrap.modal', [])
184187
};
185188

186189
$modalStack.close = function (modalInstance, result) {
187-
var modal = openedWindows.get(modalInstance);
188-
if (modal) {
189-
modal.value.deferred.resolve(result);
190+
var modalWindow = openedWindows.get(modalInstance).value;
191+
if (modalWindow) {
192+
modalWindow.deferred.resolve(result);
190193
removeModalWindow(modalInstance);
191194
}
192195
};

src/modal/test/modal.spec.js

Lines changed: 2 additions & 2 deletions
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 + "'.";
@@ -153,7 +153,7 @@ describe('$modal', function () {
153153
var modal = open({template: '<div>Content</div>'});
154154
expect($document).toHaveModalsOpen(1);
155155

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

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

template/modal/backdrop.html

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
<div class="modal fade {{ windowClass }}" ng-class="{in: animate}" ng-style="{'z-index': 1050 + index*10}" ng-transclude></div>
1+
<div 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)