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

Commit 96d52ce

Browse files
committed
feat(modal): remove replace usage
- Remove `replace: true` usage BREAKING CHANGE: This removes `replace: true` usage, causing some structural changes to the HTML - the major part here is that there is no more backdrop template, and the top level elements for the window/backdrop elements lose a little flexibility. See documentation examples for new structure. Closes #5989
1 parent 55cf26b commit 96d52ce

File tree

4 files changed

+30
-41
lines changed

4 files changed

+30
-41
lines changed

src/modal/modal.js

+26-13
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap', 'ui.bootstrap.p
106106
.directive('uibModalBackdrop', ['$animate', '$injector', '$uibModalStack',
107107
function($animate, $injector, $modalStack) {
108108
return {
109-
replace: true,
110-
templateUrl: 'uib/template/modal/backdrop.html',
109+
restrict: 'A',
111110
compile: function(tElement, tAttrs) {
112111
tElement.addClass(tAttrs.backdropClass);
113112
return linkFn;
@@ -136,13 +135,12 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap', 'ui.bootstrap.p
136135
scope: {
137136
index: '@'
138137
},
139-
replace: true,
138+
restrict: 'A',
140139
transclude: true,
141140
templateUrl: function(tElement, tAttrs) {
142141
return tAttrs.templateUrl || 'uib/template/modal/window.html';
143142
},
144143
link: function(scope, element, attrs) {
145-
element.addClass(attrs.windowClass || '');
146144
element.addClass(attrs.windowTopClass || '');
147145
scope.size = attrs.size;
148146

@@ -167,12 +165,9 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap', 'ui.bootstrap.p
167165

168166
// Deferred object that will be resolved when this modal is render.
169167
var modalRenderDeferObj = $q.defer();
170-
// Observe function will be called on next digest cycle after compilation, ensuring that the DOM is ready.
171-
// In order to use this way of finding whether DOM is ready, we need to observe a scope property used in modal's template.
172-
attrs.$observe('modalRender', function(value) {
173-
if (value === 'true') {
174-
modalRenderDeferObj.resolve();
175-
}
168+
// Resolve render promise post-digest
169+
scope.$$postDigest(function() {
170+
modalRenderDeferObj.resolve();
176171
});
177172

178173
modalRenderDeferObj.promise.then(function() {
@@ -477,7 +472,16 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap', 'ui.bootstrap.p
477472
backdropScope.modalOptions = modal;
478473
backdropScope.index = currBackdropIndex;
479474
backdropDomEl = angular.element('<div uib-modal-backdrop="modal-backdrop"></div>');
480-
backdropDomEl.attr('backdrop-class', modal.backdropClass);
475+
backdropDomEl.attr({
476+
'class': 'modal-backdrop',
477+
'ng-style': '{\'z-index\': 1040 + (index && 1 || 0) + index*10}',
478+
'uib-modal-animation-class': 'fade',
479+
'modal-in-class': 'in'
480+
});
481+
if (modal.backdropClass) {
482+
backdropDomEl.addClass(modal.backdropClass);
483+
}
484+
481485
if (modal.animation) {
482486
backdropDomEl.attr('modal-animation', 'true');
483487
}
@@ -493,13 +497,22 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap', 'ui.bootstrap.p
493497
topModalIndex = previousTopOpenedModal ? parseInt(previousTopOpenedModal.value.modalDomEl.attr('index'), 10) + 1 : 0;
494498
var angularDomEl = angular.element('<div uib-modal-window="modal-window"></div>');
495499
angularDomEl.attr({
500+
'class': 'modal',
496501
'template-url': modal.windowTemplateUrl,
497-
'window-class': modal.windowClass,
498502
'window-top-class': modal.windowTopClass,
503+
'role': 'dialog',
499504
'size': modal.size,
500505
'index': topModalIndex,
501-
'animate': 'animate'
506+
'animate': 'animate',
507+
'ng-style': '{\'z-index\': 1050 + index*10, display: \'block\'}',
508+
'tabindex': -1,
509+
'uib-modal-animation-class': 'fade',
510+
'modal-in-class': 'in'
502511
}).html(modal.content);
512+
if (modal.windowClass) {
513+
angularDomEl.addClass(modal.windowClass);
514+
}
515+
503516
if (modal.animation) {
504517
angularDomEl.attr('modal-animation', 'true');
505518
}

src/modal/test/modal.spec.js

+3-17
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ describe('$uibModal', function() {
5252

5353
beforeEach(module('ngAnimateMock'));
5454
beforeEach(module('ui.bootstrap.modal'));
55-
beforeEach(module('uib/template/modal/backdrop.html'));
5655
beforeEach(module('uib/template/modal/window.html'));
5756
beforeEach(module(function(_$controllerProvider_, _$uibModalProvider_, $compileProvider) {
5857
$controllerProvider = _$controllerProvider_;
@@ -1415,15 +1414,6 @@ describe('$uibModal', function() {
14151414
expect($rootScope.foo).toBeTruthy();
14161415
});
14171416

1418-
it('should support custom CSS classes as string', function() {
1419-
$rootScope.animate = false;
1420-
var windowEl = $compile('<div uib-modal-window animate="animate" window-class="test foo">content</div>')($rootScope);
1421-
$rootScope.$digest();
1422-
1423-
expect(windowEl).toHaveClass('test');
1424-
expect(windowEl).toHaveClass('foo');
1425-
});
1426-
14271417
it('should support window top class', function () {
14281418
$rootScope.animate = false;
14291419
var windowEl = $compile('<div uib-modal-window animate="animate" window-top-class="test foo">content</div>')($rootScope);
@@ -1434,13 +1424,12 @@ describe('$uibModal', function() {
14341424
});
14351425

14361426
it('should support custom template url', inject(function($templateCache) {
1437-
$templateCache.put('window.html', '<div class="mywindow" ng-transclude></div>');
1427+
$templateCache.put('window.html', '<div ng-transclude></div>');
14381428

1439-
var windowEl = $compile('<div uib-modal-window template-url="window.html" window-class="test">content</div>')($rootScope);
1429+
var windowEl = $compile('<div uib-modal-window template-url="window.html">content</div>')($rootScope);
14401430
$rootScope.$digest();
14411431

1442-
expect(windowEl).toHaveClass('mywindow');
1443-
expect(windowEl).toHaveClass('test');
1432+
expect(windowEl.html()).toBe('<div ng-transclude=""><span class="ng-scope">content</span></div>');
14441433
}));
14451434
});
14461435

@@ -1726,7 +1715,6 @@ describe('$uibModal', function() {
17261715
content: '<div>Modal1</div>'
17271716
});
17281717

1729-
expect($document).toHaveModalsOpen(0);
17301718
$rootScope.$digest();
17311719
$animate.flush();
17321720
expect($document).toHaveModalsOpen(1);
@@ -1746,7 +1734,6 @@ describe('$uibModal', function() {
17461734
modal2Index = parseInt($uibModalStack.getTop().value.modalDomEl.attr('index'), 10);
17471735
});
17481736

1749-
expect($document).toHaveModalsOpen(1);
17501737
$rootScope.$digest();
17511738
$animate.flush();
17521739
expect($document).toHaveModalsOpen(2);
@@ -1768,7 +1755,6 @@ describe('$uibModal', function() {
17681755
modal3Index = parseInt($uibModalStack.getTop().value.modalDomEl.attr('index'), 10);
17691756
});
17701757

1771-
expect($document).toHaveModalsOpen(1);
17721758
$rootScope.$digest();
17731759
$animate.flush();
17741760
expect($document).toHaveModalsOpen(2);

template/modal/backdrop.html

-5
This file was deleted.

template/modal/window.html

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
<div modal-render="{{$isRendered}}" tabindex="-1" role="dialog" class="modal"
2-
uib-modal-animation-class="fade"
3-
modal-in-class="in"
4-
ng-style="{'z-index': 1050 + index*10, display: 'block'}">
5-
<div class="modal-dialog {{size ? 'modal-' + size : ''}}"><div class="modal-content" uib-modal-transclude></div></div>
6-
</div>
1+
<div class="modal-dialog {{size ? 'modal-' + size : ''}}"><div class="modal-content" uib-modal-transclude></div></div>

0 commit comments

Comments
 (0)