From 96d52ce150219c4071ef4ebf7c4ec0f7ab3bdb81 Mon Sep 17 00:00:00 2001 From: Wesley Cho Date: Sun, 12 Jun 2016 23:48:06 -0700 Subject: [PATCH] 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 --- src/modal/modal.js | 39 ++++++++++++++++++++++++------------ src/modal/test/modal.spec.js | 20 +++--------------- template/modal/backdrop.html | 5 ----- template/modal/window.html | 7 +------ 4 files changed, 30 insertions(+), 41 deletions(-) delete mode 100644 template/modal/backdrop.html diff --git a/src/modal/modal.js b/src/modal/modal.js index 23e81007dd..a64533a74c 100644 --- a/src/modal/modal.js +++ b/src/modal/modal.js @@ -106,8 +106,7 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap', 'ui.bootstrap.p .directive('uibModalBackdrop', ['$animate', '$injector', '$uibModalStack', function($animate, $injector, $modalStack) { return { - replace: true, - templateUrl: 'uib/template/modal/backdrop.html', + restrict: 'A', compile: function(tElement, tAttrs) { tElement.addClass(tAttrs.backdropClass); return linkFn; @@ -136,13 +135,12 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap', 'ui.bootstrap.p scope: { index: '@' }, - replace: true, + restrict: 'A', transclude: true, templateUrl: function(tElement, tAttrs) { return tAttrs.templateUrl || 'uib/template/modal/window.html'; }, link: function(scope, element, attrs) { - element.addClass(attrs.windowClass || ''); element.addClass(attrs.windowTopClass || ''); scope.size = attrs.size; @@ -167,12 +165,9 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap', 'ui.bootstrap.p // Deferred object that will be resolved when this modal is render. var modalRenderDeferObj = $q.defer(); - // Observe function will be called on next digest cycle after compilation, ensuring that the DOM is ready. - // In order to use this way of finding whether DOM is ready, we need to observe a scope property used in modal's template. - attrs.$observe('modalRender', function(value) { - if (value === 'true') { - modalRenderDeferObj.resolve(); - } + // Resolve render promise post-digest + scope.$$postDigest(function() { + modalRenderDeferObj.resolve(); }); modalRenderDeferObj.promise.then(function() { @@ -477,7 +472,16 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap', 'ui.bootstrap.p backdropScope.modalOptions = modal; backdropScope.index = currBackdropIndex; backdropDomEl = angular.element('
'); - backdropDomEl.attr('backdrop-class', modal.backdropClass); + backdropDomEl.attr({ + 'class': 'modal-backdrop', + 'ng-style': '{\'z-index\': 1040 + (index && 1 || 0) + index*10}', + 'uib-modal-animation-class': 'fade', + 'modal-in-class': 'in' + }); + if (modal.backdropClass) { + backdropDomEl.addClass(modal.backdropClass); + } + if (modal.animation) { backdropDomEl.attr('modal-animation', 'true'); } @@ -493,13 +497,22 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap', 'ui.bootstrap.p topModalIndex = previousTopOpenedModal ? parseInt(previousTopOpenedModal.value.modalDomEl.attr('index'), 10) + 1 : 0; var angularDomEl = angular.element('
'); angularDomEl.attr({ + 'class': 'modal', 'template-url': modal.windowTemplateUrl, - 'window-class': modal.windowClass, 'window-top-class': modal.windowTopClass, + 'role': 'dialog', 'size': modal.size, 'index': topModalIndex, - 'animate': 'animate' + 'animate': 'animate', + 'ng-style': '{\'z-index\': 1050 + index*10, display: \'block\'}', + 'tabindex': -1, + 'uib-modal-animation-class': 'fade', + 'modal-in-class': 'in' }).html(modal.content); + if (modal.windowClass) { + angularDomEl.addClass(modal.windowClass); + } + if (modal.animation) { angularDomEl.attr('modal-animation', 'true'); } diff --git a/src/modal/test/modal.spec.js b/src/modal/test/modal.spec.js index dff247e966..2bd0486666 100644 --- a/src/modal/test/modal.spec.js +++ b/src/modal/test/modal.spec.js @@ -52,7 +52,6 @@ describe('$uibModal', function() { beforeEach(module('ngAnimateMock')); beforeEach(module('ui.bootstrap.modal')); - beforeEach(module('uib/template/modal/backdrop.html')); beforeEach(module('uib/template/modal/window.html')); beforeEach(module(function(_$controllerProvider_, _$uibModalProvider_, $compileProvider) { $controllerProvider = _$controllerProvider_; @@ -1415,15 +1414,6 @@ describe('$uibModal', function() { expect($rootScope.foo).toBeTruthy(); }); - it('should support custom CSS classes as string', function() { - $rootScope.animate = false; - var windowEl = $compile('
content
')($rootScope); - $rootScope.$digest(); - - expect(windowEl).toHaveClass('test'); - expect(windowEl).toHaveClass('foo'); - }); - it('should support window top class', function () { $rootScope.animate = false; var windowEl = $compile('
content
')($rootScope); @@ -1434,13 +1424,12 @@ describe('$uibModal', function() { }); it('should support custom template url', inject(function($templateCache) { - $templateCache.put('window.html', '
'); + $templateCache.put('window.html', '
'); - var windowEl = $compile('
content
')($rootScope); + var windowEl = $compile('
content
')($rootScope); $rootScope.$digest(); - expect(windowEl).toHaveClass('mywindow'); - expect(windowEl).toHaveClass('test'); + expect(windowEl.html()).toBe('
content
'); })); }); @@ -1726,7 +1715,6 @@ describe('$uibModal', function() { content: '
Modal1
' }); - expect($document).toHaveModalsOpen(0); $rootScope.$digest(); $animate.flush(); expect($document).toHaveModalsOpen(1); @@ -1746,7 +1734,6 @@ describe('$uibModal', function() { modal2Index = parseInt($uibModalStack.getTop().value.modalDomEl.attr('index'), 10); }); - expect($document).toHaveModalsOpen(1); $rootScope.$digest(); $animate.flush(); expect($document).toHaveModalsOpen(2); @@ -1768,7 +1755,6 @@ describe('$uibModal', function() { modal3Index = parseInt($uibModalStack.getTop().value.modalDomEl.attr('index'), 10); }); - expect($document).toHaveModalsOpen(1); $rootScope.$digest(); $animate.flush(); expect($document).toHaveModalsOpen(2); diff --git a/template/modal/backdrop.html b/template/modal/backdrop.html deleted file mode 100644 index 1eeaa1a996..0000000000 --- a/template/modal/backdrop.html +++ /dev/null @@ -1,5 +0,0 @@ - diff --git a/template/modal/window.html b/template/modal/window.html index e28a8e8373..9850c1b61e 100644 --- a/template/modal/window.html +++ b/template/modal/window.html @@ -1,6 +1 @@ - +