From 6d8aae7875bc38061472123518ec35841a384f56 Mon Sep 17 00:00:00 2001 From: Wesley Cho Date: Fri, 23 Oct 2015 14:42:51 -0700 Subject: [PATCH] feat(modal): remove deprecated code BREAKING CHANGE: Remove deprecated services/directives --- src/modal/modal.js | 242 +---------------------------------- src/modal/test/modal.spec.js | 69 ---------- 2 files changed, 2 insertions(+), 309 deletions(-) diff --git a/src/modal/modal.js b/src/modal/modal.js index 93d07cf10a..971e5410eb 100644 --- a/src/modal/modal.js +++ b/src/modal/modal.js @@ -554,8 +554,8 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap']) backdrop: true, //can also be false or 'static' keyboard: true }, - $get: ['$injector', '$rootScope', '$q', '$templateRequest', '$controller', '$uibModalStack', '$modalSuppressWarning', '$log', - function ($injector, $rootScope, $q, $templateRequest, $controller, $modalStack, $modalSuppressWarning, $log) { + $get: ['$injector', '$rootScope', '$q', '$templateRequest', '$controller', '$uibModalStack', + function ($injector, $rootScope, $q, $templateRequest, $controller, $modalStack) { var $modal = {}; function getTemplatePromise(options) { @@ -642,15 +642,6 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap']) if (modalOptions.controller) { ctrlLocals.$scope = modalScope; ctrlLocals.$uibModalInstance = modalInstance; - Object.defineProperty(ctrlLocals, '$modalInstance', { - get: function() { - if (!$modalSuppressWarning) { - $log.warn('$modalInstance is now deprecated. Use $uibModalInstance instead.'); - } - - return modalInstance; - } - }); angular.forEach(modalOptions.resolve, function(value, key) { ctrlLocals[key] = tplAndVars[resolveIter++]; }); @@ -702,232 +693,3 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap']) return $modalProvider; }); - -/* deprecated modal below */ - -angular.module('ui.bootstrap.modal') - - .value('$modalSuppressWarning', false) - - /** - * A helper directive for the $modal service. It creates a backdrop element. - */ - .directive('modalBackdrop', [ - '$animate', '$injector', '$modalStack', '$log', '$modalSuppressWarning', - function($animate , $injector, $modalStack, $log, $modalSuppressWarning) { - var $animateCss = null; - - if ($injector.has('$animateCss')) { - $animateCss = $injector.get('$animateCss'); - } - - return { - replace: true, - templateUrl: 'template/modal/backdrop.html', - compile: function(tElement, tAttrs) { - tElement.addClass(tAttrs.backdropClass); - return linkFn; - } - }; - - function linkFn(scope, element, attrs) { - if (!$modalSuppressWarning) { - $log.warn('modal-backdrop is now deprecated. Use uib-modal-backdrop instead.'); - } - element.addClass('modal-backdrop'); - - if (attrs.modalInClass) { - if ($animateCss) { - $animateCss(element, { - addClass: attrs.modalInClass - }).start(); - } else { - $animate.addClass(element, attrs.modalInClass); - } - - scope.$on($modalStack.NOW_CLOSING_EVENT, function(e, setIsAsync) { - var done = setIsAsync(); - if ($animateCss) { - $animateCss(element, { - removeClass: attrs.modalInClass - }).start().then(done); - } else { - $animate.removeClass(element, attrs.modalInClass).then(done); - } - }); - } - } - }]) - - .directive('modalWindow', [ - '$modalStack', '$q', '$animate', '$injector', '$log', '$modalSuppressWarning', - function($modalStack , $q , $animate, $injector, $log, $modalSuppressWarning) { - var $animateCss = null; - - if ($injector.has('$animateCss')) { - $animateCss = $injector.get('$animateCss'); - } - - return { - scope: { - index: '@' - }, - replace: true, - transclude: true, - templateUrl: function(tElement, tAttrs) { - return tAttrs.templateUrl || 'template/modal/window.html'; - }, - link: function(scope, element, attrs) { - if (!$modalSuppressWarning) { - $log.warn('modal-window is now deprecated. Use uib-modal-window instead.'); - } - element.addClass(attrs.windowClass || ''); - element.addClass(attrs.windowTopClass || ''); - scope.size = attrs.size; - - 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'); - } - }; - - // moved from template to fix issue #2280 - element.on('click', scope.close); - - // This property is only added to the scope for the purpose of detecting when this directive is rendered. - // We can detect that by using this property in the template associated with this directive and then use - // {@link Attribute#$observe} on it. For more details please see {@link TableColumnResize}. - scope.$isRendered = true; - - // 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(); - } - }); - - modalRenderDeferObj.promise.then(function() { - var animationPromise = null; - - if (attrs.modalInClass) { - if ($animateCss) { - animationPromise = $animateCss(element, { - addClass: attrs.modalInClass - }).start(); - } else { - animationPromise = $animate.addClass(element, attrs.modalInClass); - } - - scope.$on($modalStack.NOW_CLOSING_EVENT, function(e, setIsAsync) { - var done = setIsAsync(); - if ($animateCss) { - $animateCss(element, { - removeClass: attrs.modalInClass - }).start().then(done); - } else { - $animate.removeClass(element, attrs.modalInClass).then(done); - } - }); - } - - - $q.when(animationPromise).then(function() { - var inputWithAutofocus = element[0].querySelector('[autofocus]'); - /** - * Auto-focusing of a freshly-opened modal element causes any child elements - * with the autofocus attribute to lose focus. This is an issue on touch - * based devices which will show and then hide the onscreen keyboard. - * Attempts to refocus the autofocus element via JavaScript will not reopen - * the onscreen keyboard. Fixed by updated the focusing logic to only autofocus - * the modal element if the modal does not contain an autofocus element. - */ - if (inputWithAutofocus) { - inputWithAutofocus.focus(); - } else { - element[0].focus(); - } - }); - - // Notify {@link $modalStack} that modal is rendered. - var modal = $modalStack.getTop(); - if (modal) { - $modalStack.modalRendered(modal.key); - } - }); - } - }; - }]) - - .directive('modalAnimationClass', [ - '$log', '$modalSuppressWarning', - function ($log, $modalSuppressWarning) { - return { - compile: function(tElement, tAttrs) { - if (!$modalSuppressWarning) { - $log.warn('modal-animation-class is now deprecated. Use uib-modal-animation-class instead.'); - } - if (tAttrs.modalAnimation) { - tElement.addClass(tAttrs.modalAnimationClass); - } - } - }; - }]) - - .directive('modalTransclude', [ - '$log', '$modalSuppressWarning', - function ($log, $modalSuppressWarning) { - return { - link: function($scope, $element, $attrs, controller, $transclude) { - if (!$modalSuppressWarning) { - $log.warn('modal-transclude is now deprecated. Use uib-modal-transclude instead.'); - } - $transclude($scope.$parent, function(clone) { - $element.empty(); - $element.append(clone); - }); - } - }; - }]) - - .service('$modalStack', [ - '$animate', '$timeout', '$document', '$compile', '$rootScope', - '$q', - '$injector', - '$$multiMap', - '$$stackedMap', - '$uibModalStack', - '$log', - '$modalSuppressWarning', - function($animate , $timeout , $document , $compile , $rootScope , - $q, - $injector, - $$multiMap, - $$stackedMap, - $uibModalStack, - $log, - $modalSuppressWarning) { - if (!$modalSuppressWarning) { - $log.warn('$modalStack is now deprecated. Use $uibModalStack instead.'); - } - - angular.extend(this, $uibModalStack); - }]) - - .provider('$modal', ['$uibModalProvider', function($uibModalProvider) { - angular.extend(this, $uibModalProvider); - - this.$get = ['$injector', '$log', '$modalSuppressWarning', - function ($injector, $log, $modalSuppressWarning) { - if (!$modalSuppressWarning) { - $log.warn('$modal is now deprecated. Use $uibModal instead.'); - } - - return $injector.invoke($uibModalProvider.$get); - }]; - }]); diff --git a/src/modal/test/modal.spec.js b/src/modal/test/modal.spec.js index a427584548..d6c7c03a37 100644 --- a/src/modal/test/modal.spec.js +++ b/src/modal/test/modal.spec.js @@ -1184,72 +1184,3 @@ describe('$uibModal', function () { }); }); }); - -/* deprecation tests below */ - -describe('$modal deprecation', function() { - beforeEach(module('ngAnimateMock')); - beforeEach(module('ui.bootstrap.modal')); - beforeEach(module('template/modal/backdrop.html')); - beforeEach(module('template/modal/window.html')); - - it('should suppress warning', function() { - module(function($provide) { - $provide.value('$modalSuppressWarning', true); - }); - - inject(function($modal, $timeout, $log, $rootScope) { - spyOn($log, 'warn'); - - $modal.open({template: '
Foo
', controller: function($modalInstance) {}}); - $rootScope.$digest(); - $timeout.flush(0); - expect($log.warn.calls.count()).toBe(0); - }); - }); - - it('should give warning by default', inject(function($log) { - spyOn($log, 'warn'); - - inject(function($compile, $templateCache, $rootScope, $modal, $timeout) { - var backdropTemplate = - ''; - $templateCache.put('template/modal/backdrop.html', backdropTemplate); - - var windowTemplate = - ''; - $templateCache.put('template/modal/window.html', windowTemplate); - - $modal.open({template: '
Foo
', controller: function($modalInstance) {}}); - $rootScope.$digest(); - $timeout.flush(0); - - expect($log.warn.calls.count()).toBe(6); - expect($log.warn.calls.argsFor(0)).toEqual(['$modal is now deprecated. Use $uibModal instead.']); - expect($log.warn.calls.argsFor(1)).toEqual(['$modalInstance is now deprecated. Use $uibModalInstance instead.']); - expect($log.warn.calls.argsFor(2)).toEqual(['$modalStack is now deprecated. Use $uibModalStack instead.']); - expect($log.warn.calls.argsFor(3)).toEqual(['modal-animation-class is now deprecated. Use uib-modal-animation-class instead.']); - expect($log.warn.calls.argsFor(4)).toEqual(['modal-animation-class is now deprecated. Use uib-modal-animation-class instead.']); - expect($log.warn.calls.argsFor(5)).toEqual(['modal-transclude is now deprecated. Use uib-modal-transclude instead.']); - - $log.warn.calls.reset(); - $compile('
')($rootScope); - $rootScope.$digest(); - expect($log.warn.calls.argsFor(1)).toEqual(['modal-backdrop is now deprecated. Use uib-modal-backdrop instead.']); - - $log.warn.calls.reset(); - $compile('
')($rootScope); - $rootScope.$digest(); - expect($log.warn.calls.argsFor(2)).toEqual(['modal-window is now deprecated. Use uib-modal-window instead.']); - }); - })); -});