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

Commit a85d499

Browse files
committed
feat(modal): remove deprecated code
BREAKING CHANGE: Remove deprecated services/directives Closes #4709
1 parent 2fc3f21 commit a85d499

File tree

2 files changed

+2
-309
lines changed

2 files changed

+2
-309
lines changed

src/modal/modal.js

+2-240
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,8 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
554554
backdrop: true, //can also be false or 'static'
555555
keyboard: true
556556
},
557-
$get: ['$injector', '$rootScope', '$q', '$templateRequest', '$controller', '$uibModalStack', '$modalSuppressWarning', '$log',
558-
function ($injector, $rootScope, $q, $templateRequest, $controller, $modalStack, $modalSuppressWarning, $log) {
557+
$get: ['$injector', '$rootScope', '$q', '$templateRequest', '$controller', '$uibModalStack',
558+
function ($injector, $rootScope, $q, $templateRequest, $controller, $modalStack) {
559559
var $modal = {};
560560

561561
function getTemplatePromise(options) {
@@ -642,15 +642,6 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
642642
if (modalOptions.controller) {
643643
ctrlLocals.$scope = modalScope;
644644
ctrlLocals.$uibModalInstance = modalInstance;
645-
Object.defineProperty(ctrlLocals, '$modalInstance', {
646-
get: function() {
647-
if (!$modalSuppressWarning) {
648-
$log.warn('$modalInstance is now deprecated. Use $uibModalInstance instead.');
649-
}
650-
651-
return modalInstance;
652-
}
653-
});
654645
angular.forEach(modalOptions.resolve, function(value, key) {
655646
ctrlLocals[key] = tplAndVars[resolveIter++];
656647
});
@@ -702,232 +693,3 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
702693

703694
return $modalProvider;
704695
});
705-
706-
/* deprecated modal below */
707-
708-
angular.module('ui.bootstrap.modal')
709-
710-
.value('$modalSuppressWarning', false)
711-
712-
/**
713-
* A helper directive for the $modal service. It creates a backdrop element.
714-
*/
715-
.directive('modalBackdrop', [
716-
'$animate', '$injector', '$modalStack', '$log', '$modalSuppressWarning',
717-
function($animate , $injector, $modalStack, $log, $modalSuppressWarning) {
718-
var $animateCss = null;
719-
720-
if ($injector.has('$animateCss')) {
721-
$animateCss = $injector.get('$animateCss');
722-
}
723-
724-
return {
725-
replace: true,
726-
templateUrl: 'template/modal/backdrop.html',
727-
compile: function(tElement, tAttrs) {
728-
tElement.addClass(tAttrs.backdropClass);
729-
return linkFn;
730-
}
731-
};
732-
733-
function linkFn(scope, element, attrs) {
734-
if (!$modalSuppressWarning) {
735-
$log.warn('modal-backdrop is now deprecated. Use uib-modal-backdrop instead.');
736-
}
737-
element.addClass('modal-backdrop');
738-
739-
if (attrs.modalInClass) {
740-
if ($animateCss) {
741-
$animateCss(element, {
742-
addClass: attrs.modalInClass
743-
}).start();
744-
} else {
745-
$animate.addClass(element, attrs.modalInClass);
746-
}
747-
748-
scope.$on($modalStack.NOW_CLOSING_EVENT, function(e, setIsAsync) {
749-
var done = setIsAsync();
750-
if ($animateCss) {
751-
$animateCss(element, {
752-
removeClass: attrs.modalInClass
753-
}).start().then(done);
754-
} else {
755-
$animate.removeClass(element, attrs.modalInClass).then(done);
756-
}
757-
});
758-
}
759-
}
760-
}])
761-
762-
.directive('modalWindow', [
763-
'$modalStack', '$q', '$animate', '$injector', '$log', '$modalSuppressWarning',
764-
function($modalStack , $q , $animate, $injector, $log, $modalSuppressWarning) {
765-
var $animateCss = null;
766-
767-
if ($injector.has('$animateCss')) {
768-
$animateCss = $injector.get('$animateCss');
769-
}
770-
771-
return {
772-
scope: {
773-
index: '@'
774-
},
775-
replace: true,
776-
transclude: true,
777-
templateUrl: function(tElement, tAttrs) {
778-
return tAttrs.templateUrl || 'template/modal/window.html';
779-
},
780-
link: function(scope, element, attrs) {
781-
if (!$modalSuppressWarning) {
782-
$log.warn('modal-window is now deprecated. Use uib-modal-window instead.');
783-
}
784-
element.addClass(attrs.windowClass || '');
785-
element.addClass(attrs.windowTopClass || '');
786-
scope.size = attrs.size;
787-
788-
scope.close = function(evt) {
789-
var modal = $modalStack.getTop();
790-
if (modal && modal.value.backdrop && modal.value.backdrop !== 'static' && (evt.target === evt.currentTarget)) {
791-
evt.preventDefault();
792-
evt.stopPropagation();
793-
$modalStack.dismiss(modal.key, 'backdrop click');
794-
}
795-
};
796-
797-
// moved from template to fix issue #2280
798-
element.on('click', scope.close);
799-
800-
// This property is only added to the scope for the purpose of detecting when this directive is rendered.
801-
// We can detect that by using this property in the template associated with this directive and then use
802-
// {@link Attribute#$observe} on it. For more details please see {@link TableColumnResize}.
803-
scope.$isRendered = true;
804-
805-
// Deferred object that will be resolved when this modal is render.
806-
var modalRenderDeferObj = $q.defer();
807-
// Observe function will be called on next digest cycle after compilation, ensuring that the DOM is ready.
808-
// In order to use this way of finding whether DOM is ready, we need to observe a scope property used in modal's template.
809-
attrs.$observe('modalRender', function(value) {
810-
if (value == 'true') {
811-
modalRenderDeferObj.resolve();
812-
}
813-
});
814-
815-
modalRenderDeferObj.promise.then(function() {
816-
var animationPromise = null;
817-
818-
if (attrs.modalInClass) {
819-
if ($animateCss) {
820-
animationPromise = $animateCss(element, {
821-
addClass: attrs.modalInClass
822-
}).start();
823-
} else {
824-
animationPromise = $animate.addClass(element, attrs.modalInClass);
825-
}
826-
827-
scope.$on($modalStack.NOW_CLOSING_EVENT, function(e, setIsAsync) {
828-
var done = setIsAsync();
829-
if ($animateCss) {
830-
$animateCss(element, {
831-
removeClass: attrs.modalInClass
832-
}).start().then(done);
833-
} else {
834-
$animate.removeClass(element, attrs.modalInClass).then(done);
835-
}
836-
});
837-
}
838-
839-
840-
$q.when(animationPromise).then(function() {
841-
var inputWithAutofocus = element[0].querySelector('[autofocus]');
842-
/**
843-
* Auto-focusing of a freshly-opened modal element causes any child elements
844-
* with the autofocus attribute to lose focus. This is an issue on touch
845-
* based devices which will show and then hide the onscreen keyboard.
846-
* Attempts to refocus the autofocus element via JavaScript will not reopen
847-
* the onscreen keyboard. Fixed by updated the focusing logic to only autofocus
848-
* the modal element if the modal does not contain an autofocus element.
849-
*/
850-
if (inputWithAutofocus) {
851-
inputWithAutofocus.focus();
852-
} else {
853-
element[0].focus();
854-
}
855-
});
856-
857-
// Notify {@link $modalStack} that modal is rendered.
858-
var modal = $modalStack.getTop();
859-
if (modal) {
860-
$modalStack.modalRendered(modal.key);
861-
}
862-
});
863-
}
864-
};
865-
}])
866-
867-
.directive('modalAnimationClass', [
868-
'$log', '$modalSuppressWarning',
869-
function ($log, $modalSuppressWarning) {
870-
return {
871-
compile: function(tElement, tAttrs) {
872-
if (!$modalSuppressWarning) {
873-
$log.warn('modal-animation-class is now deprecated. Use uib-modal-animation-class instead.');
874-
}
875-
if (tAttrs.modalAnimation) {
876-
tElement.addClass(tAttrs.modalAnimationClass);
877-
}
878-
}
879-
};
880-
}])
881-
882-
.directive('modalTransclude', [
883-
'$log', '$modalSuppressWarning',
884-
function ($log, $modalSuppressWarning) {
885-
return {
886-
link: function($scope, $element, $attrs, controller, $transclude) {
887-
if (!$modalSuppressWarning) {
888-
$log.warn('modal-transclude is now deprecated. Use uib-modal-transclude instead.');
889-
}
890-
$transclude($scope.$parent, function(clone) {
891-
$element.empty();
892-
$element.append(clone);
893-
});
894-
}
895-
};
896-
}])
897-
898-
.service('$modalStack', [
899-
'$animate', '$timeout', '$document', '$compile', '$rootScope',
900-
'$q',
901-
'$injector',
902-
'$$multiMap',
903-
'$$stackedMap',
904-
'$uibModalStack',
905-
'$log',
906-
'$modalSuppressWarning',
907-
function($animate , $timeout , $document , $compile , $rootScope ,
908-
$q,
909-
$injector,
910-
$$multiMap,
911-
$$stackedMap,
912-
$uibModalStack,
913-
$log,
914-
$modalSuppressWarning) {
915-
if (!$modalSuppressWarning) {
916-
$log.warn('$modalStack is now deprecated. Use $uibModalStack instead.');
917-
}
918-
919-
angular.extend(this, $uibModalStack);
920-
}])
921-
922-
.provider('$modal', ['$uibModalProvider', function($uibModalProvider) {
923-
angular.extend(this, $uibModalProvider);
924-
925-
this.$get = ['$injector', '$log', '$modalSuppressWarning',
926-
function ($injector, $log, $modalSuppressWarning) {
927-
if (!$modalSuppressWarning) {
928-
$log.warn('$modal is now deprecated. Use $uibModal instead.');
929-
}
930-
931-
return $injector.invoke($uibModalProvider.$get);
932-
}];
933-
}]);

src/modal/test/modal.spec.js

-69
Original file line numberDiff line numberDiff line change
@@ -1184,72 +1184,3 @@ describe('$uibModal', function () {
11841184
});
11851185
});
11861186
});
1187-
1188-
/* deprecation tests below */
1189-
1190-
describe('$modal deprecation', function() {
1191-
beforeEach(module('ngAnimateMock'));
1192-
beforeEach(module('ui.bootstrap.modal'));
1193-
beforeEach(module('template/modal/backdrop.html'));
1194-
beforeEach(module('template/modal/window.html'));
1195-
1196-
it('should suppress warning', function() {
1197-
module(function($provide) {
1198-
$provide.value('$modalSuppressWarning', true);
1199-
});
1200-
1201-
inject(function($modal, $timeout, $log, $rootScope) {
1202-
spyOn($log, 'warn');
1203-
1204-
$modal.open({template: '<div>Foo</div>', controller: function($modalInstance) {}});
1205-
$rootScope.$digest();
1206-
$timeout.flush(0);
1207-
expect($log.warn.calls.count()).toBe(0);
1208-
});
1209-
});
1210-
1211-
it('should give warning by default', inject(function($log) {
1212-
spyOn($log, 'warn');
1213-
1214-
inject(function($compile, $templateCache, $rootScope, $modal, $timeout) {
1215-
var backdropTemplate =
1216-
'<div class="modal-backdrop"' +
1217-
'modal-animation-class="fade"' +
1218-
'modal-in-class="in"' +
1219-
'ng-style="{\'z-index\': 1040 + (index && 1 || 0) + index*10}"' +
1220-
'></div>';
1221-
$templateCache.put('template/modal/backdrop.html', backdropTemplate);
1222-
1223-
var windowTemplate =
1224-
'<div modal-render="{{$isRendered}}" tabindex="-1" role="dialog" class="modal"' +
1225-
'modal-animation-class="fade"' +
1226-
'modal-in-class="in"' +
1227-
'ng-style="{\'z-index\': 1050 + index*10, display: \'block\'}">' +
1228-
'<div class="modal-dialog" ng-class="size ? \'modal-\' + size : \'\'"><div class="modal-content" modal-transclude></div></div>' +
1229-
'</div>';
1230-
$templateCache.put('template/modal/window.html', windowTemplate);
1231-
1232-
$modal.open({template: '<div>Foo</div>', controller: function($modalInstance) {}});
1233-
$rootScope.$digest();
1234-
$timeout.flush(0);
1235-
1236-
expect($log.warn.calls.count()).toBe(6);
1237-
expect($log.warn.calls.argsFor(0)).toEqual(['$modal is now deprecated. Use $uibModal instead.']);
1238-
expect($log.warn.calls.argsFor(1)).toEqual(['$modalInstance is now deprecated. Use $uibModalInstance instead.']);
1239-
expect($log.warn.calls.argsFor(2)).toEqual(['$modalStack is now deprecated. Use $uibModalStack instead.']);
1240-
expect($log.warn.calls.argsFor(3)).toEqual(['modal-animation-class is now deprecated. Use uib-modal-animation-class instead.']);
1241-
expect($log.warn.calls.argsFor(4)).toEqual(['modal-animation-class is now deprecated. Use uib-modal-animation-class instead.']);
1242-
expect($log.warn.calls.argsFor(5)).toEqual(['modal-transclude is now deprecated. Use uib-modal-transclude instead.']);
1243-
1244-
$log.warn.calls.reset();
1245-
$compile('<div modal-backdrop></div>')($rootScope);
1246-
$rootScope.$digest();
1247-
expect($log.warn.calls.argsFor(1)).toEqual(['modal-backdrop is now deprecated. Use uib-modal-backdrop instead.']);
1248-
1249-
$log.warn.calls.reset();
1250-
$compile('<div modal-window></div>')($rootScope);
1251-
$rootScope.$digest();
1252-
expect($log.warn.calls.argsFor(2)).toEqual(['modal-window is now deprecated. Use uib-modal-window instead.']);
1253-
});
1254-
}));
1255-
});

0 commit comments

Comments
 (0)